@@ -15,22 +15,22 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageDropRequest extends PageCloseRequest |
| 17 | 17 | { |
| 18 | - protected function getTemplate(PdoDatabase $database) |
|
| 19 | - { |
|
| 20 | - return EmailTemplate::getDroppedTemplate(); |
|
| 21 | - } |
|
| 18 | + protected function getTemplate(PdoDatabase $database) |
|
| 19 | + { |
|
| 20 | + return EmailTemplate::getDroppedTemplate(); |
|
| 21 | + } |
|
| 22 | 22 | |
| 23 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | - { |
|
| 25 | - return false; |
|
| 26 | - } |
|
| 23 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 24 | + { |
|
| 25 | + return false; |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | - { |
|
| 30 | - return false; |
|
| 31 | - } |
|
| 28 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 29 | + { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 34 | - { |
|
| 35 | - } |
|
| 33 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 34 | + { |
|
| 35 | + } |
|
| 36 | 36 | } |
| 37 | 37 | \ No newline at end of file |
@@ -21,231 +21,231 @@ |
||
| 21 | 21 | |
| 22 | 22 | class PageCloseRequest extends RequestActionBase |
| 23 | 23 | { |
| 24 | - protected function main() |
|
| 25 | - { |
|
| 26 | - $this->processClose(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Main function for this page, when no specific actions are called. |
|
| 31 | - * @throws ApplicationLogicException |
|
| 32 | - */ |
|
| 33 | - final protected function processClose() |
|
| 34 | - { |
|
| 35 | - $this->checkPosted(); |
|
| 36 | - $database = $this->getDatabase(); |
|
| 37 | - |
|
| 38 | - $currentUser = User::getCurrent($database); |
|
| 39 | - $template = $this->getTemplate($database); |
|
| 40 | - $request = $this->getRequest($database); |
|
| 41 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 42 | - |
|
| 43 | - if ($request->getStatus() === 'Closed') { |
|
| 44 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 48 | - return; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if ($this->checkReserveProtect($request, $currentUser)) { |
|
| 52 | - return; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - if ($this->confirmAccountCreated($request, $template)) { |
|
| 56 | - return; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // I think we're good here... |
|
| 60 | - $request->setStatus('Closed'); |
|
| 61 | - $request->setReserved(null); |
|
| 62 | - |
|
| 63 | - Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 64 | - |
|
| 65 | - $request->save(); |
|
| 66 | - |
|
| 67 | - $this->processWelcome($template->getDefaultAction()); |
|
| 68 | - |
|
| 69 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 70 | - // be rolled back. |
|
| 71 | - |
|
| 72 | - $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 73 | - $sanitisedTemplateName = htmlentities($template->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 74 | - SessionAlert::success("Request {$request->getId()} has been closed as {$sanitisedTemplateName}"); |
|
| 75 | - |
|
| 76 | - $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 77 | - |
|
| 78 | - $this->redirect(); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @param PdoDatabase $database |
|
| 83 | - * |
|
| 84 | - * @return EmailTemplate |
|
| 85 | - * @throws ApplicationLogicException |
|
| 86 | - */ |
|
| 87 | - protected function getTemplate(PdoDatabase $database) |
|
| 88 | - { |
|
| 89 | - $templateId = WebRequest::postInt('template'); |
|
| 90 | - if ($templateId === null) { |
|
| 91 | - throw new ApplicationLogicException('No template specified'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** @var EmailTemplate $template */ |
|
| 95 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 96 | - if ($template === false || !$template->getActive()) { |
|
| 97 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return $template; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param Request $request |
|
| 105 | - * @param EmailTemplate $template |
|
| 106 | - * |
|
| 107 | - * @return bool |
|
| 108 | - */ |
|
| 109 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 110 | - { |
|
| 111 | - if ($this->checkEmailAlreadySent($request)) { |
|
| 112 | - $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 113 | - |
|
| 114 | - return true; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - protected function checkEmailAlreadySent(Request $request) |
|
| 121 | - { |
|
| 122 | - if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 123 | - return true; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return false; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - protected function checkReserveProtect(Request $request, User $currentUser) |
|
| 130 | - { |
|
| 131 | - $reservationId = $request->getReserved(); |
|
| 132 | - |
|
| 133 | - if ($reservationId !== 0 && $reservationId !== null) { |
|
| 134 | - if ($currentUser->getId() !== $reservationId) { |
|
| 135 | - SessionAlert::error("Request is reserved by someone else."); |
|
| 136 | - $this->redirect('/viewRequest', null, ['id' => $request->getId()] ); |
|
| 137 | - return true; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return false; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param Request $request |
|
| 146 | - * @param EmailTemplate $template |
|
| 147 | - * |
|
| 148 | - * @return bool |
|
| 149 | - * @throws Exception |
|
| 150 | - */ |
|
| 151 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 152 | - { |
|
| 153 | - if ($this->checkAccountCreated($request, $template)) { |
|
| 154 | - $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 155 | - |
|
| 156 | - return true; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return false; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 163 | - { |
|
| 164 | - if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 165 | - $parameters = array( |
|
| 166 | - 'action' => 'query', |
|
| 167 | - 'list' => 'users', |
|
| 168 | - 'format' => 'php', |
|
| 169 | - 'ususers' => $request->getName(), |
|
| 170 | - ); |
|
| 171 | - |
|
| 172 | - $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 173 | - $parameters); |
|
| 174 | - |
|
| 175 | - $apiResult = unserialize($content); |
|
| 176 | - $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 177 | - |
|
| 178 | - if (!$exists) { |
|
| 179 | - return true; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return false; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * @param Request $request |
|
| 188 | - * @param string $mailText |
|
| 189 | - * @param User $currentUser |
|
| 190 | - * @param boolean $ccMailingList |
|
| 191 | - */ |
|
| 192 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 193 | - { |
|
| 194 | - $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
| 195 | - $requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList); |
|
| 196 | - |
|
| 197 | - $request->setEmailSent(true); |
|
| 198 | - $request->save(); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @param Request $request |
|
| 203 | - * @param EmailTemplate $template |
|
| 204 | - * @param string $templateName |
|
| 205 | - * |
|
| 206 | - * @throws Exception |
|
| 207 | - * @return void |
|
| 208 | - */ |
|
| 209 | - protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 210 | - { |
|
| 211 | - $this->assignCSRFToken(); |
|
| 212 | - |
|
| 213 | - $this->assign('request', $request->getId()); |
|
| 214 | - $this->assign('template', $template->getId()); |
|
| 215 | - |
|
| 216 | - $this->assign('updateversion', $request->getUpdateVersion()); |
|
| 217 | - |
|
| 218 | - $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 219 | - $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 220 | - $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 221 | - |
|
| 222 | - $this->skipAlerts(); |
|
| 223 | - |
|
| 224 | - $this->setTemplate($templateName); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @param string $action |
|
| 229 | - * |
|
| 230 | - * @throws ApplicationLogicException |
|
| 231 | - */ |
|
| 232 | - final protected function processWelcome(string $action): void |
|
| 233 | - { |
|
| 234 | - $database = $this->getDatabase(); |
|
| 235 | - $currentUser = User::getCurrent($database); |
|
| 236 | - |
|
| 237 | - if ($action !== EmailTemplate::CREATED) { |
|
| 238 | - return; |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - if ($currentUser->getWelcomeTemplate() === null) { |
|
| 242 | - return; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if (WebRequest::postBoolean('skipAutoWelcome')) { |
|
| 246 | - return; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $this->enqueueWelcomeTask($this->getRequest($database), null, $currentUser, $database); |
|
| 250 | - } |
|
| 24 | + protected function main() |
|
| 25 | + { |
|
| 26 | + $this->processClose(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Main function for this page, when no specific actions are called. |
|
| 31 | + * @throws ApplicationLogicException |
|
| 32 | + */ |
|
| 33 | + final protected function processClose() |
|
| 34 | + { |
|
| 35 | + $this->checkPosted(); |
|
| 36 | + $database = $this->getDatabase(); |
|
| 37 | + |
|
| 38 | + $currentUser = User::getCurrent($database); |
|
| 39 | + $template = $this->getTemplate($database); |
|
| 40 | + $request = $this->getRequest($database); |
|
| 41 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 42 | + |
|
| 43 | + if ($request->getStatus() === 'Closed') { |
|
| 44 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + if ($this->confirmEmailAlreadySent($request, $template)) { |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if ($this->checkReserveProtect($request, $currentUser)) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + if ($this->confirmAccountCreated($request, $template)) { |
|
| 56 | + return; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // I think we're good here... |
|
| 60 | + $request->setStatus('Closed'); |
|
| 61 | + $request->setReserved(null); |
|
| 62 | + |
|
| 63 | + Logger::closeRequest($database, $request, $template->getId(), null); |
|
| 64 | + |
|
| 65 | + $request->save(); |
|
| 66 | + |
|
| 67 | + $this->processWelcome($template->getDefaultAction()); |
|
| 68 | + |
|
| 69 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 70 | + // be rolled back. |
|
| 71 | + |
|
| 72 | + $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
| 73 | + $sanitisedTemplateName = htmlentities($template->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 74 | + SessionAlert::success("Request {$request->getId()} has been closed as {$sanitisedTemplateName}"); |
|
| 75 | + |
|
| 76 | + $this->sendMail($request, $template->getText(), $currentUser, false); |
|
| 77 | + |
|
| 78 | + $this->redirect(); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @param PdoDatabase $database |
|
| 83 | + * |
|
| 84 | + * @return EmailTemplate |
|
| 85 | + * @throws ApplicationLogicException |
|
| 86 | + */ |
|
| 87 | + protected function getTemplate(PdoDatabase $database) |
|
| 88 | + { |
|
| 89 | + $templateId = WebRequest::postInt('template'); |
|
| 90 | + if ($templateId === null) { |
|
| 91 | + throw new ApplicationLogicException('No template specified'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** @var EmailTemplate $template */ |
|
| 95 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 96 | + if ($template === false || !$template->getActive()) { |
|
| 97 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return $template; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param Request $request |
|
| 105 | + * @param EmailTemplate $template |
|
| 106 | + * |
|
| 107 | + * @return bool |
|
| 108 | + */ |
|
| 109 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
| 110 | + { |
|
| 111 | + if ($this->checkEmailAlreadySent($request)) { |
|
| 112 | + $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
| 113 | + |
|
| 114 | + return true; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + protected function checkEmailAlreadySent(Request $request) |
|
| 121 | + { |
|
| 122 | + if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
| 123 | + return true; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return false; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + protected function checkReserveProtect(Request $request, User $currentUser) |
|
| 130 | + { |
|
| 131 | + $reservationId = $request->getReserved(); |
|
| 132 | + |
|
| 133 | + if ($reservationId !== 0 && $reservationId !== null) { |
|
| 134 | + if ($currentUser->getId() !== $reservationId) { |
|
| 135 | + SessionAlert::error("Request is reserved by someone else."); |
|
| 136 | + $this->redirect('/viewRequest', null, ['id' => $request->getId()] ); |
|
| 137 | + return true; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param Request $request |
|
| 146 | + * @param EmailTemplate $template |
|
| 147 | + * |
|
| 148 | + * @return bool |
|
| 149 | + * @throws Exception |
|
| 150 | + */ |
|
| 151 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
| 152 | + { |
|
| 153 | + if ($this->checkAccountCreated($request, $template)) { |
|
| 154 | + $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
| 155 | + |
|
| 156 | + return true; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + protected function checkAccountCreated(Request $request, EmailTemplate $template) |
|
| 163 | + { |
|
| 164 | + if ($template->getDefaultAction() === EmailTemplate::CREATED && !WebRequest::postBoolean('createOverride')) { |
|
| 165 | + $parameters = array( |
|
| 166 | + 'action' => 'query', |
|
| 167 | + 'list' => 'users', |
|
| 168 | + 'format' => 'php', |
|
| 169 | + 'ususers' => $request->getName(), |
|
| 170 | + ); |
|
| 171 | + |
|
| 172 | + $content = $this->getHttpHelper()->get($this->getSiteConfiguration()->getMediawikiWebServiceEndpoint(), |
|
| 173 | + $parameters); |
|
| 174 | + |
|
| 175 | + $apiResult = unserialize($content); |
|
| 176 | + $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
| 177 | + |
|
| 178 | + if (!$exists) { |
|
| 179 | + return true; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return false; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * @param Request $request |
|
| 188 | + * @param string $mailText |
|
| 189 | + * @param User $currentUser |
|
| 190 | + * @param boolean $ccMailingList |
|
| 191 | + */ |
|
| 192 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
| 193 | + { |
|
| 194 | + $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
| 195 | + $requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList); |
|
| 196 | + |
|
| 197 | + $request->setEmailSent(true); |
|
| 198 | + $request->save(); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @param Request $request |
|
| 203 | + * @param EmailTemplate $template |
|
| 204 | + * @param string $templateName |
|
| 205 | + * |
|
| 206 | + * @throws Exception |
|
| 207 | + * @return void |
|
| 208 | + */ |
|
| 209 | + protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
| 210 | + { |
|
| 211 | + $this->assignCSRFToken(); |
|
| 212 | + |
|
| 213 | + $this->assign('request', $request->getId()); |
|
| 214 | + $this->assign('template', $template->getId()); |
|
| 215 | + |
|
| 216 | + $this->assign('updateversion', $request->getUpdateVersion()); |
|
| 217 | + |
|
| 218 | + $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
| 219 | + $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
| 220 | + $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
| 221 | + |
|
| 222 | + $this->skipAlerts(); |
|
| 223 | + |
|
| 224 | + $this->setTemplate($templateName); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @param string $action |
|
| 229 | + * |
|
| 230 | + * @throws ApplicationLogicException |
|
| 231 | + */ |
|
| 232 | + final protected function processWelcome(string $action): void |
|
| 233 | + { |
|
| 234 | + $database = $this->getDatabase(); |
|
| 235 | + $currentUser = User::getCurrent($database); |
|
| 236 | + |
|
| 237 | + if ($action !== EmailTemplate::CREATED) { |
|
| 238 | + return; |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + if ($currentUser->getWelcomeTemplate() === null) { |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if (WebRequest::postBoolean('skipAutoWelcome')) { |
|
| 246 | + return; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $this->enqueueWelcomeTask($this->getRequest($database), null, $currentUser, $database); |
|
| 250 | + } |
|
| 251 | 251 | } |
@@ -24,278 +24,278 @@ |
||
| 24 | 24 | |
| 25 | 25 | class PageCustomClose extends PageCloseRequest |
| 26 | 26 | { |
| 27 | - use RequestData; |
|
| 28 | - |
|
| 29 | - protected function main() |
|
| 30 | - { |
|
| 31 | - $database = $this->getDatabase(); |
|
| 32 | - |
|
| 33 | - $request = $this->getRequest($database); |
|
| 34 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 35 | - |
|
| 36 | - if ($request->getStatus() === 'Closed') { |
|
| 37 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // Dual-mode page |
|
| 41 | - if (WebRequest::wasPosted()) { |
|
| 42 | - $this->validateCSRFToken(); |
|
| 43 | - $this->doCustomClose($currentUser, $request, $database); |
|
| 44 | - |
|
| 45 | - $this->redirect(); |
|
| 46 | - } |
|
| 47 | - else { |
|
| 48 | - $this->assignCSRFToken(); |
|
| 49 | - $this->showCustomCloseForm($database, $request); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param $database |
|
| 55 | - * |
|
| 56 | - * @return Request |
|
| 57 | - * @throws ApplicationLogicException |
|
| 58 | - */ |
|
| 59 | - protected function getRequest(PdoDatabase $database) |
|
| 60 | - { |
|
| 61 | - $requestId = WebRequest::getInt('request'); |
|
| 62 | - if ($requestId === null) { |
|
| 63 | - throw new ApplicationLogicException('Request ID not found'); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** @var Request $request */ |
|
| 67 | - $request = Request::getById($requestId, $database); |
|
| 68 | - |
|
| 69 | - if ($request === false) { |
|
| 70 | - throw new ApplicationLogicException('Request not found'); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $request; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param PdoDatabase $database |
|
| 78 | - * |
|
| 79 | - * @return EmailTemplate|null |
|
| 80 | - */ |
|
| 81 | - protected function getTemplate(PdoDatabase $database) |
|
| 82 | - { |
|
| 83 | - $templateId = WebRequest::getInt('template'); |
|
| 84 | - if ($templateId === null) { |
|
| 85 | - return null; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** @var EmailTemplate $template */ |
|
| 89 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 90 | - if ($template === false || !$template->getActive()) { |
|
| 91 | - return null; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - return $template; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param $database |
|
| 99 | - * @param $request |
|
| 100 | - * |
|
| 101 | - * @throws Exception |
|
| 102 | - */ |
|
| 103 | - protected function showCustomCloseForm(PdoDatabase $database, Request $request) |
|
| 104 | - { |
|
| 105 | - $currentUser = User::getCurrent($database); |
|
| 106 | - $config = $this->getSiteConfiguration(); |
|
| 107 | - |
|
| 108 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 109 | - if (!$allowedPrivateData) { |
|
| 110 | - // we probably shouldn't be showing the user this form if they're not allowed to access private data... |
|
| 111 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $template = $this->getTemplate($database); |
|
| 115 | - |
|
| 116 | - // Preload data |
|
| 117 | - $this->assign('defaultAction', ''); |
|
| 118 | - $this->assign('preloadText', ''); |
|
| 119 | - $this->assign('preloadTitle', ''); |
|
| 120 | - |
|
| 121 | - if ($template !== null) { |
|
| 122 | - $this->assign('defaultAction', $template->getDefaultAction()); |
|
| 123 | - $this->assign('preloadText', $template->getText()); |
|
| 124 | - $this->assign('preloadTitle', $template->getName()); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Static data |
|
| 128 | - $this->assign('requeststates', $config->getRequestStates()); |
|
| 129 | - |
|
| 130 | - // request data |
|
| 131 | - $this->assign('requestId', $request->getIp()); |
|
| 132 | - $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 133 | - $this->setupBasicData($request, $config); |
|
| 134 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 135 | - $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 136 | - |
|
| 137 | - // IP location |
|
| 138 | - $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 139 | - $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp)); |
|
| 140 | - |
|
| 141 | - // Confirmations |
|
| 142 | - $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request)); |
|
| 143 | - |
|
| 144 | - $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser)); |
|
| 145 | - |
|
| 146 | - $this->assign('allowWelcomeSkip', false); |
|
| 147 | - $this->assign('forceWelcomeSkip', false); |
|
| 148 | - |
|
| 149 | - $oauth = new OAuthUserHelper($currentUser, $this->getDatabase(), $this->getOAuthProtocolHelper(), $config); |
|
| 150 | - |
|
| 151 | - if ($currentUser->getWelcomeTemplate() != 0) { |
|
| 152 | - $this->assign('allowWelcomeSkip', true); |
|
| 153 | - |
|
| 154 | - if (!$oauth->canWelcome()) { |
|
| 155 | - $this->assign('forceWelcomeSkip', true); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - // template |
|
| 161 | - $this->setTemplate('custom-close.tpl'); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @param User $currentUser |
|
| 166 | - * @param Request $request |
|
| 167 | - * @param PdoDatabase $database |
|
| 168 | - * |
|
| 169 | - * @throws ApplicationLogicException |
|
| 170 | - */ |
|
| 171 | - protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database) |
|
| 172 | - { |
|
| 173 | - $messageBody = WebRequest::postString('msgbody'); |
|
| 174 | - if ($messageBody === null || trim($messageBody) === '') { |
|
| 175 | - throw new ApplicationLogicException('Message body cannot be blank'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $ccMailingList = true; |
|
| 179 | - if ($this->barrierTest('skipCcMailingList', $currentUser)) { |
|
| 180 | - $ccMailingList = WebRequest::postBoolean('ccMailingList'); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - if ($request->getStatus() === 'Closed') { |
|
| 184 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - if (!(WebRequest::postBoolean('confirmEmailAlreadySent')) |
|
| 188 | - ) { |
|
| 189 | - throw new ApplicationLogicException('Not all confirmations checked'); |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $action = WebRequest::postString('action'); |
|
| 193 | - $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 194 | - |
|
| 195 | - if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) { |
|
| 196 | - // Close request |
|
| 197 | - $this->closeRequest($request, $database, $action, $messageBody); |
|
| 198 | - |
|
| 199 | - $this->processWelcome($action); |
|
| 200 | - |
|
| 201 | - // Send the mail after the save, since save can be rolled back |
|
| 202 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 203 | - } |
|
| 204 | - else { |
|
| 205 | - if (array_key_exists($action, $availableRequestStates)) { |
|
| 206 | - // Defer to other state |
|
| 207 | - $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody); |
|
| 208 | - |
|
| 209 | - // Send the mail after the save, since save can be rolled back |
|
| 210 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 211 | - } |
|
| 212 | - else { |
|
| 213 | - $request->setReserved(null); |
|
| 214 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 215 | - $request->save(); |
|
| 216 | - |
|
| 217 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 218 | - // and be rolled back. |
|
| 219 | - |
|
| 220 | - // Send mail |
|
| 221 | - $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 222 | - |
|
| 223 | - Logger::sentMail($database, $request, $messageBody); |
|
| 224 | - Logger::unreserve($database, $request); |
|
| 225 | - |
|
| 226 | - $this->getNotificationHelper()->sentMail($request); |
|
| 227 | - SessionAlert::success("Sent mail to Request {$request->getId()}"); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * @param Request $request |
|
| 234 | - * @param PdoDatabase $database |
|
| 235 | - * @param string $action |
|
| 236 | - * @param string $messageBody |
|
| 237 | - * |
|
| 238 | - * @throws Exception |
|
| 239 | - * @throws OptimisticLockFailedException |
|
| 240 | - */ |
|
| 241 | - protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody) |
|
| 242 | - { |
|
| 243 | - $request->setStatus('Closed'); |
|
| 244 | - $request->setReserved(null); |
|
| 245 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 246 | - $request->save(); |
|
| 247 | - |
|
| 248 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 249 | - // be rolled back. |
|
| 250 | - |
|
| 251 | - if ($action == EmailTemplate::CREATED) { |
|
| 252 | - $logCloseType = 'custom-y'; |
|
| 253 | - $notificationCloseType = "Custom, Created"; |
|
| 254 | - } |
|
| 255 | - else { |
|
| 256 | - $logCloseType = 'custom-n'; |
|
| 257 | - $notificationCloseType = "Custom, Not Created"; |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - Logger::closeRequest($database, $request, $logCloseType, $messageBody); |
|
| 261 | - $this->getNotificationHelper()->requestClosed($request, $notificationCloseType); |
|
| 262 | - |
|
| 263 | - $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 264 | - SessionAlert::success("Request {$request->getId()} ({$requestName}) closed as {$notificationCloseType}."); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @param Request $request |
|
| 269 | - * @param PdoDatabase $database |
|
| 270 | - * @param string $action |
|
| 271 | - * @param $availableRequestStates |
|
| 272 | - * @param string $messageBody |
|
| 273 | - * |
|
| 274 | - * @throws Exception |
|
| 275 | - * @throws OptimisticLockFailedException |
|
| 276 | - */ |
|
| 277 | - protected function deferRequest( |
|
| 278 | - Request $request, |
|
| 279 | - PdoDatabase $database, |
|
| 280 | - $action, |
|
| 281 | - $availableRequestStates, |
|
| 282 | - $messageBody |
|
| 283 | - ) { |
|
| 284 | - $request->setStatus($action); |
|
| 285 | - $request->setReserved(null); |
|
| 286 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 287 | - $request->save(); |
|
| 288 | - |
|
| 289 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 290 | - // and be rolled back. |
|
| 291 | - |
|
| 292 | - $deferToLog = $availableRequestStates[$action]['defertolog']; |
|
| 293 | - Logger::sentMail($database, $request, $messageBody); |
|
| 294 | - Logger::deferRequest($database, $request, $deferToLog); |
|
| 295 | - |
|
| 296 | - $this->getNotificationHelper()->requestDeferredWithMail($request); |
|
| 297 | - |
|
| 298 | - $deferTo = $availableRequestStates[$action]['deferto']; |
|
| 299 | - SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email."); |
|
| 300 | - } |
|
| 27 | + use RequestData; |
|
| 28 | + |
|
| 29 | + protected function main() |
|
| 30 | + { |
|
| 31 | + $database = $this->getDatabase(); |
|
| 32 | + |
|
| 33 | + $request = $this->getRequest($database); |
|
| 34 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 35 | + |
|
| 36 | + if ($request->getStatus() === 'Closed') { |
|
| 37 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // Dual-mode page |
|
| 41 | + if (WebRequest::wasPosted()) { |
|
| 42 | + $this->validateCSRFToken(); |
|
| 43 | + $this->doCustomClose($currentUser, $request, $database); |
|
| 44 | + |
|
| 45 | + $this->redirect(); |
|
| 46 | + } |
|
| 47 | + else { |
|
| 48 | + $this->assignCSRFToken(); |
|
| 49 | + $this->showCustomCloseForm($database, $request); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param $database |
|
| 55 | + * |
|
| 56 | + * @return Request |
|
| 57 | + * @throws ApplicationLogicException |
|
| 58 | + */ |
|
| 59 | + protected function getRequest(PdoDatabase $database) |
|
| 60 | + { |
|
| 61 | + $requestId = WebRequest::getInt('request'); |
|
| 62 | + if ($requestId === null) { |
|
| 63 | + throw new ApplicationLogicException('Request ID not found'); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** @var Request $request */ |
|
| 67 | + $request = Request::getById($requestId, $database); |
|
| 68 | + |
|
| 69 | + if ($request === false) { |
|
| 70 | + throw new ApplicationLogicException('Request not found'); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $request; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param PdoDatabase $database |
|
| 78 | + * |
|
| 79 | + * @return EmailTemplate|null |
|
| 80 | + */ |
|
| 81 | + protected function getTemplate(PdoDatabase $database) |
|
| 82 | + { |
|
| 83 | + $templateId = WebRequest::getInt('template'); |
|
| 84 | + if ($templateId === null) { |
|
| 85 | + return null; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** @var EmailTemplate $template */ |
|
| 89 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 90 | + if ($template === false || !$template->getActive()) { |
|
| 91 | + return null; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + return $template; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param $database |
|
| 99 | + * @param $request |
|
| 100 | + * |
|
| 101 | + * @throws Exception |
|
| 102 | + */ |
|
| 103 | + protected function showCustomCloseForm(PdoDatabase $database, Request $request) |
|
| 104 | + { |
|
| 105 | + $currentUser = User::getCurrent($database); |
|
| 106 | + $config = $this->getSiteConfiguration(); |
|
| 107 | + |
|
| 108 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 109 | + if (!$allowedPrivateData) { |
|
| 110 | + // we probably shouldn't be showing the user this form if they're not allowed to access private data... |
|
| 111 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $template = $this->getTemplate($database); |
|
| 115 | + |
|
| 116 | + // Preload data |
|
| 117 | + $this->assign('defaultAction', ''); |
|
| 118 | + $this->assign('preloadText', ''); |
|
| 119 | + $this->assign('preloadTitle', ''); |
|
| 120 | + |
|
| 121 | + if ($template !== null) { |
|
| 122 | + $this->assign('defaultAction', $template->getDefaultAction()); |
|
| 123 | + $this->assign('preloadText', $template->getText()); |
|
| 124 | + $this->assign('preloadTitle', $template->getName()); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Static data |
|
| 128 | + $this->assign('requeststates', $config->getRequestStates()); |
|
| 129 | + |
|
| 130 | + // request data |
|
| 131 | + $this->assign('requestId', $request->getIp()); |
|
| 132 | + $this->assign('updateVersion', $request->getUpdateVersion()); |
|
| 133 | + $this->setupBasicData($request, $config); |
|
| 134 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 135 | + $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 136 | + |
|
| 137 | + // IP location |
|
| 138 | + $trustedIp = $this->getXffTrustProvider()->getTrustedClientIp($request->getIp(), $request->getForwardedIp()); |
|
| 139 | + $this->assign('iplocation', $this->getLocationProvider()->getIpLocation($trustedIp)); |
|
| 140 | + |
|
| 141 | + // Confirmations |
|
| 142 | + $this->assign('confirmEmailAlreadySent', $this->checkEmailAlreadySent($request)); |
|
| 143 | + |
|
| 144 | + $this->assign('canSkipCcMailingList', $this->barrierTest('skipCcMailingList', $currentUser)); |
|
| 145 | + |
|
| 146 | + $this->assign('allowWelcomeSkip', false); |
|
| 147 | + $this->assign('forceWelcomeSkip', false); |
|
| 148 | + |
|
| 149 | + $oauth = new OAuthUserHelper($currentUser, $this->getDatabase(), $this->getOAuthProtocolHelper(), $config); |
|
| 150 | + |
|
| 151 | + if ($currentUser->getWelcomeTemplate() != 0) { |
|
| 152 | + $this->assign('allowWelcomeSkip', true); |
|
| 153 | + |
|
| 154 | + if (!$oauth->canWelcome()) { |
|
| 155 | + $this->assign('forceWelcomeSkip', true); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + // template |
|
| 161 | + $this->setTemplate('custom-close.tpl'); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @param User $currentUser |
|
| 166 | + * @param Request $request |
|
| 167 | + * @param PdoDatabase $database |
|
| 168 | + * |
|
| 169 | + * @throws ApplicationLogicException |
|
| 170 | + */ |
|
| 171 | + protected function doCustomClose(User $currentUser, Request $request, PdoDatabase $database) |
|
| 172 | + { |
|
| 173 | + $messageBody = WebRequest::postString('msgbody'); |
|
| 174 | + if ($messageBody === null || trim($messageBody) === '') { |
|
| 175 | + throw new ApplicationLogicException('Message body cannot be blank'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $ccMailingList = true; |
|
| 179 | + if ($this->barrierTest('skipCcMailingList', $currentUser)) { |
|
| 180 | + $ccMailingList = WebRequest::postBoolean('ccMailingList'); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + if ($request->getStatus() === 'Closed') { |
|
| 184 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + if (!(WebRequest::postBoolean('confirmEmailAlreadySent')) |
|
| 188 | + ) { |
|
| 189 | + throw new ApplicationLogicException('Not all confirmations checked'); |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $action = WebRequest::postString('action'); |
|
| 193 | + $availableRequestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 194 | + |
|
| 195 | + if ($action === EmailTemplate::CREATED || $action === EmailTemplate::NOT_CREATED) { |
|
| 196 | + // Close request |
|
| 197 | + $this->closeRequest($request, $database, $action, $messageBody); |
|
| 198 | + |
|
| 199 | + $this->processWelcome($action); |
|
| 200 | + |
|
| 201 | + // Send the mail after the save, since save can be rolled back |
|
| 202 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 203 | + } |
|
| 204 | + else { |
|
| 205 | + if (array_key_exists($action, $availableRequestStates)) { |
|
| 206 | + // Defer to other state |
|
| 207 | + $this->deferRequest($request, $database, $action, $availableRequestStates, $messageBody); |
|
| 208 | + |
|
| 209 | + // Send the mail after the save, since save can be rolled back |
|
| 210 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 211 | + } |
|
| 212 | + else { |
|
| 213 | + $request->setReserved(null); |
|
| 214 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 215 | + $request->save(); |
|
| 216 | + |
|
| 217 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 218 | + // and be rolled back. |
|
| 219 | + |
|
| 220 | + // Send mail |
|
| 221 | + $this->sendMail($request, $messageBody, $currentUser, $ccMailingList); |
|
| 222 | + |
|
| 223 | + Logger::sentMail($database, $request, $messageBody); |
|
| 224 | + Logger::unreserve($database, $request); |
|
| 225 | + |
|
| 226 | + $this->getNotificationHelper()->sentMail($request); |
|
| 227 | + SessionAlert::success("Sent mail to Request {$request->getId()}"); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * @param Request $request |
|
| 234 | + * @param PdoDatabase $database |
|
| 235 | + * @param string $action |
|
| 236 | + * @param string $messageBody |
|
| 237 | + * |
|
| 238 | + * @throws Exception |
|
| 239 | + * @throws OptimisticLockFailedException |
|
| 240 | + */ |
|
| 241 | + protected function closeRequest(Request $request, PdoDatabase $database, $action, $messageBody) |
|
| 242 | + { |
|
| 243 | + $request->setStatus('Closed'); |
|
| 244 | + $request->setReserved(null); |
|
| 245 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 246 | + $request->save(); |
|
| 247 | + |
|
| 248 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
| 249 | + // be rolled back. |
|
| 250 | + |
|
| 251 | + if ($action == EmailTemplate::CREATED) { |
|
| 252 | + $logCloseType = 'custom-y'; |
|
| 253 | + $notificationCloseType = "Custom, Created"; |
|
| 254 | + } |
|
| 255 | + else { |
|
| 256 | + $logCloseType = 'custom-n'; |
|
| 257 | + $notificationCloseType = "Custom, Not Created"; |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + Logger::closeRequest($database, $request, $logCloseType, $messageBody); |
|
| 261 | + $this->getNotificationHelper()->requestClosed($request, $notificationCloseType); |
|
| 262 | + |
|
| 263 | + $requestName = htmlentities($request->getName(), ENT_COMPAT, 'UTF-8'); |
|
| 264 | + SessionAlert::success("Request {$request->getId()} ({$requestName}) closed as {$notificationCloseType}."); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @param Request $request |
|
| 269 | + * @param PdoDatabase $database |
|
| 270 | + * @param string $action |
|
| 271 | + * @param $availableRequestStates |
|
| 272 | + * @param string $messageBody |
|
| 273 | + * |
|
| 274 | + * @throws Exception |
|
| 275 | + * @throws OptimisticLockFailedException |
|
| 276 | + */ |
|
| 277 | + protected function deferRequest( |
|
| 278 | + Request $request, |
|
| 279 | + PdoDatabase $database, |
|
| 280 | + $action, |
|
| 281 | + $availableRequestStates, |
|
| 282 | + $messageBody |
|
| 283 | + ) { |
|
| 284 | + $request->setStatus($action); |
|
| 285 | + $request->setReserved(null); |
|
| 286 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 287 | + $request->save(); |
|
| 288 | + |
|
| 289 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE |
|
| 290 | + // and be rolled back. |
|
| 291 | + |
|
| 292 | + $deferToLog = $availableRequestStates[$action]['defertolog']; |
|
| 293 | + Logger::sentMail($database, $request, $messageBody); |
|
| 294 | + Logger::deferRequest($database, $request, $deferToLog); |
|
| 295 | + |
|
| 296 | + $this->getNotificationHelper()->requestDeferredWithMail($request); |
|
| 297 | + |
|
| 298 | + $deferTo = $availableRequestStates[$action]['deferto']; |
|
| 299 | + SessionAlert::success("Request {$request->getId()} deferred to $deferTo, sending an email."); |
|
| 300 | + } |
|
| 301 | 301 | } |
@@ -33,153 +33,153 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class PageCreateRequest extends RequestActionBase |
| 35 | 35 | { |
| 36 | - /** |
|
| 37 | - * Main function for this page, when no specific actions are called. |
|
| 38 | - * @return void |
|
| 39 | - * @throws AccessDeniedException |
|
| 40 | - * @throws ApplicationLogicException |
|
| 41 | - */ |
|
| 42 | - protected function main() |
|
| 43 | - { |
|
| 44 | - $this->checkPosted(); |
|
| 45 | - |
|
| 46 | - $database = $this->getDatabase(); |
|
| 47 | - |
|
| 48 | - $request = $this->getRequest($database); |
|
| 49 | - $template = $this->getTemplate($database); |
|
| 50 | - $creationMode = $this->getCreationMode(); |
|
| 51 | - $user = User::getCurrent($database); |
|
| 52 | - |
|
| 53 | - $secMgr = $this->getSecurityManager(); |
|
| 54 | - if ($secMgr->allows('RequestCreation', User::CREATION_BOT, $user) !== SecurityManager::ALLOWED |
|
| 55 | - && $creationMode === 'bot' |
|
| 56 | - ) { |
|
| 57 | - throw new AccessDeniedException($secMgr); |
|
| 58 | - } |
|
| 59 | - elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED |
|
| 60 | - && $creationMode === 'oauth' |
|
| 61 | - ) { |
|
| 62 | - throw new AccessDeniedException($secMgr); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if ($request->getEmailSent()) { |
|
| 66 | - throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $request->setStatus(RequestStatus::JOBQUEUE); |
|
| 70 | - $request->setReserved(null); |
|
| 71 | - $request->save(); |
|
| 72 | - |
|
| 73 | - Logger::enqueuedJobQueue($database, $request); |
|
| 74 | - |
|
| 75 | - $creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database); |
|
| 76 | - |
|
| 77 | - if ($user->getWelcomeTemplate() !== null && !WebRequest::postBoolean('skipAutoWelcome')) { |
|
| 78 | - $this->enqueueWelcomeTask($request, $creationTaskId, $user, $database); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $this->getNotificationHelper()->requestCloseQueued($request, $template->getName()); |
|
| 82 | - |
|
| 83 | - SessionAlert::success("Request {$request->getId()} has been queued for autocreation"); |
|
| 84 | - |
|
| 85 | - $this->redirect(); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - protected function getCreationMode() |
|
| 89 | - { |
|
| 90 | - $creationMode = WebRequest::postString('mode'); |
|
| 91 | - if ($creationMode !== 'oauth' && $creationMode !== 'bot') { |
|
| 92 | - throw new ApplicationLogicException('Unknown creation mode'); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $creationMode; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @param PdoDatabase $database |
|
| 100 | - * |
|
| 101 | - * @return EmailTemplate |
|
| 102 | - * @throws ApplicationLogicException |
|
| 103 | - */ |
|
| 104 | - protected function getTemplate(PdoDatabase $database) |
|
| 105 | - { |
|
| 106 | - $templateId = WebRequest::postInt('template'); |
|
| 107 | - if ($templateId === null) { |
|
| 108 | - throw new ApplicationLogicException('No template specified'); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** @var EmailTemplate $template */ |
|
| 112 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 113 | - if ($template === false || !$template->getActive()) { |
|
| 114 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if ($template->getDefaultAction() !== EmailTemplate::CREATED) { |
|
| 118 | - throw new ApplicationLogicException('Specified template is not a creation template!'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return $template; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param PdoDatabase $database |
|
| 126 | - * |
|
| 127 | - * @return Request |
|
| 128 | - * @throws ApplicationLogicException |
|
| 129 | - */ |
|
| 130 | - protected function getRequest(PdoDatabase $database) |
|
| 131 | - { |
|
| 132 | - $request = parent::getRequest($database); |
|
| 133 | - |
|
| 134 | - if ($request->getStatus() == RequestStatus::CLOSED) { |
|
| 135 | - throw new ApplicationLogicException('Request is already closed'); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $request; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @param $creationMode |
|
| 143 | - * @param Request $request |
|
| 144 | - * @param EmailTemplate $template |
|
| 145 | - * @param User $user |
|
| 146 | - * |
|
| 147 | - * @param PdoDatabase $database |
|
| 148 | - * |
|
| 149 | - * @return int |
|
| 150 | - * @throws ApplicationLogicException |
|
| 151 | - */ |
|
| 152 | - protected function enqueueCreationTask( |
|
| 153 | - $creationMode, |
|
| 154 | - Request $request, |
|
| 155 | - EmailTemplate $template, |
|
| 156 | - User $user, |
|
| 157 | - PdoDatabase $database |
|
| 158 | - ) { |
|
| 159 | - $creationTaskClass = null; |
|
| 160 | - |
|
| 161 | - if ($creationMode == "oauth") { |
|
| 162 | - $creationTaskClass = UserCreationTask::class; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - if ($creationMode == "bot") { |
|
| 166 | - $creationTaskClass = BotCreationTask::class; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if ($creationTaskClass === null) { |
|
| 170 | - throw new ApplicationLogicException('Cannot determine creation mode'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - $creationTask = new JobQueue(); |
|
| 174 | - $creationTask->setTask($creationTaskClass); |
|
| 175 | - $creationTask->setRequest($request->getId()); |
|
| 176 | - $creationTask->setEmailTemplate($template->getId()); |
|
| 177 | - $creationTask->setTriggerUserId($user->getId()); |
|
| 178 | - $creationTask->setDatabase($database); |
|
| 179 | - $creationTask->save(); |
|
| 180 | - |
|
| 181 | - $creationTaskId = $creationTask->getId(); |
|
| 182 | - |
|
| 183 | - return $creationTaskId; |
|
| 184 | - } |
|
| 36 | + /** |
|
| 37 | + * Main function for this page, when no specific actions are called. |
|
| 38 | + * @return void |
|
| 39 | + * @throws AccessDeniedException |
|
| 40 | + * @throws ApplicationLogicException |
|
| 41 | + */ |
|
| 42 | + protected function main() |
|
| 43 | + { |
|
| 44 | + $this->checkPosted(); |
|
| 45 | + |
|
| 46 | + $database = $this->getDatabase(); |
|
| 47 | + |
|
| 48 | + $request = $this->getRequest($database); |
|
| 49 | + $template = $this->getTemplate($database); |
|
| 50 | + $creationMode = $this->getCreationMode(); |
|
| 51 | + $user = User::getCurrent($database); |
|
| 52 | + |
|
| 53 | + $secMgr = $this->getSecurityManager(); |
|
| 54 | + if ($secMgr->allows('RequestCreation', User::CREATION_BOT, $user) !== SecurityManager::ALLOWED |
|
| 55 | + && $creationMode === 'bot' |
|
| 56 | + ) { |
|
| 57 | + throw new AccessDeniedException($secMgr); |
|
| 58 | + } |
|
| 59 | + elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED |
|
| 60 | + && $creationMode === 'oauth' |
|
| 61 | + ) { |
|
| 62 | + throw new AccessDeniedException($secMgr); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if ($request->getEmailSent()) { |
|
| 66 | + throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $request->setStatus(RequestStatus::JOBQUEUE); |
|
| 70 | + $request->setReserved(null); |
|
| 71 | + $request->save(); |
|
| 72 | + |
|
| 73 | + Logger::enqueuedJobQueue($database, $request); |
|
| 74 | + |
|
| 75 | + $creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database); |
|
| 76 | + |
|
| 77 | + if ($user->getWelcomeTemplate() !== null && !WebRequest::postBoolean('skipAutoWelcome')) { |
|
| 78 | + $this->enqueueWelcomeTask($request, $creationTaskId, $user, $database); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $this->getNotificationHelper()->requestCloseQueued($request, $template->getName()); |
|
| 82 | + |
|
| 83 | + SessionAlert::success("Request {$request->getId()} has been queued for autocreation"); |
|
| 84 | + |
|
| 85 | + $this->redirect(); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + protected function getCreationMode() |
|
| 89 | + { |
|
| 90 | + $creationMode = WebRequest::postString('mode'); |
|
| 91 | + if ($creationMode !== 'oauth' && $creationMode !== 'bot') { |
|
| 92 | + throw new ApplicationLogicException('Unknown creation mode'); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $creationMode; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @param PdoDatabase $database |
|
| 100 | + * |
|
| 101 | + * @return EmailTemplate |
|
| 102 | + * @throws ApplicationLogicException |
|
| 103 | + */ |
|
| 104 | + protected function getTemplate(PdoDatabase $database) |
|
| 105 | + { |
|
| 106 | + $templateId = WebRequest::postInt('template'); |
|
| 107 | + if ($templateId === null) { |
|
| 108 | + throw new ApplicationLogicException('No template specified'); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** @var EmailTemplate $template */ |
|
| 112 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 113 | + if ($template === false || !$template->getActive()) { |
|
| 114 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if ($template->getDefaultAction() !== EmailTemplate::CREATED) { |
|
| 118 | + throw new ApplicationLogicException('Specified template is not a creation template!'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return $template; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param PdoDatabase $database |
|
| 126 | + * |
|
| 127 | + * @return Request |
|
| 128 | + * @throws ApplicationLogicException |
|
| 129 | + */ |
|
| 130 | + protected function getRequest(PdoDatabase $database) |
|
| 131 | + { |
|
| 132 | + $request = parent::getRequest($database); |
|
| 133 | + |
|
| 134 | + if ($request->getStatus() == RequestStatus::CLOSED) { |
|
| 135 | + throw new ApplicationLogicException('Request is already closed'); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $request; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @param $creationMode |
|
| 143 | + * @param Request $request |
|
| 144 | + * @param EmailTemplate $template |
|
| 145 | + * @param User $user |
|
| 146 | + * |
|
| 147 | + * @param PdoDatabase $database |
|
| 148 | + * |
|
| 149 | + * @return int |
|
| 150 | + * @throws ApplicationLogicException |
|
| 151 | + */ |
|
| 152 | + protected function enqueueCreationTask( |
|
| 153 | + $creationMode, |
|
| 154 | + Request $request, |
|
| 155 | + EmailTemplate $template, |
|
| 156 | + User $user, |
|
| 157 | + PdoDatabase $database |
|
| 158 | + ) { |
|
| 159 | + $creationTaskClass = null; |
|
| 160 | + |
|
| 161 | + if ($creationMode == "oauth") { |
|
| 162 | + $creationTaskClass = UserCreationTask::class; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + if ($creationMode == "bot") { |
|
| 166 | + $creationTaskClass = BotCreationTask::class; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if ($creationTaskClass === null) { |
|
| 170 | + throw new ApplicationLogicException('Cannot determine creation mode'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + $creationTask = new JobQueue(); |
|
| 174 | + $creationTask->setTask($creationTaskClass); |
|
| 175 | + $creationTask->setRequest($request->getId()); |
|
| 176 | + $creationTask->setEmailTemplate($template->getId()); |
|
| 177 | + $creationTask->setTriggerUserId($user->getId()); |
|
| 178 | + $creationTask->setDatabase($database); |
|
| 179 | + $creationTask->save(); |
|
| 180 | + |
|
| 181 | + $creationTaskId = $creationTask->getId(); |
|
| 182 | + |
|
| 183 | + return $creationTaskId; |
|
| 184 | + } |
|
| 185 | 185 | } |
@@ -20,71 +20,71 @@ |
||
| 20 | 20 | |
| 21 | 21 | class PageDeferRequest extends RequestActionBase |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Main function for this page, when no specific actions are called. |
|
| 25 | - * @throws ApplicationLogicException |
|
| 26 | - */ |
|
| 27 | - protected function main() |
|
| 28 | - { |
|
| 29 | - $this->checkPosted(); |
|
| 30 | - $database = $this->getDatabase(); |
|
| 31 | - $request = $this->getRequest($database); |
|
| 32 | - $currentUser = User::getCurrent($database); |
|
| 33 | - |
|
| 34 | - $target = WebRequest::postString('target'); |
|
| 35 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 36 | - |
|
| 37 | - if (!array_key_exists($target, $requestStates)) { |
|
| 38 | - throw new ApplicationLogicException('Defer target not valid'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - if ($request->getStatus() == $target) { |
|
| 42 | - SessionAlert::warning('This request is already in the specified queue.'); |
|
| 43 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 44 | - |
|
| 45 | - return; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - $closureDate = $request->getClosureDate(); |
|
| 49 | - $date = new DateTime(); |
|
| 50 | - $date->modify("-7 days"); |
|
| 51 | - $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 52 | - |
|
| 53 | - |
|
| 54 | - if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 55 | - if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 56 | - throw new ApplicationLogicException( |
|
| 57 | - "You are not allowed to re-open a request that has been closed for over a week."); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - if ($request->getStatus() === RequestStatus::JOBQUEUE) { |
|
| 62 | - /** @var JobQueue[] $pendingJobs */ |
|
| 63 | - $pendingJobs = JobQueueSearchHelper::get($database)->byRequest($request->getId())->statusIn([ |
|
| 64 | - JobQueue::STATUS_READY, |
|
| 65 | - JobQueue::STATUS_WAITING, |
|
| 66 | - ])->fetch(); |
|
| 67 | - |
|
| 68 | - foreach ($pendingJobs as $job) { |
|
| 69 | - $job->setStatus(JobQueue::STATUS_CANCELLED); |
|
| 70 | - $job->setError('Cancelled by request deferral'); |
|
| 71 | - $job->save(); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $request->setReserved(null); |
|
| 76 | - $request->setStatus($target); |
|
| 77 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 78 | - $request->save(); |
|
| 79 | - |
|
| 80 | - $deto = $requestStates[$target]['deferto']; |
|
| 81 | - $detolog = $requestStates[$target]['defertolog']; |
|
| 82 | - |
|
| 83 | - Logger::deferRequest($database, $request, $detolog); |
|
| 84 | - |
|
| 85 | - $this->getNotificationHelper()->requestDeferred($request); |
|
| 86 | - SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
| 87 | - |
|
| 88 | - $this->redirect(); |
|
| 89 | - } |
|
| 23 | + /** |
|
| 24 | + * Main function for this page, when no specific actions are called. |
|
| 25 | + * @throws ApplicationLogicException |
|
| 26 | + */ |
|
| 27 | + protected function main() |
|
| 28 | + { |
|
| 29 | + $this->checkPosted(); |
|
| 30 | + $database = $this->getDatabase(); |
|
| 31 | + $request = $this->getRequest($database); |
|
| 32 | + $currentUser = User::getCurrent($database); |
|
| 33 | + |
|
| 34 | + $target = WebRequest::postString('target'); |
|
| 35 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 36 | + |
|
| 37 | + if (!array_key_exists($target, $requestStates)) { |
|
| 38 | + throw new ApplicationLogicException('Defer target not valid'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + if ($request->getStatus() == $target) { |
|
| 42 | + SessionAlert::warning('This request is already in the specified queue.'); |
|
| 43 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 44 | + |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + $closureDate = $request->getClosureDate(); |
|
| 49 | + $date = new DateTime(); |
|
| 50 | + $date->modify("-7 days"); |
|
| 51 | + $oneweek = $date->format("Y-m-d H:i:s"); |
|
| 52 | + |
|
| 53 | + |
|
| 54 | + if ($request->getStatus() == "Closed" && $closureDate < $oneweek) { |
|
| 55 | + if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
| 56 | + throw new ApplicationLogicException( |
|
| 57 | + "You are not allowed to re-open a request that has been closed for over a week."); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + if ($request->getStatus() === RequestStatus::JOBQUEUE) { |
|
| 62 | + /** @var JobQueue[] $pendingJobs */ |
|
| 63 | + $pendingJobs = JobQueueSearchHelper::get($database)->byRequest($request->getId())->statusIn([ |
|
| 64 | + JobQueue::STATUS_READY, |
|
| 65 | + JobQueue::STATUS_WAITING, |
|
| 66 | + ])->fetch(); |
|
| 67 | + |
|
| 68 | + foreach ($pendingJobs as $job) { |
|
| 69 | + $job->setStatus(JobQueue::STATUS_CANCELLED); |
|
| 70 | + $job->setError('Cancelled by request deferral'); |
|
| 71 | + $job->save(); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $request->setReserved(null); |
|
| 76 | + $request->setStatus($target); |
|
| 77 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 78 | + $request->save(); |
|
| 79 | + |
|
| 80 | + $deto = $requestStates[$target]['deferto']; |
|
| 81 | + $detolog = $requestStates[$target]['defertolog']; |
|
| 82 | + |
|
| 83 | + Logger::deferRequest($database, $request, $detolog); |
|
| 84 | + |
|
| 85 | + $this->getNotificationHelper()->requestDeferred($request); |
|
| 86 | + SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
| 87 | + |
|
| 88 | + $this->redirect(); |
|
| 89 | + } |
|
| 90 | 90 | } |
@@ -25,288 +25,288 @@ |
||
| 25 | 25 | |
| 26 | 26 | class PageViewRequest extends InternalPageBase |
| 27 | 27 | { |
| 28 | - use RequestData; |
|
| 29 | - const STATUS_SYMBOL_OPEN = '☐'; |
|
| 30 | - const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 31 | - const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Main function for this page, when no specific actions are called. |
|
| 35 | - * @throws ApplicationLogicException |
|
| 36 | - */ |
|
| 37 | - protected function main() |
|
| 38 | - { |
|
| 39 | - // set up csrf protection |
|
| 40 | - $this->assignCSRFToken(); |
|
| 41 | - |
|
| 42 | - // get some useful objects |
|
| 43 | - $database = $this->getDatabase(); |
|
| 44 | - $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 45 | - $config = $this->getSiteConfiguration(); |
|
| 46 | - $currentUser = User::getCurrent($database); |
|
| 47 | - |
|
| 48 | - // Test we should be able to look at this request |
|
| 49 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 50 | - if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 51 | - // Not allowed to look at this yet. |
|
| 52 | - throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $this->setupBasicData($request, $config); |
|
| 57 | - |
|
| 58 | - $this->setupUsernameData($request); |
|
| 59 | - |
|
| 60 | - $this->setupTitle($request); |
|
| 61 | - |
|
| 62 | - $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 63 | - $this->setupGeneralData($database); |
|
| 64 | - |
|
| 65 | - $this->assign('requestDataCleared', false); |
|
| 66 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 67 | - $this->assign('requestDataCleared', true); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 71 | - |
|
| 72 | - $this->setupCreationTypes($currentUser); |
|
| 73 | - |
|
| 74 | - $this->setupLogData($request, $database); |
|
| 75 | - |
|
| 76 | - $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 77 | - |
|
| 78 | - $this->assign('showRevealLink', false); |
|
| 79 | - if ($request->getReserved() === $currentUser->getId() || |
|
| 80 | - $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 81 | - ) { |
|
| 82 | - $this->assign('showRevealLink', true); |
|
| 83 | - $this->assign('revealHash', $request->getRevealHash()); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - if ($allowedPrivateData) { |
|
| 87 | - $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 88 | - $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 89 | - |
|
| 90 | - $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 91 | - $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 92 | - |
|
| 93 | - if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 94 | - $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 95 | - $this->setupCheckUserData($request); |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - else { |
|
| 99 | - $this->setTemplate('view-request/main.tpl'); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @param Request $request |
|
| 105 | - */ |
|
| 106 | - protected function setupTitle(Request $request) |
|
| 107 | - { |
|
| 108 | - $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 109 | - if ($request->getStatus() === 'Closed') { |
|
| 110 | - if ($request->getWasCreated()) { |
|
| 111 | - $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 112 | - } |
|
| 113 | - else { |
|
| 114 | - $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Sets up data unrelated to the request, such as the email template information |
|
| 123 | - * |
|
| 124 | - * @param PdoDatabase $database |
|
| 125 | - */ |
|
| 126 | - protected function setupGeneralData(PdoDatabase $database) |
|
| 127 | - { |
|
| 128 | - $config = $this->getSiteConfiguration(); |
|
| 129 | - |
|
| 130 | - $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 131 | - |
|
| 132 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 133 | - |
|
| 134 | - $this->assign('requestStates', $config->getRequestStates()); |
|
| 135 | - |
|
| 136 | - /** @var EmailTemplate $createdTemplate */ |
|
| 137 | - $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 138 | - |
|
| 139 | - $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 140 | - $this->assign('createdId', $createdTemplate->getId()); |
|
| 141 | - $this->assign('createdName', $createdTemplate->getName()); |
|
| 142 | - |
|
| 143 | - $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 144 | - $this->assign("createReasons", $createReasons); |
|
| 145 | - $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 146 | - $this->assign("declineReasons", $declineReasons); |
|
| 147 | - |
|
| 148 | - $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 149 | - $this->assign("allCreateReasons", $allCreateReasons); |
|
| 150 | - $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 151 | - $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 152 | - $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 153 | - $this->assign("allOtherReasons", $allOtherReasons); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - private function setupLogData(Request $request, PdoDatabase $database) |
|
| 157 | - { |
|
| 158 | - $currentUser = User::getCurrent($database); |
|
| 159 | - |
|
| 160 | - $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 161 | - $requestLogs = array(); |
|
| 162 | - |
|
| 163 | - if (trim($request->getComment()) !== "") { |
|
| 164 | - $requestLogs[] = array( |
|
| 165 | - 'type' => 'comment', |
|
| 166 | - 'security' => 'user', |
|
| 167 | - 'userid' => null, |
|
| 168 | - 'user' => $request->getName(), |
|
| 169 | - 'entry' => null, |
|
| 170 | - 'time' => $request->getDate(), |
|
| 171 | - 'canedit' => false, |
|
| 172 | - 'id' => $request->getId(), |
|
| 173 | - 'comment' => $request->getComment(), |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** @var User[] $nameCache */ |
|
| 178 | - $nameCache = array(); |
|
| 179 | - |
|
| 180 | - $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 181 | - |
|
| 182 | - /** @var Log|Comment $entry */ |
|
| 183 | - foreach ($logs as $entry) { |
|
| 184 | - // both log and comment have a 'user' field |
|
| 185 | - if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 186 | - $entryUser = User::getById($entry->getUser(), $database); |
|
| 187 | - $nameCache[$entry->getUser()] = $entryUser; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if ($entry instanceof Comment) { |
|
| 191 | - $requestLogs[] = array( |
|
| 192 | - 'type' => 'comment', |
|
| 193 | - 'security' => $entry->getVisibility(), |
|
| 194 | - 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
| 195 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 196 | - 'entry' => null, |
|
| 197 | - 'time' => $entry->getTime(), |
|
| 198 | - 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 199 | - 'id' => $entry->getId(), |
|
| 200 | - 'comment' => $entry->getComment(), |
|
| 201 | - ); |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - if ($entry instanceof Log) { |
|
| 205 | - $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 206 | - $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 207 | - |
|
| 208 | - $entryComment = $entry->getComment(); |
|
| 209 | - |
|
| 210 | - if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){ |
|
| 211 | - $data = unserialize($entry->getComment()); |
|
| 212 | - /** @var JobQueue $job */ |
|
| 213 | - $job = JobQueue::getById($data['job'], $database); |
|
| 214 | - $requestLogs[] = array( |
|
| 215 | - 'type' => 'joblog', |
|
| 216 | - 'security' => 'user', |
|
| 217 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 218 | - 'user' => $entryUser->getUsername(), |
|
| 219 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 220 | - 'time' => $entry->getTimestamp(), |
|
| 221 | - 'canedit' => false, |
|
| 222 | - 'id' => $entry->getId(), |
|
| 223 | - 'jobId' => $job->getId(), |
|
| 224 | - 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 225 | - ); |
|
| 226 | - } else { |
|
| 227 | - $requestLogs[] = array( |
|
| 228 | - 'type' => 'log', |
|
| 229 | - 'security' => 'user', |
|
| 230 | - 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 231 | - 'user' => $entryUser->getUsername(), |
|
| 232 | - 'entry' => LogHelper::getLogDescription($entry), |
|
| 233 | - 'time' => $entry->getTimestamp(), |
|
| 234 | - 'canedit' => false, |
|
| 235 | - 'id' => $entry->getId(), |
|
| 236 | - 'comment' => $entryComment, |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 243 | - |
|
| 244 | - $this->assign("requestLogs", $requestLogs); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @param Request $request |
|
| 249 | - */ |
|
| 250 | - protected function setupUsernameData(Request $request) |
|
| 251 | - { |
|
| 252 | - $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 253 | - |
|
| 254 | - $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 255 | - $this->assign('requestBlacklist', $blacklistData); |
|
| 256 | - |
|
| 257 | - try { |
|
| 258 | - $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 259 | - } |
|
| 260 | - catch (Exception $ex) { |
|
| 261 | - $spoofs = $ex->getMessage(); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $this->assign("spoofs", $spoofs); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - private function setupCreationTypes(User $user) |
|
| 268 | - { |
|
| 269 | - $this->assign('allowWelcomeSkip', false); |
|
| 270 | - $this->assign('forceWelcomeSkip', false); |
|
| 271 | - |
|
| 272 | - $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 273 | - |
|
| 274 | - if ($user->getWelcomeTemplate() != 0) { |
|
| 275 | - $this->assign('allowWelcomeSkip', true); |
|
| 276 | - |
|
| 277 | - if (!$oauth->canWelcome()) { |
|
| 278 | - $this->assign('forceWelcomeSkip', true); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // test credentials |
|
| 283 | - $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 284 | - $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 285 | - $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'); |
|
| 286 | - |
|
| 287 | - $this->assign('canManualCreate', $canManualCreate); |
|
| 288 | - $this->assign('canOauthCreate', $canOauthCreate); |
|
| 289 | - $this->assign('canBotCreate', $canBotCreate); |
|
| 290 | - |
|
| 291 | - // show/hide the type radio buttons |
|
| 292 | - $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 293 | - |
|
| 294 | - if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) { |
|
| 295 | - // user is not allowed to use their default. Force a choice. |
|
| 296 | - $creationHasChoice = true; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - $this->assign('creationHasChoice', $creationHasChoice); |
|
| 300 | - |
|
| 301 | - // determine problems in creation types |
|
| 302 | - $this->assign('botProblem', false); |
|
| 303 | - if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 304 | - $this->assign('botProblem', true); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $this->assign('oauthProblem', false); |
|
| 308 | - if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 309 | - $this->assign('oauthProblem', true); |
|
| 310 | - } |
|
| 311 | - } |
|
| 28 | + use RequestData; |
|
| 29 | + const STATUS_SYMBOL_OPEN = '☐'; |
|
| 30 | + const STATUS_SYMBOL_ACCEPTED = '☑'; |
|
| 31 | + const STATUS_SYMBOL_REJECTED = '☒'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Main function for this page, when no specific actions are called. |
|
| 35 | + * @throws ApplicationLogicException |
|
| 36 | + */ |
|
| 37 | + protected function main() |
|
| 38 | + { |
|
| 39 | + // set up csrf protection |
|
| 40 | + $this->assignCSRFToken(); |
|
| 41 | + |
|
| 42 | + // get some useful objects |
|
| 43 | + $database = $this->getDatabase(); |
|
| 44 | + $request = $this->getRequest($database, WebRequest::getInt('id')); |
|
| 45 | + $config = $this->getSiteConfiguration(); |
|
| 46 | + $currentUser = User::getCurrent($database); |
|
| 47 | + |
|
| 48 | + // Test we should be able to look at this request |
|
| 49 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 50 | + if ($request->getEmailConfirm() !== 'Confirmed') { |
|
| 51 | + // Not allowed to look at this yet. |
|
| 52 | + throw new ApplicationLogicException('The email address has not yet been confirmed for this request.'); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $this->setupBasicData($request, $config); |
|
| 57 | + |
|
| 58 | + $this->setupUsernameData($request); |
|
| 59 | + |
|
| 60 | + $this->setupTitle($request); |
|
| 61 | + |
|
| 62 | + $this->setupReservationDetails($request->getReserved(), $database, $currentUser); |
|
| 63 | + $this->setupGeneralData($database); |
|
| 64 | + |
|
| 65 | + $this->assign('requestDataCleared', false); |
|
| 66 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
| 67 | + $this->assign('requestDataCleared', true); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser); |
|
| 71 | + |
|
| 72 | + $this->setupCreationTypes($currentUser); |
|
| 73 | + |
|
| 74 | + $this->setupLogData($request, $database); |
|
| 75 | + |
|
| 76 | + $this->addJs("/api.php?action=templates&targetVariable=templateconfirms"); |
|
| 77 | + |
|
| 78 | + $this->assign('showRevealLink', false); |
|
| 79 | + if ($request->getReserved() === $currentUser->getId() || |
|
| 80 | + $this->barrierTest('alwaysSeeHash', $currentUser, 'RequestData') |
|
| 81 | + ) { |
|
| 82 | + $this->assign('showRevealLink', true); |
|
| 83 | + $this->assign('revealHash', $request->getRevealHash()); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + if ($allowedPrivateData) { |
|
| 87 | + $this->setTemplate('view-request/main-with-data.tpl'); |
|
| 88 | + $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database); |
|
| 89 | + |
|
| 90 | + $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class)); |
|
| 91 | + $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')); |
|
| 92 | + |
|
| 93 | + if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) { |
|
| 94 | + $this->setTemplate('view-request/main-with-checkuser-data.tpl'); |
|
| 95 | + $this->setupCheckUserData($request); |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + else { |
|
| 99 | + $this->setTemplate('view-request/main.tpl'); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @param Request $request |
|
| 105 | + */ |
|
| 106 | + protected function setupTitle(Request $request) |
|
| 107 | + { |
|
| 108 | + $statusSymbol = self::STATUS_SYMBOL_OPEN; |
|
| 109 | + if ($request->getStatus() === 'Closed') { |
|
| 110 | + if ($request->getWasCreated()) { |
|
| 111 | + $statusSymbol = self::STATUS_SYMBOL_ACCEPTED; |
|
| 112 | + } |
|
| 113 | + else { |
|
| 114 | + $statusSymbol = self::STATUS_SYMBOL_REJECTED; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $this->setHtmlTitle($statusSymbol . ' #' . $request->getId()); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Sets up data unrelated to the request, such as the email template information |
|
| 123 | + * |
|
| 124 | + * @param PdoDatabase $database |
|
| 125 | + */ |
|
| 126 | + protected function setupGeneralData(PdoDatabase $database) |
|
| 127 | + { |
|
| 128 | + $config = $this->getSiteConfiguration(); |
|
| 129 | + |
|
| 130 | + $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #'); |
|
| 131 | + |
|
| 132 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 133 | + |
|
| 134 | + $this->assign('requestStates', $config->getRequestStates()); |
|
| 135 | + |
|
| 136 | + /** @var EmailTemplate $createdTemplate */ |
|
| 137 | + $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database); |
|
| 138 | + |
|
| 139 | + $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != ''); |
|
| 140 | + $this->assign('createdId', $createdTemplate->getId()); |
|
| 141 | + $this->assign('createdName', $createdTemplate->getName()); |
|
| 142 | + |
|
| 143 | + $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 144 | + $this->assign("createReasons", $createReasons); |
|
| 145 | + $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 146 | + $this->assign("declineReasons", $declineReasons); |
|
| 147 | + |
|
| 148 | + $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database); |
|
| 149 | + $this->assign("allCreateReasons", $allCreateReasons); |
|
| 150 | + $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database); |
|
| 151 | + $this->assign("allDeclineReasons", $allDeclineReasons); |
|
| 152 | + $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database); |
|
| 153 | + $this->assign("allOtherReasons", $allOtherReasons); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + private function setupLogData(Request $request, PdoDatabase $database) |
|
| 157 | + { |
|
| 158 | + $currentUser = User::getCurrent($database); |
|
| 159 | + |
|
| 160 | + $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager()); |
|
| 161 | + $requestLogs = array(); |
|
| 162 | + |
|
| 163 | + if (trim($request->getComment()) !== "") { |
|
| 164 | + $requestLogs[] = array( |
|
| 165 | + 'type' => 'comment', |
|
| 166 | + 'security' => 'user', |
|
| 167 | + 'userid' => null, |
|
| 168 | + 'user' => $request->getName(), |
|
| 169 | + 'entry' => null, |
|
| 170 | + 'time' => $request->getDate(), |
|
| 171 | + 'canedit' => false, |
|
| 172 | + 'id' => $request->getId(), |
|
| 173 | + 'comment' => $request->getComment(), |
|
| 174 | + ); |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** @var User[] $nameCache */ |
|
| 178 | + $nameCache = array(); |
|
| 179 | + |
|
| 180 | + $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class); |
|
| 181 | + |
|
| 182 | + /** @var Log|Comment $entry */ |
|
| 183 | + foreach ($logs as $entry) { |
|
| 184 | + // both log and comment have a 'user' field |
|
| 185 | + if (!array_key_exists($entry->getUser(), $nameCache)) { |
|
| 186 | + $entryUser = User::getById($entry->getUser(), $database); |
|
| 187 | + $nameCache[$entry->getUser()] = $entryUser; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if ($entry instanceof Comment) { |
|
| 191 | + $requestLogs[] = array( |
|
| 192 | + 'type' => 'comment', |
|
| 193 | + 'security' => $entry->getVisibility(), |
|
| 194 | + 'user' => $nameCache[$entry->getUser()]->getUsername(), |
|
| 195 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 196 | + 'entry' => null, |
|
| 197 | + 'time' => $entry->getTime(), |
|
| 198 | + 'canedit' => ($editableComments || $entry->getUser() == $currentUser->getId()), |
|
| 199 | + 'id' => $entry->getId(), |
|
| 200 | + 'comment' => $entry->getComment(), |
|
| 201 | + ); |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + if ($entry instanceof Log) { |
|
| 205 | + $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0; |
|
| 206 | + $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()]; |
|
| 207 | + |
|
| 208 | + $entryComment = $entry->getComment(); |
|
| 209 | + |
|
| 210 | + if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){ |
|
| 211 | + $data = unserialize($entry->getComment()); |
|
| 212 | + /** @var JobQueue $job */ |
|
| 213 | + $job = JobQueue::getById($data['job'], $database); |
|
| 214 | + $requestLogs[] = array( |
|
| 215 | + 'type' => 'joblog', |
|
| 216 | + 'security' => 'user', |
|
| 217 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 218 | + 'user' => $entryUser->getUsername(), |
|
| 219 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 220 | + 'time' => $entry->getTimestamp(), |
|
| 221 | + 'canedit' => false, |
|
| 222 | + 'id' => $entry->getId(), |
|
| 223 | + 'jobId' => $job->getId(), |
|
| 224 | + 'jobDesc' => JobQueue::getTaskDescriptions()[$job->getTask()], |
|
| 225 | + ); |
|
| 226 | + } else { |
|
| 227 | + $requestLogs[] = array( |
|
| 228 | + 'type' => 'log', |
|
| 229 | + 'security' => 'user', |
|
| 230 | + 'userid' => $entry->getUser() == -1 ? null : $entry->getUser(), |
|
| 231 | + 'user' => $entryUser->getUsername(), |
|
| 232 | + 'entry' => LogHelper::getLogDescription($entry), |
|
| 233 | + 'time' => $entry->getTimestamp(), |
|
| 234 | + 'canedit' => false, |
|
| 235 | + 'id' => $entry->getId(), |
|
| 236 | + 'comment' => $entryComment, |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + $this->addJs("/api.php?action=users&targetVariable=typeaheaddata"); |
|
| 243 | + |
|
| 244 | + $this->assign("requestLogs", $requestLogs); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @param Request $request |
|
| 249 | + */ |
|
| 250 | + protected function setupUsernameData(Request $request) |
|
| 251 | + { |
|
| 252 | + $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName()); |
|
| 253 | + |
|
| 254 | + $this->assign('requestIsBlacklisted', $blacklistData !== false); |
|
| 255 | + $this->assign('requestBlacklist', $blacklistData); |
|
| 256 | + |
|
| 257 | + try { |
|
| 258 | + $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName()); |
|
| 259 | + } |
|
| 260 | + catch (Exception $ex) { |
|
| 261 | + $spoofs = $ex->getMessage(); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $this->assign("spoofs", $spoofs); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + private function setupCreationTypes(User $user) |
|
| 268 | + { |
|
| 269 | + $this->assign('allowWelcomeSkip', false); |
|
| 270 | + $this->assign('forceWelcomeSkip', false); |
|
| 271 | + |
|
| 272 | + $oauth = new OAuthUserHelper($user, $this->getDatabase(), $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 273 | + |
|
| 274 | + if ($user->getWelcomeTemplate() != 0) { |
|
| 275 | + $this->assign('allowWelcomeSkip', true); |
|
| 276 | + |
|
| 277 | + if (!$oauth->canWelcome()) { |
|
| 278 | + $this->assign('forceWelcomeSkip', true); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // test credentials |
|
| 283 | + $canManualCreate = $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'); |
|
| 284 | + $canOauthCreate = $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'); |
|
| 285 | + $canBotCreate = $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'); |
|
| 286 | + |
|
| 287 | + $this->assign('canManualCreate', $canManualCreate); |
|
| 288 | + $this->assign('canOauthCreate', $canOauthCreate); |
|
| 289 | + $this->assign('canBotCreate', $canBotCreate); |
|
| 290 | + |
|
| 291 | + // show/hide the type radio buttons |
|
| 292 | + $creationHasChoice = count(array_filter([$canManualCreate, $canOauthCreate, $canBotCreate])) > 1; |
|
| 293 | + |
|
| 294 | + if (!$this->barrierTest($user->getCreationMode(), $user, 'RequestCreation')) { |
|
| 295 | + // user is not allowed to use their default. Force a choice. |
|
| 296 | + $creationHasChoice = true; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + $this->assign('creationHasChoice', $creationHasChoice); |
|
| 300 | + |
|
| 301 | + // determine problems in creation types |
|
| 302 | + $this->assign('botProblem', false); |
|
| 303 | + if ($canBotCreate && $this->getSiteConfiguration()->getCreationBotPassword() === null) { |
|
| 304 | + $this->assign('botProblem', true); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $this->assign('oauthProblem', false); |
|
| 308 | + if ($canOauthCreate && !$oauth->canCreateAccount()) { |
|
| 309 | + $this->assign('oauthProblem', true); |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | 312 | } |
@@ -19,223 +19,223 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageWelcomeTemplateManagement extends InternalPageBase |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Main function for this page, when no specific actions are called. |
|
| 24 | - * @return void |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - $templateList = WelcomeTemplate::getAll($this->getDatabase()); |
|
| 29 | - |
|
| 30 | - $this->assignCSRFToken(); |
|
| 31 | - |
|
| 32 | - $user = User::getCurrent($this->getDatabase()); |
|
| 33 | - $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 34 | - $this->assign('canAdd', $this->barrierTest('add', $user)); |
|
| 22 | + /** |
|
| 23 | + * Main function for this page, when no specific actions are called. |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + $templateList = WelcomeTemplate::getAll($this->getDatabase()); |
|
| 29 | + |
|
| 30 | + $this->assignCSRFToken(); |
|
| 31 | + |
|
| 32 | + $user = User::getCurrent($this->getDatabase()); |
|
| 33 | + $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 34 | + $this->assign('canAdd', $this->barrierTest('add', $user)); |
|
| 35 | 35 | |
| 36 | - $this->assign('templateList', $templateList); |
|
| 37 | - $this->setTemplate('welcome-template/list.tpl'); |
|
| 38 | - } |
|
| 36 | + $this->assign('templateList', $templateList); |
|
| 37 | + $this->setTemplate('welcome-template/list.tpl'); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Handles the requests for selecting a template to use. |
|
| 42 | - * |
|
| 43 | - * @throws ApplicationLogicException |
|
| 44 | - */ |
|
| 45 | - protected function select() |
|
| 46 | - { |
|
| 47 | - // get rid of GETs |
|
| 48 | - if (!WebRequest::wasPosted()) { |
|
| 49 | - $this->redirect('welcomeTemplates'); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - $this->validateCSRFToken(); |
|
| 53 | - |
|
| 54 | - $user = User::getCurrent($this->getDatabase()); |
|
| 55 | - |
|
| 56 | - if (WebRequest::postBoolean('disable')) { |
|
| 57 | - $user->setWelcomeTemplate(null); |
|
| 58 | - $user->save(); |
|
| 59 | - |
|
| 60 | - SessionAlert::success('Disabled automatic user welcoming.'); |
|
| 61 | - $this->redirect('welcomeTemplates'); |
|
| 62 | - |
|
| 63 | - return; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $database = $this->getDatabase(); |
|
| 40 | + /** |
|
| 41 | + * Handles the requests for selecting a template to use. |
|
| 42 | + * |
|
| 43 | + * @throws ApplicationLogicException |
|
| 44 | + */ |
|
| 45 | + protected function select() |
|
| 46 | + { |
|
| 47 | + // get rid of GETs |
|
| 48 | + if (!WebRequest::wasPosted()) { |
|
| 49 | + $this->redirect('welcomeTemplates'); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + $this->validateCSRFToken(); |
|
| 53 | + |
|
| 54 | + $user = User::getCurrent($this->getDatabase()); |
|
| 55 | + |
|
| 56 | + if (WebRequest::postBoolean('disable')) { |
|
| 57 | + $user->setWelcomeTemplate(null); |
|
| 58 | + $user->save(); |
|
| 59 | + |
|
| 60 | + SessionAlert::success('Disabled automatic user welcoming.'); |
|
| 61 | + $this->redirect('welcomeTemplates'); |
|
| 62 | + |
|
| 63 | + return; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $database = $this->getDatabase(); |
|
| 67 | 67 | |
| 68 | - $templateId = WebRequest::postInt('template'); |
|
| 69 | - /** @var false|WelcomeTemplate $template */ |
|
| 70 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 68 | + $templateId = WebRequest::postInt('template'); |
|
| 69 | + /** @var false|WelcomeTemplate $template */ |
|
| 70 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 71 | 71 | |
| 72 | - if ($template === false || $template->isDeleted()) { |
|
| 73 | - throw new ApplicationLogicException('Unknown template'); |
|
| 74 | - } |
|
| 72 | + if ($template === false || $template->isDeleted()) { |
|
| 73 | + throw new ApplicationLogicException('Unknown template'); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - $user->setWelcomeTemplate($template->getId()); |
|
| 77 | - $user->save(); |
|
| 76 | + $user->setWelcomeTemplate($template->getId()); |
|
| 77 | + $user->save(); |
|
| 78 | 78 | |
| 79 | - SessionAlert::success("Updated selected welcome template for automatic welcoming."); |
|
| 79 | + SessionAlert::success("Updated selected welcome template for automatic welcoming."); |
|
| 80 | 80 | |
| 81 | - $this->redirect('welcomeTemplates'); |
|
| 82 | - } |
|
| 81 | + $this->redirect('welcomeTemplates'); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Handles the requests for viewing a template. |
|
| 86 | - * |
|
| 87 | - * @throws ApplicationLogicException |
|
| 88 | - */ |
|
| 89 | - protected function view() |
|
| 90 | - { |
|
| 91 | - $database = $this->getDatabase(); |
|
| 84 | + /** |
|
| 85 | + * Handles the requests for viewing a template. |
|
| 86 | + * |
|
| 87 | + * @throws ApplicationLogicException |
|
| 88 | + */ |
|
| 89 | + protected function view() |
|
| 90 | + { |
|
| 91 | + $database = $this->getDatabase(); |
|
| 92 | 92 | |
| 93 | - $templateId = WebRequest::getInt('template'); |
|
| 93 | + $templateId = WebRequest::getInt('template'); |
|
| 94 | 94 | |
| 95 | - /** @var WelcomeTemplate $template */ |
|
| 96 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 95 | + /** @var WelcomeTemplate $template */ |
|
| 96 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 97 | 97 | |
| 98 | - if ($template === false) { |
|
| 99 | - throw new ApplicationLogicException('Cannot find requested template'); |
|
| 100 | - } |
|
| 98 | + if ($template === false) { |
|
| 99 | + throw new ApplicationLogicException('Cannot find requested template'); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode()); |
|
| 102 | + $templateHtml = $this->getWikiTextHelper()->getHtmlForWikiText($template->getBotCode()); |
|
| 103 | 103 | |
| 104 | - $this->assign('templateHtml', $templateHtml); |
|
| 105 | - $this->assign('template', $template); |
|
| 106 | - $this->setTemplate('welcome-template/view.tpl'); |
|
| 107 | - } |
|
| 104 | + $this->assign('templateHtml', $templateHtml); |
|
| 105 | + $this->assign('template', $template); |
|
| 106 | + $this->setTemplate('welcome-template/view.tpl'); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Handler for the add action to create a new welcome template |
|
| 111 | - * |
|
| 112 | - * @throws Exception |
|
| 113 | - */ |
|
| 114 | - protected function add() |
|
| 115 | - { |
|
| 116 | - if (WebRequest::wasPosted()) { |
|
| 117 | - $this->validateCSRFToken(); |
|
| 118 | - $database = $this->getDatabase(); |
|
| 109 | + /** |
|
| 110 | + * Handler for the add action to create a new welcome template |
|
| 111 | + * |
|
| 112 | + * @throws Exception |
|
| 113 | + */ |
|
| 114 | + protected function add() |
|
| 115 | + { |
|
| 116 | + if (WebRequest::wasPosted()) { |
|
| 117 | + $this->validateCSRFToken(); |
|
| 118 | + $database = $this->getDatabase(); |
|
| 119 | 119 | |
| 120 | - $userCode = WebRequest::postString('usercode'); |
|
| 121 | - $botCode = WebRequest::postString('botcode'); |
|
| 120 | + $userCode = WebRequest::postString('usercode'); |
|
| 121 | + $botCode = WebRequest::postString('botcode'); |
|
| 122 | 122 | |
| 123 | - $this->validate($userCode, $botCode); |
|
| 123 | + $this->validate($userCode, $botCode); |
|
| 124 | 124 | |
| 125 | - $template = new WelcomeTemplate(); |
|
| 126 | - $template->setDatabase($database); |
|
| 127 | - $template->setUserCode($userCode); |
|
| 128 | - $template->setBotCode($botCode); |
|
| 129 | - $template->save(); |
|
| 125 | + $template = new WelcomeTemplate(); |
|
| 126 | + $template->setDatabase($database); |
|
| 127 | + $template->setUserCode($userCode); |
|
| 128 | + $template->setBotCode($botCode); |
|
| 129 | + $template->save(); |
|
| 130 | 130 | |
| 131 | - Logger::welcomeTemplateCreated($database, $template); |
|
| 131 | + Logger::welcomeTemplateCreated($database, $template); |
|
| 132 | 132 | |
| 133 | - $this->getNotificationHelper()->welcomeTemplateCreated($template); |
|
| 133 | + $this->getNotificationHelper()->welcomeTemplateCreated($template); |
|
| 134 | 134 | |
| 135 | - SessionAlert::success("Template successfully created."); |
|
| 135 | + SessionAlert::success("Template successfully created."); |
|
| 136 | 136 | |
| 137 | - $this->redirect('welcomeTemplates'); |
|
| 138 | - } |
|
| 139 | - else { |
|
| 140 | - $this->assignCSRFToken(); |
|
| 141 | - $this->setTemplate("welcome-template/add.tpl"); |
|
| 142 | - } |
|
| 143 | - } |
|
| 137 | + $this->redirect('welcomeTemplates'); |
|
| 138 | + } |
|
| 139 | + else { |
|
| 140 | + $this->assignCSRFToken(); |
|
| 141 | + $this->setTemplate("welcome-template/add.tpl"); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Handler for editing templates |
|
| 147 | - */ |
|
| 148 | - protected function edit() |
|
| 149 | - { |
|
| 150 | - $database = $this->getDatabase(); |
|
| 145 | + /** |
|
| 146 | + * Handler for editing templates |
|
| 147 | + */ |
|
| 148 | + protected function edit() |
|
| 149 | + { |
|
| 150 | + $database = $this->getDatabase(); |
|
| 151 | 151 | |
| 152 | - $templateId = WebRequest::getInt('template'); |
|
| 152 | + $templateId = WebRequest::getInt('template'); |
|
| 153 | 153 | |
| 154 | - /** @var WelcomeTemplate $template */ |
|
| 155 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 154 | + /** @var WelcomeTemplate $template */ |
|
| 155 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 156 | 156 | |
| 157 | - if ($template === false) { |
|
| 158 | - throw new ApplicationLogicException('Cannot find requested template'); |
|
| 159 | - } |
|
| 157 | + if ($template === false) { |
|
| 158 | + throw new ApplicationLogicException('Cannot find requested template'); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - if ($template->isDeleted()) { |
|
| 162 | - throw new ApplicationLogicException('The specified template has been deleted'); |
|
| 163 | - } |
|
| 161 | + if ($template->isDeleted()) { |
|
| 162 | + throw new ApplicationLogicException('The specified template has been deleted'); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - if (WebRequest::wasPosted()) { |
|
| 166 | - $this->validateCSRFToken(); |
|
| 165 | + if (WebRequest::wasPosted()) { |
|
| 166 | + $this->validateCSRFToken(); |
|
| 167 | 167 | |
| 168 | - $userCode = WebRequest::postString('usercode'); |
|
| 169 | - $botCode = WebRequest::postString('botcode'); |
|
| 168 | + $userCode = WebRequest::postString('usercode'); |
|
| 169 | + $botCode = WebRequest::postString('botcode'); |
|
| 170 | 170 | |
| 171 | - $this->validate($userCode, $botCode); |
|
| 171 | + $this->validate($userCode, $botCode); |
|
| 172 | 172 | |
| 173 | - $template->setUserCode($userCode); |
|
| 174 | - $template->setBotCode($botCode); |
|
| 175 | - $template->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 176 | - $template->save(); |
|
| 173 | + $template->setUserCode($userCode); |
|
| 174 | + $template->setBotCode($botCode); |
|
| 175 | + $template->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 176 | + $template->save(); |
|
| 177 | 177 | |
| 178 | - Logger::welcomeTemplateEdited($database, $template); |
|
| 178 | + Logger::welcomeTemplateEdited($database, $template); |
|
| 179 | 179 | |
| 180 | - SessionAlert::success("Template updated."); |
|
| 180 | + SessionAlert::success("Template updated."); |
|
| 181 | 181 | |
| 182 | - $this->getNotificationHelper()->welcomeTemplateEdited($template); |
|
| 182 | + $this->getNotificationHelper()->welcomeTemplateEdited($template); |
|
| 183 | 183 | |
| 184 | - $this->redirect('welcomeTemplates'); |
|
| 185 | - } |
|
| 186 | - else { |
|
| 187 | - $this->assignCSRFToken(); |
|
| 188 | - $this->assign('template', $template); |
|
| 189 | - $this->setTemplate('welcome-template/edit.tpl'); |
|
| 190 | - } |
|
| 191 | - } |
|
| 184 | + $this->redirect('welcomeTemplates'); |
|
| 185 | + } |
|
| 186 | + else { |
|
| 187 | + $this->assignCSRFToken(); |
|
| 188 | + $this->assign('template', $template); |
|
| 189 | + $this->setTemplate('welcome-template/edit.tpl'); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - protected function delete() |
|
| 194 | - { |
|
| 195 | - $this->redirect('welcomeTemplates'); |
|
| 193 | + protected function delete() |
|
| 194 | + { |
|
| 195 | + $this->redirect('welcomeTemplates'); |
|
| 196 | 196 | |
| 197 | - if (!WebRequest::wasPosted()) { |
|
| 198 | - return; |
|
| 199 | - } |
|
| 197 | + if (!WebRequest::wasPosted()) { |
|
| 198 | + return; |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - $this->validateCSRFToken(); |
|
| 201 | + $this->validateCSRFToken(); |
|
| 202 | 202 | |
| 203 | - $database = $this->getDatabase(); |
|
| 203 | + $database = $this->getDatabase(); |
|
| 204 | 204 | |
| 205 | - $templateId = WebRequest::postInt('template'); |
|
| 206 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 205 | + $templateId = WebRequest::postInt('template'); |
|
| 206 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 207 | 207 | |
| 208 | - /** @var WelcomeTemplate $template */ |
|
| 209 | - $template = WelcomeTemplate::getById($templateId, $database); |
|
| 208 | + /** @var WelcomeTemplate $template */ |
|
| 209 | + $template = WelcomeTemplate::getById($templateId, $database); |
|
| 210 | 210 | |
| 211 | - if ($template === false || $template->isDeleted()) { |
|
| 212 | - throw new ApplicationLogicException('Cannot find requested template'); |
|
| 213 | - } |
|
| 211 | + if ($template === false || $template->isDeleted()) { |
|
| 212 | + throw new ApplicationLogicException('Cannot find requested template'); |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - // set the update version to the version sent by the client (optimisticly lock from initial page load) |
|
| 216 | - $template->setUpdateVersion($updateVersion); |
|
| 215 | + // set the update version to the version sent by the client (optimisticly lock from initial page load) |
|
| 216 | + $template->setUpdateVersion($updateVersion); |
|
| 217 | 217 | |
| 218 | - $database |
|
| 219 | - ->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;") |
|
| 220 | - ->execute(array(":id" => $templateId)); |
|
| 218 | + $database |
|
| 219 | + ->prepare("UPDATE user SET welcome_template = NULL WHERE welcome_template = :id;") |
|
| 220 | + ->execute(array(":id" => $templateId)); |
|
| 221 | 221 | |
| 222 | - Logger::welcomeTemplateDeleted($database, $template); |
|
| 222 | + Logger::welcomeTemplateDeleted($database, $template); |
|
| 223 | 223 | |
| 224 | - $template->delete(); |
|
| 224 | + $template->delete(); |
|
| 225 | 225 | |
| 226 | - SessionAlert::success( |
|
| 227 | - "Template deleted. Any users who were using this template have had automatic welcoming disabled."); |
|
| 228 | - $this->getNotificationHelper()->welcomeTemplateDeleted($templateId); |
|
| 229 | - } |
|
| 226 | + SessionAlert::success( |
|
| 227 | + "Template deleted. Any users who were using this template have had automatic welcoming disabled."); |
|
| 228 | + $this->getNotificationHelper()->welcomeTemplateDeleted($templateId); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - private function validate($userCode, $botCode) |
|
| 232 | - { |
|
| 233 | - if ($userCode === null) { |
|
| 234 | - throw new ApplicationLogicException('User code cannot be null'); |
|
| 235 | - } |
|
| 231 | + private function validate($userCode, $botCode) |
|
| 232 | + { |
|
| 233 | + if ($userCode === null) { |
|
| 234 | + throw new ApplicationLogicException('User code cannot be null'); |
|
| 235 | + } |
|
| 236 | 236 | |
| 237 | - if ($botCode === null) { |
|
| 238 | - throw new ApplicationLogicException('Bot code cannot be null'); |
|
| 239 | - } |
|
| 240 | - } |
|
| 237 | + if ($botCode === null) { |
|
| 238 | + throw new ApplicationLogicException('Bot code cannot be null'); |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | } |
@@ -12,21 +12,21 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Page404 extends InternalPageBase |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Main function for this page, when no actions are called. |
|
| 17 | - */ |
|
| 18 | - protected function main() |
|
| 19 | - { |
|
| 20 | - if (!headers_sent()) { |
|
| 21 | - header("HTTP/1.1 404 Not Found"); |
|
| 22 | - } |
|
| 15 | + /** |
|
| 16 | + * Main function for this page, when no actions are called. |
|
| 17 | + */ |
|
| 18 | + protected function main() |
|
| 19 | + { |
|
| 20 | + if (!headers_sent()) { |
|
| 21 | + header("HTTP/1.1 404 Not Found"); |
|
| 22 | + } |
|
| 23 | 23 | |
| 24 | - $this->skipAlerts(); |
|
| 25 | - $this->setTemplate("404.tpl"); |
|
| 26 | - } |
|
| 24 | + $this->skipAlerts(); |
|
| 25 | + $this->setTemplate("404.tpl"); |
|
| 26 | + } |
|
| 27 | 27 | |
| 28 | - protected function isProtectedPage() |
|
| 29 | - { |
|
| 30 | - return false; |
|
| 31 | - } |
|
| 28 | + protected function isProtectedPage() |
|
| 29 | + { |
|
| 30 | + return false; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -24,565 +24,565 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class PageUserManagement extends InternalPageBase |
| 26 | 26 | { |
| 27 | - /** @var string */ |
|
| 28 | - private $adminMailingList = '[email protected]'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Main function for this page, when no specific actions are called. |
|
| 32 | - */ |
|
| 33 | - protected function main() |
|
| 34 | - { |
|
| 35 | - $this->setHtmlTitle('User Management'); |
|
| 36 | - |
|
| 37 | - $database = $this->getDatabase(); |
|
| 38 | - $currentUser = User::getCurrent($database); |
|
| 39 | - |
|
| 40 | - $userSearchRequest = WebRequest::getString('usersearch'); |
|
| 41 | - if ($userSearchRequest !== null) { |
|
| 42 | - $searchedUser = User::getByUsername($userSearchRequest, $database); |
|
| 43 | - if($searchedUser !== false) { |
|
| 44 | - $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]); |
|
| 45 | - return; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
| 50 | - // the template. I still don't have a particularly good way of handling this. |
|
| 51 | - OAuthUserHelper::prepareTokenCountStatement($database); |
|
| 52 | - |
|
| 53 | - if (WebRequest::getBoolean("showAll")) { |
|
| 54 | - $this->assign("showAll", true); |
|
| 55 | - |
|
| 56 | - $suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch(); |
|
| 57 | - $this->assign("suspendedUsers", $suspendedUsers); |
|
| 58 | - |
|
| 59 | - $declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch(); |
|
| 60 | - $this->assign("declinedUsers", $declinedUsers); |
|
| 61 | - |
|
| 62 | - UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
| 63 | - } |
|
| 64 | - else { |
|
| 65 | - $this->assign("showAll", false); |
|
| 66 | - $this->assign("suspendedUsers", array()); |
|
| 67 | - $this->assign("declinedUsers", array()); |
|
| 68 | - |
|
| 69 | - UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
| 73 | - $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
| 74 | - $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
| 75 | - $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
| 76 | - $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
| 77 | - $this->assign('newUsers', $newUsers); |
|
| 78 | - $this->assign('normalUsers', $normalUsers); |
|
| 79 | - $this->assign('adminUsers', $adminUsers); |
|
| 80 | - $this->assign('checkUsers', $checkUsers); |
|
| 81 | - $this->assign('toolRoots', $toolRoots); |
|
| 82 | - |
|
| 83 | - $this->assign('roles', $roleMap); |
|
| 84 | - |
|
| 85 | - $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 86 | - |
|
| 87 | - $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
| 88 | - $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
| 89 | - $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
| 90 | - $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
| 91 | - $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
| 92 | - $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
| 93 | - |
|
| 94 | - $this->setTemplate("usermanagement/main.tpl"); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - #region Access control |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Action target for editing the roles assigned to a user |
|
| 101 | - */ |
|
| 102 | - protected function editRoles() |
|
| 103 | - { |
|
| 104 | - $this->setHtmlTitle('User Management'); |
|
| 105 | - $database = $this->getDatabase(); |
|
| 106 | - $userId = WebRequest::getInt('user'); |
|
| 107 | - |
|
| 108 | - /** @var User $user */ |
|
| 109 | - $user = User::getById($userId, $database); |
|
| 110 | - |
|
| 111 | - if ($user === false) { |
|
| 112 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
| 116 | - |
|
| 117 | - // Dual-mode action |
|
| 118 | - if (WebRequest::wasPosted()) { |
|
| 119 | - $this->validateCSRFToken(); |
|
| 120 | - |
|
| 121 | - $reason = WebRequest::postString('reason'); |
|
| 122 | - if ($reason === false || trim($reason) === '') { |
|
| 123 | - throw new ApplicationLogicException('No reason specified for roles change'); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** @var UserRole[] $delete */ |
|
| 127 | - $delete = array(); |
|
| 128 | - /** @var string[] $delete */ |
|
| 129 | - $add = array(); |
|
| 130 | - |
|
| 131 | - foreach ($roleData as $name => $r) { |
|
| 132 | - if ($r['allowEdit'] !== 1) { |
|
| 133 | - // not allowed, to touch this, so ignore it |
|
| 134 | - continue; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
| 138 | - if ($newValue !== $r['active']) { |
|
| 139 | - if ($newValue === 0) { |
|
| 140 | - $delete[] = $r['object']; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - if ($newValue === 1) { |
|
| 144 | - $add[] = $name; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // Check there's something to do |
|
| 150 | - if ((count($add) + count($delete)) === 0) { |
|
| 151 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 152 | - SessionAlert::warning('No changes made to roles.'); |
|
| 153 | - |
|
| 154 | - return; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - $removed = array(); |
|
| 158 | - |
|
| 159 | - /** @var UserRole $d */ |
|
| 160 | - foreach ($delete as $d) { |
|
| 161 | - $removed[] = $d->getRole(); |
|
| 162 | - $d->delete(); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - foreach ($add as $x) { |
|
| 166 | - $a = new UserRole(); |
|
| 167 | - $a->setUser($user->getId()); |
|
| 168 | - $a->setRole($x); |
|
| 169 | - $a->setDatabase($database); |
|
| 170 | - $a->save(); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
| 174 | - |
|
| 175 | - // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
| 176 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 177 | - $user->save(); |
|
| 178 | - |
|
| 179 | - $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
| 180 | - SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 181 | - |
|
| 182 | - $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 183 | - |
|
| 184 | - return; |
|
| 185 | - } |
|
| 186 | - else { |
|
| 187 | - $this->assignCSRFToken(); |
|
| 188 | - $this->setTemplate('usermanagement/roleedit.tpl'); |
|
| 189 | - $this->assign('user', $user); |
|
| 190 | - $this->assign('roleData', $roleData); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Action target for suspending users |
|
| 196 | - * |
|
| 197 | - * @throws ApplicationLogicException |
|
| 198 | - */ |
|
| 199 | - protected function suspend() |
|
| 200 | - { |
|
| 201 | - $this->setHtmlTitle('User Management'); |
|
| 202 | - |
|
| 203 | - $database = $this->getDatabase(); |
|
| 204 | - |
|
| 205 | - $userId = WebRequest::getInt('user'); |
|
| 206 | - |
|
| 207 | - /** @var User $user */ |
|
| 208 | - $user = User::getById($userId, $database); |
|
| 209 | - |
|
| 210 | - if ($user === false) { |
|
| 211 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - if ($user->isSuspended()) { |
|
| 215 | - throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // Dual-mode action |
|
| 219 | - if (WebRequest::wasPosted()) { |
|
| 220 | - $this->validateCSRFToken(); |
|
| 221 | - $reason = WebRequest::postString('reason'); |
|
| 222 | - |
|
| 223 | - if ($reason === null || trim($reason) === "") { |
|
| 224 | - throw new ApplicationLogicException('No reason provided'); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $user->setStatus(User::STATUS_SUSPENDED); |
|
| 228 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 229 | - $user->save(); |
|
| 230 | - Logger::suspendedUser($database, $user, $reason); |
|
| 231 | - |
|
| 232 | - $this->getNotificationHelper()->userSuspended($user, $reason); |
|
| 233 | - SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 234 | - |
|
| 235 | - // send email |
|
| 236 | - $this->sendStatusChangeEmail( |
|
| 237 | - 'Your WP:ACC account has been suspended', |
|
| 238 | - 'usermanagement/emails/suspended.tpl', |
|
| 239 | - $reason, |
|
| 240 | - $user, |
|
| 241 | - User::getCurrent($database)->getUsername() |
|
| 242 | - ); |
|
| 243 | - |
|
| 244 | - $this->redirect('userManagement'); |
|
| 245 | - |
|
| 246 | - return; |
|
| 247 | - } |
|
| 248 | - else { |
|
| 249 | - $this->assignCSRFToken(); |
|
| 250 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
| 251 | - $this->assign('user', $user); |
|
| 252 | - $this->assign('status', 'Suspended'); |
|
| 253 | - $this->assign("showReason", true); |
|
| 254 | - |
|
| 255 | - if (WebRequest::getString('preload')) { |
|
| 256 | - $this->assign('preload', WebRequest::getString('preload')); |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Entry point for the decline action |
|
| 263 | - * |
|
| 264 | - * @throws ApplicationLogicException |
|
| 265 | - */ |
|
| 266 | - protected function decline() |
|
| 267 | - { |
|
| 268 | - $this->setHtmlTitle('User Management'); |
|
| 269 | - |
|
| 270 | - $database = $this->getDatabase(); |
|
| 271 | - |
|
| 272 | - $userId = WebRequest::getInt('user'); |
|
| 273 | - $user = User::getById($userId, $database); |
|
| 274 | - |
|
| 275 | - if ($user === false) { |
|
| 276 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if (!$user->isNewUser()) { |
|
| 280 | - throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Dual-mode action |
|
| 284 | - if (WebRequest::wasPosted()) { |
|
| 285 | - $this->validateCSRFToken(); |
|
| 286 | - $reason = WebRequest::postString('reason'); |
|
| 287 | - |
|
| 288 | - if ($reason === null || trim($reason) === "") { |
|
| 289 | - throw new ApplicationLogicException('No reason provided'); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - $user->setStatus(User::STATUS_DECLINED); |
|
| 293 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 294 | - $user->save(); |
|
| 295 | - Logger::declinedUser($database, $user, $reason); |
|
| 296 | - |
|
| 297 | - $this->getNotificationHelper()->userDeclined($user, $reason); |
|
| 298 | - SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 299 | - |
|
| 300 | - // send email |
|
| 301 | - $this->sendStatusChangeEmail( |
|
| 302 | - 'Your WP:ACC account has been declined', |
|
| 303 | - 'usermanagement/emails/declined.tpl', |
|
| 304 | - $reason, |
|
| 305 | - $user, |
|
| 306 | - User::getCurrent($database)->getUsername() |
|
| 307 | - ); |
|
| 308 | - |
|
| 309 | - $this->redirect('userManagement'); |
|
| 310 | - |
|
| 311 | - return; |
|
| 312 | - } |
|
| 313 | - else { |
|
| 314 | - $this->assignCSRFToken(); |
|
| 315 | - $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
| 316 | - $this->assign('user', $user); |
|
| 317 | - $this->assign('status', 'Declined'); |
|
| 318 | - $this->assign("showReason", true); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Entry point for the approve action |
|
| 324 | - * |
|
| 325 | - * @throws ApplicationLogicException |
|
| 326 | - */ |
|
| 327 | - protected function approve() |
|
| 328 | - { |
|
| 329 | - $this->setHtmlTitle('User Management'); |
|
| 330 | - |
|
| 331 | - $database = $this->getDatabase(); |
|
| 332 | - |
|
| 333 | - $userId = WebRequest::getInt('user'); |
|
| 334 | - $user = User::getById($userId, $database); |
|
| 335 | - |
|
| 336 | - if ($user === false) { |
|
| 337 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - if ($user->isActive()) { |
|
| 341 | - throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - // Dual-mode action |
|
| 345 | - if (WebRequest::wasPosted()) { |
|
| 346 | - $this->validateCSRFToken(); |
|
| 347 | - $user->setStatus(User::STATUS_ACTIVE); |
|
| 348 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 349 | - $user->save(); |
|
| 350 | - Logger::approvedUser($database, $user); |
|
| 351 | - |
|
| 352 | - $this->getNotificationHelper()->userApproved($user); |
|
| 353 | - SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 354 | - |
|
| 355 | - // send email |
|
| 356 | - $this->sendStatusChangeEmail( |
|
| 357 | - 'Your WP:ACC account has been approved', |
|
| 358 | - 'usermanagement/emails/approved.tpl', |
|
| 359 | - null, |
|
| 360 | - $user, |
|
| 361 | - User::getCurrent($database)->getUsername() |
|
| 362 | - ); |
|
| 363 | - |
|
| 364 | - $this->redirect("userManagement"); |
|
| 365 | - |
|
| 366 | - return; |
|
| 367 | - } |
|
| 368 | - else { |
|
| 369 | - $this->assignCSRFToken(); |
|
| 370 | - $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
| 371 | - $this->assign("user", $user); |
|
| 372 | - $this->assign("status", "Active"); |
|
| 373 | - $this->assign("showReason", false); |
|
| 374 | - } |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - #endregion |
|
| 378 | - |
|
| 379 | - #region Renaming / Editing |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Entry point for the rename action |
|
| 383 | - * |
|
| 384 | - * @throws ApplicationLogicException |
|
| 385 | - */ |
|
| 386 | - protected function rename() |
|
| 387 | - { |
|
| 388 | - $this->setHtmlTitle('User Management'); |
|
| 389 | - |
|
| 390 | - $database = $this->getDatabase(); |
|
| 391 | - |
|
| 392 | - $userId = WebRequest::getInt('user'); |
|
| 393 | - $user = User::getById($userId, $database); |
|
| 394 | - |
|
| 395 | - if ($user === false) { |
|
| 396 | - throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - // Dual-mode action |
|
| 400 | - if (WebRequest::wasPosted()) { |
|
| 401 | - $this->validateCSRFToken(); |
|
| 402 | - $newUsername = WebRequest::postString('newname'); |
|
| 403 | - |
|
| 404 | - if ($newUsername === null || trim($newUsername) === "") { |
|
| 405 | - throw new ApplicationLogicException('The new username cannot be empty'); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - if (User::getByUsername($newUsername, $database) != false) { |
|
| 409 | - throw new ApplicationLogicException('The new username already exists'); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $oldUsername = $user->getUsername(); |
|
| 413 | - $user->setUsername($newUsername); |
|
| 414 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 415 | - |
|
| 416 | - $user->save(); |
|
| 417 | - |
|
| 418 | - $logEntryData = serialize(array( |
|
| 419 | - 'old' => $oldUsername, |
|
| 420 | - 'new' => $newUsername, |
|
| 421 | - )); |
|
| 422 | - |
|
| 423 | - Logger::renamedUser($database, $user, $logEntryData); |
|
| 424 | - |
|
| 425 | - SessionAlert::quick("Changed User " |
|
| 426 | - . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
| 427 | - . " name to " |
|
| 428 | - . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
| 429 | - |
|
| 430 | - $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
| 431 | - |
|
| 432 | - // send an email to the user. |
|
| 433 | - $this->assign('targetUsername', $user->getUsername()); |
|
| 434 | - $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
| 435 | - $this->assign('oldUsername', $oldUsername); |
|
| 436 | - $this->assign('mailingList', $this->adminMailingList); |
|
| 437 | - |
|
| 438 | - $this->getEmailHelper()->sendMail( |
|
| 439 | - $user->getEmail(), |
|
| 440 | - 'Your username on WP:ACC has been changed', |
|
| 441 | - $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
| 442 | - array('Reply-To' => $this->adminMailingList) |
|
| 443 | - ); |
|
| 444 | - |
|
| 445 | - $this->redirect("userManagement"); |
|
| 446 | - |
|
| 447 | - return; |
|
| 448 | - } |
|
| 449 | - else { |
|
| 450 | - $this->assignCSRFToken(); |
|
| 451 | - $this->setTemplate('usermanagement/renameuser.tpl'); |
|
| 452 | - $this->assign('user', $user); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Entry point for the edit action |
|
| 458 | - * |
|
| 459 | - * @throws ApplicationLogicException |
|
| 460 | - */ |
|
| 461 | - protected function editUser() |
|
| 462 | - { |
|
| 463 | - $this->setHtmlTitle('User Management'); |
|
| 464 | - |
|
| 465 | - $database = $this->getDatabase(); |
|
| 466 | - |
|
| 467 | - $userId = WebRequest::getInt('user'); |
|
| 468 | - $user = User::getById($userId, $database); |
|
| 469 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 470 | - |
|
| 471 | - if ($user === false) { |
|
| 472 | - throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 473 | - } |
|
| 474 | - |
|
| 475 | - // Dual-mode action |
|
| 476 | - if (WebRequest::wasPosted()) { |
|
| 477 | - $this->validateCSRFToken(); |
|
| 478 | - $newEmail = WebRequest::postEmail('user_email'); |
|
| 479 | - $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
| 480 | - |
|
| 481 | - if ($newEmail === null) { |
|
| 482 | - throw new ApplicationLogicException('Invalid email address'); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) { |
|
| 486 | - if (trim($newOnWikiName) == "") { |
|
| 487 | - throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $user->setOnWikiName($newOnWikiName); |
|
| 491 | - $user->setWelcomeSig(WebRequest::postString('sig')); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - $user->setEmail($newEmail); |
|
| 495 | - $user->setCreationMode(WebRequest::postInt('creationmode')); |
|
| 496 | - |
|
| 497 | - $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 498 | - |
|
| 499 | - $user->save(); |
|
| 500 | - |
|
| 501 | - Logger::userPreferencesChange($database, $user); |
|
| 502 | - $this->getNotificationHelper()->userPrefChange($user); |
|
| 503 | - SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
| 504 | - |
|
| 505 | - $this->redirect("userManagement"); |
|
| 506 | - |
|
| 507 | - return; |
|
| 508 | - } |
|
| 509 | - else { |
|
| 510 | - $this->assignCSRFToken(); |
|
| 511 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 512 | - $this->getSiteConfiguration()); |
|
| 513 | - $this->setTemplate('usermanagement/edituser.tpl'); |
|
| 514 | - $this->assign('user', $user); |
|
| 515 | - $this->assign('oauth', $oauth); |
|
| 516 | - |
|
| 517 | - $this->assign('canManualCreate', |
|
| 518 | - $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 519 | - $this->assign('canOauthCreate', |
|
| 520 | - $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 521 | - $this->assign('canBotCreate', |
|
| 522 | - $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - #endregion |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Sends a status change email to the user. |
|
| 530 | - * |
|
| 531 | - * @param string $subject The subject of the email |
|
| 532 | - * @param string $template The smarty template to use |
|
| 533 | - * @param string|null $reason The reason for performing the status change |
|
| 534 | - * @param User $user The user affected |
|
| 535 | - * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
| 536 | - */ |
|
| 537 | - private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
| 538 | - { |
|
| 539 | - $this->assign('targetUsername', $user->getUsername()); |
|
| 540 | - $this->assign('toolAdmin', $toolAdminUsername); |
|
| 541 | - $this->assign('actionReason', $reason); |
|
| 542 | - $this->assign('mailingList', $this->adminMailingList); |
|
| 543 | - |
|
| 544 | - $this->getEmailHelper()->sendMail( |
|
| 545 | - $user->getEmail(), |
|
| 546 | - $subject, |
|
| 547 | - $this->fetchTemplate($template), |
|
| 548 | - array('Reply-To' => $this->adminMailingList) |
|
| 549 | - ); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * @param UserRole[] $activeRoles |
|
| 554 | - * |
|
| 555 | - * @return array |
|
| 556 | - */ |
|
| 557 | - private function getRoleData($activeRoles) |
|
| 558 | - { |
|
| 559 | - $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
| 560 | - |
|
| 561 | - $currentUser = User::getCurrent($this->getDatabase()); |
|
| 562 | - $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
| 563 | - |
|
| 564 | - $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
| 565 | - |
|
| 566 | - $roleData = array(); |
|
| 567 | - foreach ($availableRoles as $role => $data) { |
|
| 568 | - $intersection = array_intersect($data['editableBy'], $userRoles); |
|
| 569 | - |
|
| 570 | - $roleData[$role] = $initialValue; |
|
| 571 | - $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
| 572 | - $roleData[$role]['description'] = $data['description']; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - foreach ($activeRoles as $role) { |
|
| 576 | - if (!isset($roleData[$role->getRole()])) { |
|
| 577 | - // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
| 578 | - $roleData[$role->getRole()] = $initialValue; |
|
| 579 | - $roleData[$role->getRole()]['allowEdit'] = 1; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - $roleData[$role->getRole()]['object'] = $role; |
|
| 583 | - $roleData[$role->getRole()]['active'] = 1; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - return $roleData; |
|
| 587 | - } |
|
| 27 | + /** @var string */ |
|
| 28 | + private $adminMailingList = '[email protected]'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Main function for this page, when no specific actions are called. |
|
| 32 | + */ |
|
| 33 | + protected function main() |
|
| 34 | + { |
|
| 35 | + $this->setHtmlTitle('User Management'); |
|
| 36 | + |
|
| 37 | + $database = $this->getDatabase(); |
|
| 38 | + $currentUser = User::getCurrent($database); |
|
| 39 | + |
|
| 40 | + $userSearchRequest = WebRequest::getString('usersearch'); |
|
| 41 | + if ($userSearchRequest !== null) { |
|
| 42 | + $searchedUser = User::getByUsername($userSearchRequest, $database); |
|
| 43 | + if($searchedUser !== false) { |
|
| 44 | + $this->redirect('statistics/users', 'detail', ['user' => $searchedUser->getId()]); |
|
| 45 | + return; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to |
|
| 50 | + // the template. I still don't have a particularly good way of handling this. |
|
| 51 | + OAuthUserHelper::prepareTokenCountStatement($database); |
|
| 52 | + |
|
| 53 | + if (WebRequest::getBoolean("showAll")) { |
|
| 54 | + $this->assign("showAll", true); |
|
| 55 | + |
|
| 56 | + $suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch(); |
|
| 57 | + $this->assign("suspendedUsers", $suspendedUsers); |
|
| 58 | + |
|
| 59 | + $declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch(); |
|
| 60 | + $this->assign("declinedUsers", $declinedUsers); |
|
| 61 | + |
|
| 62 | + UserSearchHelper::get($database)->getRoleMap($roleMap); |
|
| 63 | + } |
|
| 64 | + else { |
|
| 65 | + $this->assign("showAll", false); |
|
| 66 | + $this->assign("suspendedUsers", array()); |
|
| 67 | + $this->assign("declinedUsers", array()); |
|
| 68 | + |
|
| 69 | + UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch(); |
|
| 73 | + $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch(); |
|
| 74 | + $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch(); |
|
| 75 | + $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch(); |
|
| 76 | + $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch(); |
|
| 77 | + $this->assign('newUsers', $newUsers); |
|
| 78 | + $this->assign('normalUsers', $normalUsers); |
|
| 79 | + $this->assign('adminUsers', $adminUsers); |
|
| 80 | + $this->assign('checkUsers', $checkUsers); |
|
| 81 | + $this->assign('toolRoots', $toolRoots); |
|
| 82 | + |
|
| 83 | + $this->assign('roles', $roleMap); |
|
| 84 | + |
|
| 85 | + $this->addJs("/api.php?action=users&all=true&targetVariable=typeaheaddata"); |
|
| 86 | + |
|
| 87 | + $this->assign('canApprove', $this->barrierTest('approve', $currentUser)); |
|
| 88 | + $this->assign('canDecline', $this->barrierTest('decline', $currentUser)); |
|
| 89 | + $this->assign('canRename', $this->barrierTest('rename', $currentUser)); |
|
| 90 | + $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser)); |
|
| 91 | + $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser)); |
|
| 92 | + $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser)); |
|
| 93 | + |
|
| 94 | + $this->setTemplate("usermanagement/main.tpl"); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + #region Access control |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Action target for editing the roles assigned to a user |
|
| 101 | + */ |
|
| 102 | + protected function editRoles() |
|
| 103 | + { |
|
| 104 | + $this->setHtmlTitle('User Management'); |
|
| 105 | + $database = $this->getDatabase(); |
|
| 106 | + $userId = WebRequest::getInt('user'); |
|
| 107 | + |
|
| 108 | + /** @var User $user */ |
|
| 109 | + $user = User::getById($userId, $database); |
|
| 110 | + |
|
| 111 | + if ($user === false) { |
|
| 112 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database)); |
|
| 116 | + |
|
| 117 | + // Dual-mode action |
|
| 118 | + if (WebRequest::wasPosted()) { |
|
| 119 | + $this->validateCSRFToken(); |
|
| 120 | + |
|
| 121 | + $reason = WebRequest::postString('reason'); |
|
| 122 | + if ($reason === false || trim($reason) === '') { |
|
| 123 | + throw new ApplicationLogicException('No reason specified for roles change'); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** @var UserRole[] $delete */ |
|
| 127 | + $delete = array(); |
|
| 128 | + /** @var string[] $delete */ |
|
| 129 | + $add = array(); |
|
| 130 | + |
|
| 131 | + foreach ($roleData as $name => $r) { |
|
| 132 | + if ($r['allowEdit'] !== 1) { |
|
| 133 | + // not allowed, to touch this, so ignore it |
|
| 134 | + continue; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0; |
|
| 138 | + if ($newValue !== $r['active']) { |
|
| 139 | + if ($newValue === 0) { |
|
| 140 | + $delete[] = $r['object']; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + if ($newValue === 1) { |
|
| 144 | + $add[] = $name; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // Check there's something to do |
|
| 150 | + if ((count($add) + count($delete)) === 0) { |
|
| 151 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 152 | + SessionAlert::warning('No changes made to roles.'); |
|
| 153 | + |
|
| 154 | + return; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + $removed = array(); |
|
| 158 | + |
|
| 159 | + /** @var UserRole $d */ |
|
| 160 | + foreach ($delete as $d) { |
|
| 161 | + $removed[] = $d->getRole(); |
|
| 162 | + $d->delete(); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + foreach ($add as $x) { |
|
| 166 | + $a = new UserRole(); |
|
| 167 | + $a->setUser($user->getId()); |
|
| 168 | + $a->setRole($x); |
|
| 169 | + $a->setDatabase($database); |
|
| 170 | + $a->save(); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + Logger::userRolesEdited($database, $user, $reason, $add, $removed); |
|
| 174 | + |
|
| 175 | + // dummy save for optimistic locking. If this fails, the entire txn will roll back. |
|
| 176 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 177 | + $user->save(); |
|
| 178 | + |
|
| 179 | + $this->getNotificationHelper()->userRolesEdited($user, $reason); |
|
| 180 | + SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 181 | + |
|
| 182 | + $this->redirect('statistics/users', 'detail', array('user' => $user->getId())); |
|
| 183 | + |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | + else { |
|
| 187 | + $this->assignCSRFToken(); |
|
| 188 | + $this->setTemplate('usermanagement/roleedit.tpl'); |
|
| 189 | + $this->assign('user', $user); |
|
| 190 | + $this->assign('roleData', $roleData); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Action target for suspending users |
|
| 196 | + * |
|
| 197 | + * @throws ApplicationLogicException |
|
| 198 | + */ |
|
| 199 | + protected function suspend() |
|
| 200 | + { |
|
| 201 | + $this->setHtmlTitle('User Management'); |
|
| 202 | + |
|
| 203 | + $database = $this->getDatabase(); |
|
| 204 | + |
|
| 205 | + $userId = WebRequest::getInt('user'); |
|
| 206 | + |
|
| 207 | + /** @var User $user */ |
|
| 208 | + $user = User::getById($userId, $database); |
|
| 209 | + |
|
| 210 | + if ($user === false) { |
|
| 211 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.'); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + if ($user->isSuspended()) { |
|
| 215 | + throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.'); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // Dual-mode action |
|
| 219 | + if (WebRequest::wasPosted()) { |
|
| 220 | + $this->validateCSRFToken(); |
|
| 221 | + $reason = WebRequest::postString('reason'); |
|
| 222 | + |
|
| 223 | + if ($reason === null || trim($reason) === "") { |
|
| 224 | + throw new ApplicationLogicException('No reason provided'); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $user->setStatus(User::STATUS_SUSPENDED); |
|
| 228 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 229 | + $user->save(); |
|
| 230 | + Logger::suspendedUser($database, $user, $reason); |
|
| 231 | + |
|
| 232 | + $this->getNotificationHelper()->userSuspended($user, $reason); |
|
| 233 | + SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 234 | + |
|
| 235 | + // send email |
|
| 236 | + $this->sendStatusChangeEmail( |
|
| 237 | + 'Your WP:ACC account has been suspended', |
|
| 238 | + 'usermanagement/emails/suspended.tpl', |
|
| 239 | + $reason, |
|
| 240 | + $user, |
|
| 241 | + User::getCurrent($database)->getUsername() |
|
| 242 | + ); |
|
| 243 | + |
|
| 244 | + $this->redirect('userManagement'); |
|
| 245 | + |
|
| 246 | + return; |
|
| 247 | + } |
|
| 248 | + else { |
|
| 249 | + $this->assignCSRFToken(); |
|
| 250 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
| 251 | + $this->assign('user', $user); |
|
| 252 | + $this->assign('status', 'Suspended'); |
|
| 253 | + $this->assign("showReason", true); |
|
| 254 | + |
|
| 255 | + if (WebRequest::getString('preload')) { |
|
| 256 | + $this->assign('preload', WebRequest::getString('preload')); |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Entry point for the decline action |
|
| 263 | + * |
|
| 264 | + * @throws ApplicationLogicException |
|
| 265 | + */ |
|
| 266 | + protected function decline() |
|
| 267 | + { |
|
| 268 | + $this->setHtmlTitle('User Management'); |
|
| 269 | + |
|
| 270 | + $database = $this->getDatabase(); |
|
| 271 | + |
|
| 272 | + $userId = WebRequest::getInt('user'); |
|
| 273 | + $user = User::getById($userId, $database); |
|
| 274 | + |
|
| 275 | + if ($user === false) { |
|
| 276 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.'); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if (!$user->isNewUser()) { |
|
| 280 | + throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.'); |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Dual-mode action |
|
| 284 | + if (WebRequest::wasPosted()) { |
|
| 285 | + $this->validateCSRFToken(); |
|
| 286 | + $reason = WebRequest::postString('reason'); |
|
| 287 | + |
|
| 288 | + if ($reason === null || trim($reason) === "") { |
|
| 289 | + throw new ApplicationLogicException('No reason provided'); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + $user->setStatus(User::STATUS_DECLINED); |
|
| 293 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 294 | + $user->save(); |
|
| 295 | + Logger::declinedUser($database, $user, $reason); |
|
| 296 | + |
|
| 297 | + $this->getNotificationHelper()->userDeclined($user, $reason); |
|
| 298 | + SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 299 | + |
|
| 300 | + // send email |
|
| 301 | + $this->sendStatusChangeEmail( |
|
| 302 | + 'Your WP:ACC account has been declined', |
|
| 303 | + 'usermanagement/emails/declined.tpl', |
|
| 304 | + $reason, |
|
| 305 | + $user, |
|
| 306 | + User::getCurrent($database)->getUsername() |
|
| 307 | + ); |
|
| 308 | + |
|
| 309 | + $this->redirect('userManagement'); |
|
| 310 | + |
|
| 311 | + return; |
|
| 312 | + } |
|
| 313 | + else { |
|
| 314 | + $this->assignCSRFToken(); |
|
| 315 | + $this->setTemplate('usermanagement/changelevel-reason.tpl'); |
|
| 316 | + $this->assign('user', $user); |
|
| 317 | + $this->assign('status', 'Declined'); |
|
| 318 | + $this->assign("showReason", true); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Entry point for the approve action |
|
| 324 | + * |
|
| 325 | + * @throws ApplicationLogicException |
|
| 326 | + */ |
|
| 327 | + protected function approve() |
|
| 328 | + { |
|
| 329 | + $this->setHtmlTitle('User Management'); |
|
| 330 | + |
|
| 331 | + $database = $this->getDatabase(); |
|
| 332 | + |
|
| 333 | + $userId = WebRequest::getInt('user'); |
|
| 334 | + $user = User::getById($userId, $database); |
|
| 335 | + |
|
| 336 | + if ($user === false) { |
|
| 337 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.'); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + if ($user->isActive()) { |
|
| 341 | + throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.'); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + // Dual-mode action |
|
| 345 | + if (WebRequest::wasPosted()) { |
|
| 346 | + $this->validateCSRFToken(); |
|
| 347 | + $user->setStatus(User::STATUS_ACTIVE); |
|
| 348 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 349 | + $user->save(); |
|
| 350 | + Logger::approvedUser($database, $user); |
|
| 351 | + |
|
| 352 | + $this->getNotificationHelper()->userApproved($user); |
|
| 353 | + SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8')); |
|
| 354 | + |
|
| 355 | + // send email |
|
| 356 | + $this->sendStatusChangeEmail( |
|
| 357 | + 'Your WP:ACC account has been approved', |
|
| 358 | + 'usermanagement/emails/approved.tpl', |
|
| 359 | + null, |
|
| 360 | + $user, |
|
| 361 | + User::getCurrent($database)->getUsername() |
|
| 362 | + ); |
|
| 363 | + |
|
| 364 | + $this->redirect("userManagement"); |
|
| 365 | + |
|
| 366 | + return; |
|
| 367 | + } |
|
| 368 | + else { |
|
| 369 | + $this->assignCSRFToken(); |
|
| 370 | + $this->setTemplate("usermanagement/changelevel-reason.tpl"); |
|
| 371 | + $this->assign("user", $user); |
|
| 372 | + $this->assign("status", "Active"); |
|
| 373 | + $this->assign("showReason", false); |
|
| 374 | + } |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + #endregion |
|
| 378 | + |
|
| 379 | + #region Renaming / Editing |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Entry point for the rename action |
|
| 383 | + * |
|
| 384 | + * @throws ApplicationLogicException |
|
| 385 | + */ |
|
| 386 | + protected function rename() |
|
| 387 | + { |
|
| 388 | + $this->setHtmlTitle('User Management'); |
|
| 389 | + |
|
| 390 | + $database = $this->getDatabase(); |
|
| 391 | + |
|
| 392 | + $userId = WebRequest::getInt('user'); |
|
| 393 | + $user = User::getById($userId, $database); |
|
| 394 | + |
|
| 395 | + if ($user === false) { |
|
| 396 | + throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.'); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + // Dual-mode action |
|
| 400 | + if (WebRequest::wasPosted()) { |
|
| 401 | + $this->validateCSRFToken(); |
|
| 402 | + $newUsername = WebRequest::postString('newname'); |
|
| 403 | + |
|
| 404 | + if ($newUsername === null || trim($newUsername) === "") { |
|
| 405 | + throw new ApplicationLogicException('The new username cannot be empty'); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + if (User::getByUsername($newUsername, $database) != false) { |
|
| 409 | + throw new ApplicationLogicException('The new username already exists'); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $oldUsername = $user->getUsername(); |
|
| 413 | + $user->setUsername($newUsername); |
|
| 414 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 415 | + |
|
| 416 | + $user->save(); |
|
| 417 | + |
|
| 418 | + $logEntryData = serialize(array( |
|
| 419 | + 'old' => $oldUsername, |
|
| 420 | + 'new' => $newUsername, |
|
| 421 | + )); |
|
| 422 | + |
|
| 423 | + Logger::renamedUser($database, $user, $logEntryData); |
|
| 424 | + |
|
| 425 | + SessionAlert::quick("Changed User " |
|
| 426 | + . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8') |
|
| 427 | + . " name to " |
|
| 428 | + . htmlentities($newUsername, ENT_COMPAT, 'UTF-8')); |
|
| 429 | + |
|
| 430 | + $this->getNotificationHelper()->userRenamed($user, $oldUsername); |
|
| 431 | + |
|
| 432 | + // send an email to the user. |
|
| 433 | + $this->assign('targetUsername', $user->getUsername()); |
|
| 434 | + $this->assign('toolAdmin', User::getCurrent($database)->getUsername()); |
|
| 435 | + $this->assign('oldUsername', $oldUsername); |
|
| 436 | + $this->assign('mailingList', $this->adminMailingList); |
|
| 437 | + |
|
| 438 | + $this->getEmailHelper()->sendMail( |
|
| 439 | + $user->getEmail(), |
|
| 440 | + 'Your username on WP:ACC has been changed', |
|
| 441 | + $this->fetchTemplate('usermanagement/emails/renamed.tpl'), |
|
| 442 | + array('Reply-To' => $this->adminMailingList) |
|
| 443 | + ); |
|
| 444 | + |
|
| 445 | + $this->redirect("userManagement"); |
|
| 446 | + |
|
| 447 | + return; |
|
| 448 | + } |
|
| 449 | + else { |
|
| 450 | + $this->assignCSRFToken(); |
|
| 451 | + $this->setTemplate('usermanagement/renameuser.tpl'); |
|
| 452 | + $this->assign('user', $user); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Entry point for the edit action |
|
| 458 | + * |
|
| 459 | + * @throws ApplicationLogicException |
|
| 460 | + */ |
|
| 461 | + protected function editUser() |
|
| 462 | + { |
|
| 463 | + $this->setHtmlTitle('User Management'); |
|
| 464 | + |
|
| 465 | + $database = $this->getDatabase(); |
|
| 466 | + |
|
| 467 | + $userId = WebRequest::getInt('user'); |
|
| 468 | + $user = User::getById($userId, $database); |
|
| 469 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
| 470 | + |
|
| 471 | + if ($user === false) { |
|
| 472 | + throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.'); |
|
| 473 | + } |
|
| 474 | + |
|
| 475 | + // Dual-mode action |
|
| 476 | + if (WebRequest::wasPosted()) { |
|
| 477 | + $this->validateCSRFToken(); |
|
| 478 | + $newEmail = WebRequest::postEmail('user_email'); |
|
| 479 | + $newOnWikiName = WebRequest::postString('user_onwikiname'); |
|
| 480 | + |
|
| 481 | + if ($newEmail === null) { |
|
| 482 | + throw new ApplicationLogicException('Invalid email address'); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if (!($oauth->isFullyLinked() || $oauth->isPartiallyLinked())) { |
|
| 486 | + if (trim($newOnWikiName) == "") { |
|
| 487 | + throw new ApplicationLogicException('New on-wiki username cannot be blank'); |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $user->setOnWikiName($newOnWikiName); |
|
| 491 | + $user->setWelcomeSig(WebRequest::postString('sig')); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + $user->setEmail($newEmail); |
|
| 495 | + $user->setCreationMode(WebRequest::postInt('creationmode')); |
|
| 496 | + |
|
| 497 | + $user->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 498 | + |
|
| 499 | + $user->save(); |
|
| 500 | + |
|
| 501 | + Logger::userPreferencesChange($database, $user); |
|
| 502 | + $this->getNotificationHelper()->userPrefChange($user); |
|
| 503 | + SessionAlert::quick('Changes to user\'s preferences have been saved'); |
|
| 504 | + |
|
| 505 | + $this->redirect("userManagement"); |
|
| 506 | + |
|
| 507 | + return; |
|
| 508 | + } |
|
| 509 | + else { |
|
| 510 | + $this->assignCSRFToken(); |
|
| 511 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), |
|
| 512 | + $this->getSiteConfiguration()); |
|
| 513 | + $this->setTemplate('usermanagement/edituser.tpl'); |
|
| 514 | + $this->assign('user', $user); |
|
| 515 | + $this->assign('oauth', $oauth); |
|
| 516 | + |
|
| 517 | + $this->assign('canManualCreate', |
|
| 518 | + $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation')); |
|
| 519 | + $this->assign('canOauthCreate', |
|
| 520 | + $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation')); |
|
| 521 | + $this->assign('canBotCreate', |
|
| 522 | + $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation')); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + #endregion |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Sends a status change email to the user. |
|
| 530 | + * |
|
| 531 | + * @param string $subject The subject of the email |
|
| 532 | + * @param string $template The smarty template to use |
|
| 533 | + * @param string|null $reason The reason for performing the status change |
|
| 534 | + * @param User $user The user affected |
|
| 535 | + * @param string $toolAdminUsername The tool admin's username who is making the edit |
|
| 536 | + */ |
|
| 537 | + private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername) |
|
| 538 | + { |
|
| 539 | + $this->assign('targetUsername', $user->getUsername()); |
|
| 540 | + $this->assign('toolAdmin', $toolAdminUsername); |
|
| 541 | + $this->assign('actionReason', $reason); |
|
| 542 | + $this->assign('mailingList', $this->adminMailingList); |
|
| 543 | + |
|
| 544 | + $this->getEmailHelper()->sendMail( |
|
| 545 | + $user->getEmail(), |
|
| 546 | + $subject, |
|
| 547 | + $this->fetchTemplate($template), |
|
| 548 | + array('Reply-To' => $this->adminMailingList) |
|
| 549 | + ); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * @param UserRole[] $activeRoles |
|
| 554 | + * |
|
| 555 | + * @return array |
|
| 556 | + */ |
|
| 557 | + private function getRoleData($activeRoles) |
|
| 558 | + { |
|
| 559 | + $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles(); |
|
| 560 | + |
|
| 561 | + $currentUser = User::getCurrent($this->getDatabase()); |
|
| 562 | + $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles); |
|
| 563 | + |
|
| 564 | + $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null); |
|
| 565 | + |
|
| 566 | + $roleData = array(); |
|
| 567 | + foreach ($availableRoles as $role => $data) { |
|
| 568 | + $intersection = array_intersect($data['editableBy'], $userRoles); |
|
| 569 | + |
|
| 570 | + $roleData[$role] = $initialValue; |
|
| 571 | + $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0; |
|
| 572 | + $roleData[$role]['description'] = $data['description']; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + foreach ($activeRoles as $role) { |
|
| 576 | + if (!isset($roleData[$role->getRole()])) { |
|
| 577 | + // This value is no longer available in the configuration, allow changing (aka removing) it. |
|
| 578 | + $roleData[$role->getRole()] = $initialValue; |
|
| 579 | + $roleData[$role->getRole()]['allowEdit'] = 1; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + $roleData[$role->getRole()]['object'] = $role; |
|
| 583 | + $roleData[$role->getRole()]['active'] = 1; |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + return $roleData; |
|
| 587 | + } |
|
| 588 | 588 | } |