Changes for page Create Application

Last modified by Thomas Mortagne on 2023/11/29 12:06

From version 1.1
edited by Thomas Mortagne
on 2012/03/01 14:08
Change comment: Imported from XAR
To version 2.1
edited by Vincent Massol
on 2012/07/09 17:19
Change comment: Imported from XAR

Summary

Details

Page properties
Author
... ... @@ -1,1 +1,1 @@
1 -XWiki.ThomasMortagne
1 +XWiki.VincentMassol
Hidden
... ... @@ -1,1 +1,1 @@
1 -false
1 +true
Content
... ... @@ -14,10 +14,6 @@
14 14   #end
15 15   )))
16 16   <form action="" method="post" class="xform wizard-body">
17 - (% class="hidden" %)
18 - (((
19 - <input type="hidden" name="form_token" value="$services.csrf.getToken()"/>
20 - )))
21 21   ; <label for="appName">$msg.get('platform.appwithinminutes.appNameLabel')</label>
22 22   (% class="xHint" %)$msg.get('platform.appwithinminutes.appNameHint')
23 23   : <input type="text" id="appName" name="appName" />
... ... @@ -26,8 +26,27 @@
26 26   {{/html}}
27 27  #end
28 28  
25 +#macro(getAppDescriptor $appName)
26 + #set($appDescriptorClassName = 'AppWithinMinutes.LiveTableClass')
27 + #set($appDescriptorStatement = "from doc.object($appDescriptorClassName) as obj where doc.space = :space")
28 + #set($appDescriptors = $services.query.xwql($appDescriptorStatement).bindValue('space', $appName).execute())
29 + #if($appDescriptors.size() > 0)
30 + #set($appDescriptor = $xwiki.getDocument($appDescriptors.get(0)))
31 + #end
32 +#end
33 +
29 29  #macro(processStep)
30 - #set($classRef = $services.model.createDocumentReference($doc.wiki, $request.appName, "#toXMLName($request.appName)Class"))
35 + ## Check if the application already exists.
36 + #getAppDescriptor($request.appName)
37 + #if($appDescriptor)
38 + ## Edit an existing application. Use the configured class name.
39 + #set($classStringRef = $appDescriptor.getObject($appDescriptorClassName).getProperty('class').value)
40 + ## The class string reference is relative to the document holding the application descriptor.
41 + #set($classRef = $services.model.resolveDocument($classStringRef, 'explicit', $appDescriptor.documentReference))
42 + #else
43 + ## Create a new application. Use the default class name.
44 + #set($classRef = $services.model.createDocumentReference($doc.wiki, $request.appName, "#toXMLName($request.appName)Class"))
45 + #end
31 31   #set($queryString = 'wizard=true')
32 32   #if(!$xwiki.exists($classRef))
33 33   #set($classTitle = "$request.appName Class")
... ... @@ -37,20 +37,33 @@
37 37  #end
38 38  
39 39  #macro(validateAppName $appName)
40 - #set($className = "#toXMLName($appName)")
41 - #if($className == '')
42 - (% class="xErrorMsg" %)$msg.get('platform.appwithinminutes.appNameInvalidClassNameError')
55 + #getAppDescriptor("$!appName")
56 + #if($appDescriptor)
57 + ## Edit an existing application.
58 + #set($appHomeRef = $appDescriptor.documentReference)
59 + #set($classStringRef = $appDescriptor.getObject($appDescriptorClassName).getProperty('class').value)
60 + ## The class string reference is relative to the document holding the application descriptor.
61 + #set($appClassRef = $services.model.resolveDocument($classStringRef, 'explicit', $appDescriptor.documentReference))
62 + #else
63 + ## Create a new application.
64 + #set($className = "#toXMLName($appName)")
65 + #if($className == '')
66 + (% class="xErrorMsg" %)$msg.get('platform.appwithinminutes.appNameInvalidClassNameError')
67 + #end
68 + #set($appHomeRef = $services.model.createDocumentReference($doc.wiki, $appName, 'WebHome'))
69 + #set($appClassRef = $services.model.createDocumentReference($doc.wiki, $appName, "$!{className}Class"))
43 43   #end
44 - #set($appHomeRef = $services.model.createDocumentReference($doc.wiki, $appName, 'WebHome'))
45 45   #set($appHomeURL = $xwiki.getDocument($appHomeRef).getExternalURL())
72 + #if($appHomeURL.endsWith('/WebHome'))
73 + #set($appHomeURL = $appHomeURL.substring(0, $mathtool.sub($appHomeURL.length(), 7)))
74 + #end
46 46   ; $msg.get('platform.appwithinminutes.appNamePreviewHomePageUrlLabel')
47 - : {{{$!appHomeURL.substring(0, $mathtool.sub($appHomeURL.length(), 7))}}}
76 + : {{{$!appHomeURL}}}
48 48   ; $msg.get('platform.appwithinminutes.appNamePreviewDataSpaceLabel')
49 49   : {{{$doc.wiki}}} » {{{$appName}}}
50 50   ; $msg.get('platform.appwithinminutes.appNamePreviewClassReferenceLabel')
51 - : {{{$doc.wiki}}} » {{{$appName}}} » {{{$!{className}Class}}}
52 - #set($appClassRef = $services.model.createDocumentReference($doc.wiki, $appName, "$!{className}Class"))
53 - #if($xwiki.exists($appHomeRef) || $xwiki.exists($appClassRef))
80 + : {{{$appClassRef.wikiReference.name}}} » {{{$appClassRef.lastSpaceReference.name}}} » {{{$appClassRef.name}}}
81 + #if($appDescriptor || $xwiki.exists($appHomeRef) || $xwiki.exists($appClassRef))
54 54  
55 55   {{warning}}$msg.get('platform.appwithinminutes.appNameIsUsedWarning'){{/warning}}
56 56   #end
... ... @@ -61,10 +61,9 @@
61 61  #if("$!request.appName" != '')
62 62   #if($context.action == 'get')
63 63   #validateAppName($request.appName)
64 - #elseif($services.csrf.isTokenValid($request.form_token))
65 - #processStep()
66 66   #else
67 - $response.sendRedirect($services.csrf.getResubmissionURL());
93 + ## CSRF protection is not needed because this step only redirects to the next one passing data in the query string.
94 + #processStep()
68 68   #end
69 69  #else
70 70   #showStep()