Wiki source code of InvitationGuestActions
Last modified by Ecaterina Valica on 2018/09/25 12:16
Hide last authors
author | version | line-number | content |
---|---|---|---|
6.1 | 1 | {{include reference="Invitation.InvitationCommon" /}} | |
1.1 | 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. | ||
7.1 | 49 | #set ($displayDocExtra = false) | |
1.1 | 50 | ## | |
51 | #doAction($request.getParameter('messageID'), | ||
52 | $action, | ||
53 | $request.getParameter('memo'), | ||
54 | $request.getParameter('confirm'), | ||
55 | $mail, | ||
56 | $emailContainer) | ||
57 | #else | ||
5.1 | 58 | {{info}}$services.localization.render('xe.invitation.internalDocument', ["${doc.getSpace()}.WebHome"]){{/info}} | |
1.1 | 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. <------------------------------------------------------------------------ | ||
5.1 | 100 | = $services.localization.render('xe.invitation.doAction.accept.heading') = | |
1.1 | 101 | #if("$!message" == '') | |
5.1 | 102 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.noMessageFound'){{/error}} | |
1.1 | 103 | #elseif($status == 'accepted') | |
104 | ## already accepted | ||
5.1 | 105 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyAccepted'){{/error}} | |
1.1 | 106 | #elseif($status == 'declined') | |
107 | ## already declined | ||
5.1 | 108 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyDeclined'){{/error}} | |
1.1 | 109 | #elseif($status == 'canceled') | |
110 | ## invitation canceled. | ||
5.1 | 111 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.accept.invitationCanceled') | |
1.1 | 112 | #if("$!oldMemo" != '') | |
5.1 | 113 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', | |
1.1 | 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. | ||
5.1 | 120 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyReportedAsSpam'){{/error}} | |
1.1 | 121 | #elseif($status != 'pending') | |
5.1 | 122 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} | |
1.1 | 123 | #else | |
124 | #if("#canGuestAcceptInvitation($doc)" != 'true') | ||
125 | ## | ||
5.1 | 126 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.improperConfiguration'){{/error}} | |
1.1 | 127 | #else | |
128 | #define($doAfterRegistration) | ||
129 | #setMessageStatus($message, 'accepted') | ||
5.1 | 130 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.accept.saveComment')) | |
1.1 | 131 | #end | |
132 | #set($invited = true) | ||
6.1 | 133 | {{include reference="XWiki.Registration"/}} | |
1.1 | 134 | #end | |
135 | #end | ||
136 | #elseif($action == 'decline') | ||
137 | ## Decline Invitation <------------------------------------------------------------------------ | ||
5.1 | 138 | = $services.localization.render('xe.invitation.doAction.decline.heading') = | |
1.1 | 139 | #if("$!message" == '') | |
5.1 | 140 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.noMessageFound'){{/error}} | |
1.1 | 141 | #elseif($status == 'accepted') | |
142 | ## already accepted | ||
5.1 | 143 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyAccepted'){{/error}} | |
1.1 | 144 | #elseif($status == 'declined') | |
145 | ## already declined | ||
5.1 | 146 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyDeclined'){{/error}} | |
1.1 | 147 | #elseif($status == 'canceled') | |
148 | ## invitation canceled. | ||
5.1 | 149 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.decline.invitationCanceled') | |
1.1 | 150 | #if("$!oldMemo" != '') | |
5.1 | 151 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', | |
1.1 | 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. | ||
5.1 | 158 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyReportedAsSpam'){{/error}} | |
1.1 | 159 | #elseif($status != 'pending') | |
5.1 | 160 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} | |
2.1 | 161 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | |
1.1 | 162 | #setMessageStatus($message, 'declined', $memo)## | |
5.1 | 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}} | ||
1.1 | 165 | #else | |
166 | ## Are you sure?... | ||
167 | #displayActionConfirmationForm([$messageID], | ||
168 | $action, | ||
5.1 | 169 | $services.localization.render('xe.invitation.doAction.decline.memoLabel', | |
1.1 | 170 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]), | |
5.1 | 171 | $services.localization.render('xe.invitation.doAction.decline.confirmLabel'), | |
1.1 | 172 | {}) | |
173 | #end | ||
174 | #elseif($action == 'report') | ||
175 | ## Report Abuse <------------------------------------------------------------------------------ | ||
5.1 | 176 | = $services.localization.render('xe.invitation.doAction.reportSpam.heading') = | |
1.1 | 177 | #if("$!message" == '') | |
178 | ## No message found by that id. | ||
5.1 | 179 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.noMessageFound'){{/error}} | |
2.1 | 180 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | |
1.1 | 181 | #setMessageStatus($message, 'reported', $memo)## | |
5.1 | 182 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.reportSpam.reportSaveComment')) | |
1.1 | 183 | ## Your report has been logged, sorry for the inconvienence. | |
5.1 | 184 | {{info}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.success'){{/info}} | |
1.1 | 185 | #else | |
186 | ## Are you sure?... | ||
5.1 | 187 | == $services.localization.render('xe.invitation.doAction.reportSpam.areYouSure') == | |
1.1 | 188 | #displayActionConfirmationForm([$messageID], | |
189 | $action, | ||
5.1 | 190 | $services.localization.render('xe.invitation.doAction.reportSpam.memoLabel'), | |
191 | $services.localization.render('xe.invitation.doAction.confirmLabel'), | ||
1.1 | 192 | {}) | |
193 | #displayMessage($message) | ||
194 | #end | ||
195 | |||
196 | #else | ||
197 | ## Should not happen | ||
198 | Invalid action | ||
199 | #end | ||
200 | #end | ||
201 | {{/velocity}} |