Wiki source code of InvitationGuestActions
Version 1.1 by XWiki Admin on 26.05.2017 08:18
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{include reference="Invitation.InvitationCommon" /}} | ||
2 | |||
3 | {{velocity}} | ||
4 | #* | ||
5 | * Invitation Application | ||
6 | * Options for guests who are invited. | ||
7 | * | ||
8 | * Macros in this script don't rely on any variables except those which are passed to them and the following: | ||
9 | * | ||
10 | * $doc the com.xpn.xwiki.api.Document object representing the document containing this code. | ||
11 | * $msg the internationalization message provider containing a get(String) and a get(String, List) function | ||
12 | * $xcontext the com.xpn.xwiki.Context object for this request | ||
13 | * $xwiki an object of the com.xpn.xwiki.api.XWiki class. | ||
14 | * $escapetool an object of class org.apache.velocity.tools.generic.EscapeTool | ||
15 | * | ||
16 | * Macros also depend on other macros but only other macros which are contained in this script. | ||
17 | * | ||
18 | * This script is affected by the following documents: | ||
19 | * | ||
20 | * InvitationMessages stores all of the mail message objects. If this does not exist it will be created. | ||
21 | * May be changed in the configuration. | ||
22 | * | ||
23 | * InvitationMailClass the class for mail message objects. May be changed in the configuration. | ||
24 | * | ||
25 | * InvitationConfig configuration for this code. Contains an XObject of the class defined in this document. | ||
26 | * If it does not exist it will be created with default values. | ||
27 | * | ||
28 | *### | ||
29 | ## | ||
30 | ##--------------------------------------------------------------------- | ||
31 | ## Decide what we should do. | ||
32 | ##--------------------------------------------------------------------- | ||
33 | ## | ||
34 | #set($action = []) | ||
35 | #getUserAction($request.getParameterMap(), $action) | ||
36 | #if($action.size() > 0) | ||
37 | #set($action = $action.get(0)) | ||
38 | ## Load config and mail. | ||
39 | #set($config = {}) | ||
40 | #loadInvitationConfig($config) | ||
41 | #set($mail = {}) | ||
42 | #set($emailContainer = $xwiki.getDocumentAsAuthor($config.get('emailContainer'))) | ||
43 | #loadInvitationMail($config, $emailContainer, $mail) | ||
44 | ## | ||
45 | ## Load CSS | ||
46 | $xwiki.get('ssx').use($config.get('commonPage')) | ||
47 | ## | ||
48 | ## Don't load comments, history, etc. | ||
49 | #set($docextras = []) | ||
50 | ## | ||
51 | #doAction($request.getParameter('messageID'), | ||
52 | $action, | ||
53 | $request.getParameter('memo'), | ||
54 | $request.getParameter('confirm'), | ||
55 | $mail, | ||
56 | $emailContainer) | ||
57 | #else | ||
58 | {{info}}$services.localization.render('xe.invitation.internalDocument', ["${doc.getSpace()}.WebHome"]){{/info}} | ||
59 | #end | ||
60 | ## | ||
61 | ##--------------------------------------------------------------------- | ||
62 | ## The macros (Nothing below this point is run directly) | ||
63 | ##--------------------------------------------------------------------- | ||
64 | ## | ||
65 | #* | ||
66 | * Do a guest allowed action on a single message. | ||
67 | * | ||
68 | * Action codes: | ||
69 | * accept (message status code must be 1) | ||
70 | * decline (message status code must be 1) | ||
71 | * report (as spam) (message status code must not be 6) | ||
72 | * else - unknown code | ||
73 | * | ||
74 | * $messageID (String) the unique ID of the invitation to act upon. | ||
75 | * | ||
76 | * $action (String) the action to do. | ||
77 | * | ||
78 | * $memo (String) an action specific message to attach to the mail EG: reason for declining, | ||
79 | * or results of spam investigation. | ||
80 | * | ||
81 | * $confirm (Boolean) are you sure you want to do this? | ||
82 | * | ||
83 | * $mail (Map<String, XObject>) the map of stored messages by their id. | ||
84 | * | ||
85 | * $emailContainer (Document) the document to save after changing objects. | ||
86 | *### | ||
87 | #macro(doAction, $messageID, $action, $memo, $confirm, $mail, $emailContainer) | ||
88 | ## | ||
89 | ## 1. get message. (If it's invalid will be '' and each action handles differently.) | ||
90 | #set($message = '') | ||
91 | #set($message = $mail.get($messageID)) | ||
92 | #if($message != '') | ||
93 | #set($status = $message.getProperty('status').getValue()) | ||
94 | #end | ||
95 | #set($oldMemo = "#getLastMemo($message)") | ||
96 | |||
97 | ## 3. Do action. | ||
98 | #if($action == 'accept') | ||
99 | ## Accept invitation. <------------------------------------------------------------------------ | ||
100 | = $services.localization.render('xe.invitation.doAction.accept.heading') = | ||
101 | #if("$!message" == '') | ||
102 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.noMessageFound'){{/error}} | ||
103 | #elseif($status == 'accepted') | ||
104 | ## already accepted | ||
105 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyAccepted'){{/error}} | ||
106 | #elseif($status == 'declined') | ||
107 | ## already declined | ||
108 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyDeclined'){{/error}} | ||
109 | #elseif($status == 'canceled') | ||
110 | ## invitation canceled. | ||
111 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.accept.invitationCanceled') | ||
112 | #if("$!oldMemo" != '') | ||
113 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', | ||
114 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]) | ||
115 | $oldMemo | ||
116 | #end | ||
117 | {{/error}} | ||
118 | #elseif($status == 'reported' || $status == 'notSpam') | ||
119 | ## reported as spam, nolonger valid. | ||
120 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyReportedAsSpam'){{/error}} | ||
121 | #elseif($status != 'pending') | ||
122 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} | ||
123 | #else | ||
124 | #if("#canGuestAcceptInvitation($doc)" != 'true') | ||
125 | ## | ||
126 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.improperConfiguration'){{/error}} | ||
127 | #else | ||
128 | #define($doAfterRegistration) | ||
129 | #setMessageStatus($message, 'accepted') | ||
130 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.accept.saveComment')) | ||
131 | #end | ||
132 | #set($invited = true) | ||
133 | {{include reference="XWiki.Registration"/}} | ||
134 | #end | ||
135 | #end | ||
136 | #elseif($action == 'decline') | ||
137 | ## Decline Invitation <------------------------------------------------------------------------ | ||
138 | = $services.localization.render('xe.invitation.doAction.decline.heading') = | ||
139 | #if("$!message" == '') | ||
140 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.noMessageFound'){{/error}} | ||
141 | #elseif($status == 'accepted') | ||
142 | ## already accepted | ||
143 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyAccepted'){{/error}} | ||
144 | #elseif($status == 'declined') | ||
145 | ## already declined | ||
146 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyDeclined'){{/error}} | ||
147 | #elseif($status == 'canceled') | ||
148 | ## invitation canceled. | ||
149 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.decline.invitationCanceled') | ||
150 | #if("$!oldMemo" != '') | ||
151 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', | ||
152 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]) | ||
153 | $oldMemo | ||
154 | #end | ||
155 | {{/error}}))) | ||
156 | #elseif($status == 'reported' || $status == 'notSpam') | ||
157 | ## reported as spam, nolonger valid. | ||
158 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyReportedAsSpam'){{/error}} | ||
159 | #elseif($status != 'pending') | ||
160 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} | ||
161 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | ||
162 | #setMessageStatus($message, 'declined', $memo)## | ||
163 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.decline.saveComment')) | ||
164 | {{info}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.success'){{/info}} | ||
165 | #else | ||
166 | ## Are you sure?... | ||
167 | #displayActionConfirmationForm([$messageID], | ||
168 | $action, | ||
169 | $services.localization.render('xe.invitation.doAction.decline.memoLabel', | ||
170 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]), | ||
171 | $services.localization.render('xe.invitation.doAction.decline.confirmLabel'), | ||
172 | {}) | ||
173 | #end | ||
174 | #elseif($action == 'report') | ||
175 | ## Report Abuse <------------------------------------------------------------------------------ | ||
176 | = $services.localization.render('xe.invitation.doAction.reportSpam.heading') = | ||
177 | #if("$!message" == '') | ||
178 | ## No message found by that id. | ||
179 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.noMessageFound'){{/error}} | ||
180 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | ||
181 | #setMessageStatus($message, 'reported', $memo)## | ||
182 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.reportSpam.reportSaveComment')) | ||
183 | ## Your report has been logged, sorry for the inconvienence. | ||
184 | {{info}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.success'){{/info}} | ||
185 | #else | ||
186 | ## Are you sure?... | ||
187 | == $services.localization.render('xe.invitation.doAction.reportSpam.areYouSure') == | ||
188 | #displayActionConfirmationForm([$messageID], | ||
189 | $action, | ||
190 | $services.localization.render('xe.invitation.doAction.reportSpam.memoLabel'), | ||
191 | $services.localization.render('xe.invitation.doAction.confirmLabel'), | ||
192 | {}) | ||
193 | #displayMessage($message) | ||
194 | #end | ||
195 | |||
196 | #else | ||
197 | ## Should not happen | ||
198 | Invalid action | ||
199 | #end | ||
200 | #end | ||
201 | {{/velocity}} |