Wiki source code of InvitationGuestActions
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
2.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. | ||
| |
2.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 | ||
| |
2.1 | 58 | #set ($linkTarget = "${doc.getSpace()}.WebHome") |
| 59 | #set ($linkTarget = $services.rendering.escape($linkTarget, 'xwiki/2.1')) | ||
| 60 | {{info}}$services.localization.render('xe.invitation.internalDocument', [$linkTarget]){{/info}} | ||
| |
1.1 | 61 | #end |
| 62 | ## | ||
| 63 | ##--------------------------------------------------------------------- | ||
| 64 | ## The macros (Nothing below this point is run directly) | ||
| 65 | ##--------------------------------------------------------------------- | ||
| 66 | ## | ||
| 67 | #* | ||
| 68 | * Do a guest allowed action on a single message. | ||
| 69 | * | ||
| 70 | * Action codes: | ||
| 71 | * accept (message status code must be 1) | ||
| 72 | * decline (message status code must be 1) | ||
| 73 | * report (as spam) (message status code must not be 6) | ||
| 74 | * else - unknown code | ||
| 75 | * | ||
| 76 | * $messageID (String) the unique ID of the invitation to act upon. | ||
| 77 | * | ||
| 78 | * $action (String) the action to do. | ||
| 79 | * | ||
| 80 | * $memo (String) an action specific message to attach to the mail EG: reason for declining, | ||
| 81 | * or results of spam investigation. | ||
| 82 | * | ||
| 83 | * $confirm (Boolean) are you sure you want to do this? | ||
| 84 | * | ||
| 85 | * $mail (Map<String, XObject>) the map of stored messages by their id. | ||
| 86 | * | ||
| 87 | * $emailContainer (Document) the document to save after changing objects. | ||
| 88 | *### | ||
| 89 | #macro(doAction, $messageID, $action, $memo, $confirm, $mail, $emailContainer) | ||
| 90 | ## | ||
| 91 | ## 1. get message. (If it's invalid will be '' and each action handles differently.) | ||
| 92 | #set($message = '') | ||
| 93 | #set($message = $mail.get($messageID)) | ||
| 94 | #if($message != '') | ||
| 95 | #set($status = $message.getProperty('status').getValue()) | ||
| 96 | #end | ||
| 97 | #set($oldMemo = "#getLastMemo($message)") | ||
| 98 | |||
| 99 | ## 3. Do action. | ||
| 100 | #if($action == 'accept') | ||
| 101 | ## Accept invitation. <------------------------------------------------------------------------ | ||
| |
2.1 | 102 | = $services.localization.render('xe.invitation.doAction.accept.heading') = |
| |
1.1 | 103 | #if("$!message" == '') |
| |
2.1 | 104 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.noMessageFound'){{/error}} |
| |
1.1 | 105 | #elseif($status == 'accepted') |
| 106 | ## already accepted | ||
| |
2.1 | 107 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyAccepted'){{/error}} |
| |
1.1 | 108 | #elseif($status == 'declined') |
| 109 | ## already declined | ||
| |
2.1 | 110 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyDeclined'){{/error}} |
| |
1.1 | 111 | #elseif($status == 'canceled') |
| 112 | ## invitation canceled. | ||
| |
2.1 | 113 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.accept.invitationCanceled') |
| |
1.1 | 114 | #if("$!oldMemo" != '') |
| |
2.1 | 115 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', |
| |
1.1 | 116 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]) |
| 117 | $oldMemo | ||
| 118 | #end | ||
| 119 | {{/error}} | ||
| 120 | #elseif($status == 'reported' || $status == 'notSpam') | ||
| 121 | ## reported as spam, nolonger valid. | ||
| |
2.1 | 122 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyReportedAsSpam'){{/error}} |
| |
1.1 | 123 | #elseif($status != 'pending') |
| |
2.1 | 124 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} |
| |
1.1 | 125 | #else |
| 126 | #if("#canGuestAcceptInvitation($doc)" != 'true') | ||
| 127 | ## | ||
| |
2.1 | 128 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.improperConfiguration'){{/error}} |
| |
1.1 | 129 | #else |
| 130 | #define($doAfterRegistration) | ||
| 131 | #setMessageStatus($message, 'accepted') | ||
| |
2.1 | 132 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.accept.saveComment')) |
| |
1.1 | 133 | #end |
| |
2.1 | 134 | ## Allow the guest to register even if the register right is denied. It's only possible when this document |
| 135 | ## has programming right (see canGuestAcceptInvitation), and it applies only to the registration page included | ||
| 136 | ## right after. | ||
| 137 | #set ($discard = $services.security.registration.allowInvitedRegistration()) | ||
| 138 | {{include reference="XWiki.Registration"/}} | ||
| |
1.1 | 139 | #end |
| 140 | #end | ||
| 141 | #elseif($action == 'decline') | ||
| 142 | ## Decline Invitation <------------------------------------------------------------------------ | ||
| |
2.1 | 143 | = $services.localization.render('xe.invitation.doAction.decline.heading') = |
| |
1.1 | 144 | #if("$!message" == '') |
| |
2.1 | 145 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.noMessageFound'){{/error}} |
| |
1.1 | 146 | #elseif($status == 'accepted') |
| 147 | ## already accepted | ||
| |
2.1 | 148 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyAccepted'){{/error}} |
| |
1.1 | 149 | #elseif($status == 'declined') |
| 150 | ## already declined | ||
| |
2.1 | 151 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyDeclined'){{/error}} |
| |
1.1 | 152 | #elseif($status == 'canceled') |
| 153 | ## invitation canceled. | ||
| |
2.1 | 154 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.decline.invitationCanceled') |
| |
1.1 | 155 | #if("$!oldMemo" != '') |
| |
2.1 | 156 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', |
| |
1.1 | 157 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]) |
| 158 | $oldMemo | ||
| 159 | #end | ||
| 160 | {{/error}}))) | ||
| 161 | #elseif($status == 'reported' || $status == 'notSpam') | ||
| 162 | ## reported as spam, nolonger valid. | ||
| |
2.1 | 163 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyReportedAsSpam'){{/error}} |
| |
1.1 | 164 | #elseif($status != 'pending') |
| |
2.1 | 165 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} |
| 166 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | ||
| |
1.1 | 167 | #setMessageStatus($message, 'declined', $memo)## |
| |
2.1 | 168 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.decline.saveComment')) |
| 169 | {{info}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.success'){{/info}} | ||
| |
1.1 | 170 | #else |
| 171 | ## Are you sure?... | ||
| 172 | #displayActionConfirmationForm([$messageID], | ||
| 173 | $action, | ||
| |
2.1 | 174 | $services.localization.render('xe.invitation.doAction.decline.memoLabel', |
| |
1.1 | 175 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]), |
| |
2.1 | 176 | $services.localization.render('xe.invitation.doAction.decline.confirmLabel'), |
| |
1.1 | 177 | {}) |
| 178 | #end | ||
| 179 | #elseif($action == 'report') | ||
| 180 | ## Report Abuse <------------------------------------------------------------------------------ | ||
| |
2.1 | 181 | = $services.localization.render('xe.invitation.doAction.reportSpam.heading') = |
| |
1.1 | 182 | #if("$!message" == '') |
| 183 | ## No message found by that id. | ||
| |
2.1 | 184 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.noMessageFound'){{/error}} |
| 185 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | ||
| |
1.1 | 186 | #setMessageStatus($message, 'reported', $memo)## |
| |
2.1 | 187 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.reportSpam.reportSaveComment')) |
| |
1.1 | 188 | ## Your report has been logged, sorry for the inconvienence. |
| |
2.1 | 189 | {{info}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.success'){{/info}} |
| |
1.1 | 190 | #else |
| 191 | ## Are you sure?... | ||
| |
2.1 | 192 | == $services.localization.render('xe.invitation.doAction.reportSpam.areYouSure') == |
| |
1.1 | 193 | #displayActionConfirmationForm([$messageID], |
| 194 | $action, | ||
| |
2.1 | 195 | $services.localization.render('xe.invitation.doAction.reportSpam.memoLabel'), |
| 196 | $services.localization.render('xe.invitation.doAction.confirmLabel'), | ||
| |
1.1 | 197 | {}) |
| 198 | #displayMessage($message) | ||
| 199 | #end | ||
| 200 | |||
| 201 | #else | ||
| 202 | ## Should not happen | ||
| 203 | Invalid action | ||
| 204 | #end | ||
| 205 | #end | ||
| 206 | {{/velocity}} |