Wiki-Quellcode von InvitationGuestActions
Zuletzt geändert von base4it Admin am 2025/11/04 19:31
Verstecke letzte Bearbeiter
| 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. | ||
| 49 | #set ($displayDocExtra = false) | ||
| 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. <------------------------------------------------------------------------ | ||
| 102 | = $services.localization.render('xe.invitation.doAction.accept.heading') = | ||
| 103 | #if("$!message" == '') | ||
| 104 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.noMessageFound'){{/error}} | ||
| 105 | #elseif($status == 'accepted') | ||
| 106 | ## already accepted | ||
| 107 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyAccepted'){{/error}} | ||
| 108 | #elseif($status == 'declined') | ||
| 109 | ## already declined | ||
| 110 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyDeclined'){{/error}} | ||
| 111 | #elseif($status == 'canceled') | ||
| 112 | ## invitation canceled. | ||
| 113 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.accept.invitationCanceled') | ||
| 114 | #if("$!oldMemo" != '') | ||
| 115 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', | ||
| 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. | ||
| 122 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.alreadyReportedAsSpam'){{/error}} | ||
| 123 | #elseif($status != 'pending') | ||
| 124 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} | ||
| 125 | #else | ||
| 126 | #if("#canGuestAcceptInvitation($doc)" != 'true') | ||
| 127 | ## | ||
| 128 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.accept.improperConfiguration'){{/error}} | ||
| 129 | #else | ||
| 130 | #define($doAfterRegistration) | ||
| 131 | #setMessageStatus($message, 'accepted') | ||
| 132 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.accept.saveComment')) | ||
| 133 | #end | ||
| 134 | #set($invited = true) | ||
| 135 | {{include reference="XWiki.Registration"/}} | ||
| 136 | #end | ||
| 137 | #end | ||
| 138 | #elseif($action == 'decline') | ||
| 139 | ## Decline Invitation <------------------------------------------------------------------------ | ||
| 140 | = $services.localization.render('xe.invitation.doAction.decline.heading') = | ||
| 141 | #if("$!message" == '') | ||
| 142 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.noMessageFound'){{/error}} | ||
| 143 | #elseif($status == 'accepted') | ||
| 144 | ## already accepted | ||
| 145 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyAccepted'){{/error}} | ||
| 146 | #elseif($status == 'declined') | ||
| 147 | ## already declined | ||
| 148 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyDeclined'){{/error}} | ||
| 149 | #elseif($status == 'canceled') | ||
| 150 | ## invitation canceled. | ||
| 151 | (%id="invitation-action-message"%)((({{error}}$services.localization.render('xe.invitation.doAction.decline.invitationCanceled') | ||
| 152 | #if("$!oldMemo" != '') | ||
| 153 | $services.localization.render('xe.invitation.doAction.invitationCanceledMemo', | ||
| 154 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]) | ||
| 155 | $oldMemo | ||
| 156 | #end | ||
| 157 | {{/error}}))) | ||
| 158 | #elseif($status == 'reported' || $status == 'notSpam') | ||
| 159 | ## reported as spam, nolonger valid. | ||
| 160 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.alreadyReportedAsSpam'){{/error}} | ||
| 161 | #elseif($status != 'pending') | ||
| 162 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.invalidStatus', ["#messageStatusForCode($status)"]){{/error}} | ||
| 163 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | ||
| 164 | #setMessageStatus($message, 'declined', $memo)## | ||
| 165 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.decline.saveComment')) | ||
| 166 | {{info}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.decline.success'){{/info}} | ||
| 167 | #else | ||
| 168 | ## Are you sure?... | ||
| 169 | #displayActionConfirmationForm([$messageID], | ||
| 170 | $action, | ||
| 171 | $services.localization.render('xe.invitation.doAction.decline.memoLabel', | ||
| 172 | [$xwiki.getUserName($message.getProperty('sendingUser').getValue(), false)]), | ||
| 173 | $services.localization.render('xe.invitation.doAction.decline.confirmLabel'), | ||
| 174 | {}) | ||
| 175 | #end | ||
| 176 | #elseif($action == 'report') | ||
| 177 | ## Report Abuse <------------------------------------------------------------------------------ | ||
| 178 | = $services.localization.render('xe.invitation.doAction.reportSpam.heading') = | ||
| 179 | #if("$!message" == '') | ||
| 180 | ## No message found by that id. | ||
| 181 | {{error}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.noMessageFound'){{/error}} | ||
| 182 | #elseif($confirm && ${services.csrf.isTokenValid("$!{request.getParameter('form_token')}")}) | ||
| 183 | #setMessageStatus($message, 'reported', $memo)## | ||
| 184 | $emailContainer.saveAsAuthor($services.localization.render('xe.invitation.doAction.reportSpam.reportSaveComment')) | ||
| 185 | ## Your report has been logged, sorry for the inconvienence. | ||
| 186 | {{info}}(%id="invitation-action-message"%)$services.localization.render('xe.invitation.doAction.reportSpam.success'){{/info}} | ||
| 187 | #else | ||
| 188 | ## Are you sure?... | ||
| 189 | == $services.localization.render('xe.invitation.doAction.reportSpam.areYouSure') == | ||
| 190 | #displayActionConfirmationForm([$messageID], | ||
| 191 | $action, | ||
| 192 | $services.localization.render('xe.invitation.doAction.reportSpam.memoLabel'), | ||
| 193 | $services.localization.render('xe.invitation.doAction.confirmLabel'), | ||
| 194 | {}) | ||
| 195 | #displayMessage($message) | ||
| 196 | #end | ||
| 197 | |||
| 198 | #else | ||
| 199 | ## Should not happen | ||
| 200 | Invalid action | ||
| 201 | #end | ||
| 202 | #end | ||
| 203 | {{/velocity}} |