@@ -19,179 +19,179 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageEmailManagement 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 | - $this->setHtmlTitle('Close Emails'); |
|
| 29 | - |
|
| 30 | - // Get all active email templates |
|
| 31 | - $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase()); |
|
| 32 | - $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase()); |
|
| 33 | - |
|
| 34 | - $this->assign('activeTemplates', $activeTemplates); |
|
| 35 | - $this->assign('inactiveTemplates', $inactiveTemplates); |
|
| 36 | - |
|
| 37 | - $user = User::getCurrent($this->getDatabase()); |
|
| 38 | - $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
| 39 | - $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 40 | - |
|
| 41 | - $this->setTemplate('email-management/main.tpl'); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - protected function view() |
|
| 45 | - { |
|
| 46 | - $this->setHtmlTitle('Close Emails'); |
|
| 47 | - |
|
| 48 | - $database = $this->getDatabase(); |
|
| 49 | - $template = $this->getTemplate($database); |
|
| 50 | - |
|
| 51 | - $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
| 52 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 53 | - |
|
| 54 | - $this->assign('id', $template->getId()); |
|
| 55 | - $this->assign('emailTemplate', $template); |
|
| 56 | - $this->assign('createdid', $createdId); |
|
| 57 | - $this->assign('requeststates', $requestStates); |
|
| 58 | - |
|
| 59 | - $this->setTemplate('email-management/view.tpl'); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @param PdoDatabase $database |
|
| 64 | - * |
|
| 65 | - * @return EmailTemplate |
|
| 66 | - * @throws ApplicationLogicException |
|
| 67 | - */ |
|
| 68 | - protected function getTemplate(PdoDatabase $database) |
|
| 69 | - { |
|
| 70 | - $templateId = WebRequest::getInt('id'); |
|
| 71 | - if ($templateId === null) { |
|
| 72 | - throw new ApplicationLogicException('Template not specified'); |
|
| 73 | - } |
|
| 74 | - $template = EmailTemplate::getById($templateId, $database); |
|
| 75 | - if ($template === false || !is_a($template, EmailTemplate::class)) { |
|
| 76 | - throw new ApplicationLogicException('Template not found'); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - return $template; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - protected function edit() |
|
| 83 | - { |
|
| 84 | - $this->setHtmlTitle('Close Emails'); |
|
| 85 | - |
|
| 86 | - $database = $this->getDatabase(); |
|
| 87 | - $template = $this->getTemplate($database); |
|
| 88 | - |
|
| 89 | - $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
| 90 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 91 | - |
|
| 92 | - if (WebRequest::wasPosted()) { |
|
| 93 | - $this->validateCSRFToken(); |
|
| 94 | - |
|
| 95 | - $this->modifyTemplateData($template); |
|
| 96 | - |
|
| 97 | - $other = EmailTemplate::getByName($template->getName(), $database); |
|
| 98 | - if ($other !== false && $other->getId() !== $template->getId()) { |
|
| 99 | - throw new ApplicationLogicException('A template with this name already exists'); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($template->getId() === $createdId) { |
|
| 103 | - $template->setDefaultAction(EmailTemplate::CREATED); |
|
| 104 | - $template->setActive(true); |
|
| 105 | - $template->setPreloadOnly(false); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // optimistically lock on load of edit form |
|
| 109 | - $updateVersion = WebRequest::postInt('updateversion'); |
|
| 110 | - $template->setUpdateVersion($updateVersion); |
|
| 111 | - |
|
| 112 | - $template->save(); |
|
| 113 | - Logger::editedEmail($database, $template); |
|
| 114 | - $this->getNotificationHelper()->emailEdited($template); |
|
| 115 | - SessionAlert::success("Email template has been saved successfully."); |
|
| 116 | - |
|
| 117 | - $this->redirect('emailManagement'); |
|
| 118 | - } |
|
| 119 | - else { |
|
| 120 | - $this->assignCSRFToken(); |
|
| 121 | - $this->assign('id', $template->getId()); |
|
| 122 | - $this->assign('emailTemplate', $template); |
|
| 123 | - $this->assign('createdid', $createdId); |
|
| 124 | - $this->assign('requeststates', $requestStates); |
|
| 125 | - |
|
| 126 | - $this->setTemplate('email-management/edit.tpl'); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * @param EmailTemplate $template |
|
| 132 | - * |
|
| 133 | - * @throws ApplicationLogicException |
|
| 134 | - */ |
|
| 135 | - private function modifyTemplateData(EmailTemplate $template) |
|
| 136 | - { |
|
| 137 | - $name = WebRequest::postString('name'); |
|
| 138 | - if ($name === null || $name === '') { |
|
| 139 | - throw new ApplicationLogicException('Name not specified'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - $template->setName($name); |
|
| 143 | - |
|
| 144 | - $text = WebRequest::postString('text'); |
|
| 145 | - if ($text === null || $text === '') { |
|
| 146 | - throw new ApplicationLogicException('Text not specified'); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - $template->setText($text); |
|
| 150 | - |
|
| 151 | - $template->setJsquestion(WebRequest::postString('jsquestion')); |
|
| 152 | - |
|
| 153 | - $template->setDefaultAction(WebRequest::postString('defaultaction')); |
|
| 154 | - $template->setActive(WebRequest::postBoolean('active')); |
|
| 155 | - $template->setPreloadOnly(WebRequest::postBoolean('preloadonly')); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - protected function create() |
|
| 159 | - { |
|
| 160 | - $this->setHtmlTitle('Close Emails'); |
|
| 161 | - |
|
| 162 | - $database = $this->getDatabase(); |
|
| 163 | - |
|
| 164 | - $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 165 | - |
|
| 166 | - if (WebRequest::wasPosted()) { |
|
| 167 | - $this->validateCSRFToken(); |
|
| 168 | - $template = new EmailTemplate(); |
|
| 169 | - $template->setDatabase($database); |
|
| 170 | - |
|
| 171 | - $this->modifyTemplateData($template); |
|
| 172 | - |
|
| 173 | - $other = EmailTemplate::getByName($template->getName(), $database); |
|
| 174 | - if ($other !== false) { |
|
| 175 | - throw new ApplicationLogicException('A template with this name already exists'); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - $template->save(); |
|
| 179 | - |
|
| 180 | - Logger::createEmail($database, $template); |
|
| 181 | - $this->getNotificationHelper()->emailCreated($template); |
|
| 182 | - |
|
| 183 | - SessionAlert::success("Email template has been saved successfully."); |
|
| 184 | - |
|
| 185 | - $this->redirect('emailManagement'); |
|
| 186 | - } |
|
| 187 | - else { |
|
| 188 | - $this->assignCSRFToken(); |
|
| 189 | - $this->assign('id', -1); |
|
| 190 | - $this->assign('emailTemplate', new EmailTemplate()); |
|
| 191 | - $this->assign('createdid', -2); |
|
| 192 | - |
|
| 193 | - $this->assign('requeststates', $requestStates); |
|
| 194 | - $this->setTemplate('email-management/edit.tpl'); |
|
| 195 | - } |
|
| 196 | - } |
|
| 22 | + /** |
|
| 23 | + * Main function for this page, when no specific actions are called. |
|
| 24 | + * @return void |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + $this->setHtmlTitle('Close Emails'); |
|
| 29 | + |
|
| 30 | + // Get all active email templates |
|
| 31 | + $activeTemplates = EmailTemplate::getAllActiveTemplates(null, $this->getDatabase()); |
|
| 32 | + $inactiveTemplates = EmailTemplate::getAllInactiveTemplates($this->getDatabase()); |
|
| 33 | + |
|
| 34 | + $this->assign('activeTemplates', $activeTemplates); |
|
| 35 | + $this->assign('inactiveTemplates', $inactiveTemplates); |
|
| 36 | + |
|
| 37 | + $user = User::getCurrent($this->getDatabase()); |
|
| 38 | + $this->assign('canCreate', $this->barrierTest('create', $user)); |
|
| 39 | + $this->assign('canEdit', $this->barrierTest('edit', $user)); |
|
| 40 | + |
|
| 41 | + $this->setTemplate('email-management/main.tpl'); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + protected function view() |
|
| 45 | + { |
|
| 46 | + $this->setHtmlTitle('Close Emails'); |
|
| 47 | + |
|
| 48 | + $database = $this->getDatabase(); |
|
| 49 | + $template = $this->getTemplate($database); |
|
| 50 | + |
|
| 51 | + $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
| 52 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 53 | + |
|
| 54 | + $this->assign('id', $template->getId()); |
|
| 55 | + $this->assign('emailTemplate', $template); |
|
| 56 | + $this->assign('createdid', $createdId); |
|
| 57 | + $this->assign('requeststates', $requestStates); |
|
| 58 | + |
|
| 59 | + $this->setTemplate('email-management/view.tpl'); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @param PdoDatabase $database |
|
| 64 | + * |
|
| 65 | + * @return EmailTemplate |
|
| 66 | + * @throws ApplicationLogicException |
|
| 67 | + */ |
|
| 68 | + protected function getTemplate(PdoDatabase $database) |
|
| 69 | + { |
|
| 70 | + $templateId = WebRequest::getInt('id'); |
|
| 71 | + if ($templateId === null) { |
|
| 72 | + throw new ApplicationLogicException('Template not specified'); |
|
| 73 | + } |
|
| 74 | + $template = EmailTemplate::getById($templateId, $database); |
|
| 75 | + if ($template === false || !is_a($template, EmailTemplate::class)) { |
|
| 76 | + throw new ApplicationLogicException('Template not found'); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + return $template; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + protected function edit() |
|
| 83 | + { |
|
| 84 | + $this->setHtmlTitle('Close Emails'); |
|
| 85 | + |
|
| 86 | + $database = $this->getDatabase(); |
|
| 87 | + $template = $this->getTemplate($database); |
|
| 88 | + |
|
| 89 | + $createdId = $this->getSiteConfiguration()->getDefaultCreatedTemplateId(); |
|
| 90 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 91 | + |
|
| 92 | + if (WebRequest::wasPosted()) { |
|
| 93 | + $this->validateCSRFToken(); |
|
| 94 | + |
|
| 95 | + $this->modifyTemplateData($template); |
|
| 96 | + |
|
| 97 | + $other = EmailTemplate::getByName($template->getName(), $database); |
|
| 98 | + if ($other !== false && $other->getId() !== $template->getId()) { |
|
| 99 | + throw new ApplicationLogicException('A template with this name already exists'); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($template->getId() === $createdId) { |
|
| 103 | + $template->setDefaultAction(EmailTemplate::CREATED); |
|
| 104 | + $template->setActive(true); |
|
| 105 | + $template->setPreloadOnly(false); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // optimistically lock on load of edit form |
|
| 109 | + $updateVersion = WebRequest::postInt('updateversion'); |
|
| 110 | + $template->setUpdateVersion($updateVersion); |
|
| 111 | + |
|
| 112 | + $template->save(); |
|
| 113 | + Logger::editedEmail($database, $template); |
|
| 114 | + $this->getNotificationHelper()->emailEdited($template); |
|
| 115 | + SessionAlert::success("Email template has been saved successfully."); |
|
| 116 | + |
|
| 117 | + $this->redirect('emailManagement'); |
|
| 118 | + } |
|
| 119 | + else { |
|
| 120 | + $this->assignCSRFToken(); |
|
| 121 | + $this->assign('id', $template->getId()); |
|
| 122 | + $this->assign('emailTemplate', $template); |
|
| 123 | + $this->assign('createdid', $createdId); |
|
| 124 | + $this->assign('requeststates', $requestStates); |
|
| 125 | + |
|
| 126 | + $this->setTemplate('email-management/edit.tpl'); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * @param EmailTemplate $template |
|
| 132 | + * |
|
| 133 | + * @throws ApplicationLogicException |
|
| 134 | + */ |
|
| 135 | + private function modifyTemplateData(EmailTemplate $template) |
|
| 136 | + { |
|
| 137 | + $name = WebRequest::postString('name'); |
|
| 138 | + if ($name === null || $name === '') { |
|
| 139 | + throw new ApplicationLogicException('Name not specified'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + $template->setName($name); |
|
| 143 | + |
|
| 144 | + $text = WebRequest::postString('text'); |
|
| 145 | + if ($text === null || $text === '') { |
|
| 146 | + throw new ApplicationLogicException('Text not specified'); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + $template->setText($text); |
|
| 150 | + |
|
| 151 | + $template->setJsquestion(WebRequest::postString('jsquestion')); |
|
| 152 | + |
|
| 153 | + $template->setDefaultAction(WebRequest::postString('defaultaction')); |
|
| 154 | + $template->setActive(WebRequest::postBoolean('active')); |
|
| 155 | + $template->setPreloadOnly(WebRequest::postBoolean('preloadonly')); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + protected function create() |
|
| 159 | + { |
|
| 160 | + $this->setHtmlTitle('Close Emails'); |
|
| 161 | + |
|
| 162 | + $database = $this->getDatabase(); |
|
| 163 | + |
|
| 164 | + $requestStates = $this->getSiteConfiguration()->getRequestStates(); |
|
| 165 | + |
|
| 166 | + if (WebRequest::wasPosted()) { |
|
| 167 | + $this->validateCSRFToken(); |
|
| 168 | + $template = new EmailTemplate(); |
|
| 169 | + $template->setDatabase($database); |
|
| 170 | + |
|
| 171 | + $this->modifyTemplateData($template); |
|
| 172 | + |
|
| 173 | + $other = EmailTemplate::getByName($template->getName(), $database); |
|
| 174 | + if ($other !== false) { |
|
| 175 | + throw new ApplicationLogicException('A template with this name already exists'); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + $template->save(); |
|
| 179 | + |
|
| 180 | + Logger::createEmail($database, $template); |
|
| 181 | + $this->getNotificationHelper()->emailCreated($template); |
|
| 182 | + |
|
| 183 | + SessionAlert::success("Email template has been saved successfully."); |
|
| 184 | + |
|
| 185 | + $this->redirect('emailManagement'); |
|
| 186 | + } |
|
| 187 | + else { |
|
| 188 | + $this->assignCSRFToken(); |
|
| 189 | + $this->assign('id', -1); |
|
| 190 | + $this->assign('emailTemplate', new EmailTemplate()); |
|
| 191 | + $this->assign('createdid', -2); |
|
| 192 | + |
|
| 193 | + $this->assign('requeststates', $requestStates); |
|
| 194 | + $this->setTemplate('email-management/edit.tpl'); |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | 197 | } |
@@ -115,8 +115,7 @@ discard block |
||
| 115 | 115 | SessionAlert::success("Email template has been saved successfully."); |
| 116 | 116 | |
| 117 | 117 | $this->redirect('emailManagement'); |
| 118 | - } |
|
| 119 | - else { |
|
| 118 | + } else { |
|
| 120 | 119 | $this->assignCSRFToken(); |
| 121 | 120 | $this->assign('id', $template->getId()); |
| 122 | 121 | $this->assign('emailTemplate', $template); |
@@ -183,8 +182,7 @@ discard block |
||
| 183 | 182 | SessionAlert::success("Email template has been saved successfully."); |
| 184 | 183 | |
| 185 | 184 | $this->redirect('emailManagement'); |
| 186 | - } |
|
| 187 | - else { |
|
| 185 | + } else { |
|
| 188 | 186 | $this->assignCSRFToken(); |
| 189 | 187 | $this->assign('id', -1); |
| 190 | 188 | $this->assign('emailTemplate', new EmailTemplate()); |
@@ -17,31 +17,31 @@ |
||
| 17 | 17 | |
| 18 | 18 | class StatsInactiveUsers extends InternalPageBase |
| 19 | 19 | { |
| 20 | - public function main() |
|
| 21 | - { |
|
| 22 | - $this->setHtmlTitle('Inactive Users :: Statistics'); |
|
| 23 | - |
|
| 24 | - $date = new DateTime(); |
|
| 25 | - $date->modify("-90 days"); |
|
| 26 | - |
|
| 27 | - $inactiveUsers = UserSearchHelper::get($this->getDatabase()) |
|
| 28 | - ->byStatus('Active') |
|
| 29 | - ->lastActiveBefore($date) |
|
| 30 | - ->getRoleMap($roleMap) |
|
| 31 | - ->fetch(); |
|
| 32 | - |
|
| 33 | - $this->assign('inactiveUsers', $inactiveUsers); |
|
| 34 | - $this->assign('roles', $roleMap); |
|
| 35 | - $this->assign('canSuspend', |
|
| 36 | - $this->barrierTest('suspend', User::getCurrent($this->getDatabase()), PageUserManagement::class)); |
|
| 37 | - |
|
| 38 | - $immuneUsers = $this->getDatabase() |
|
| 39 | - ->query("SELECT user FROM userrole WHERE role IN ('toolRoot', 'checkuser') GROUP BY user;") |
|
| 40 | - ->fetchAll(PDO::FETCH_COLUMN); |
|
| 20 | + public function main() |
|
| 21 | + { |
|
| 22 | + $this->setHtmlTitle('Inactive Users :: Statistics'); |
|
| 23 | + |
|
| 24 | + $date = new DateTime(); |
|
| 25 | + $date->modify("-90 days"); |
|
| 26 | + |
|
| 27 | + $inactiveUsers = UserSearchHelper::get($this->getDatabase()) |
|
| 28 | + ->byStatus('Active') |
|
| 29 | + ->lastActiveBefore($date) |
|
| 30 | + ->getRoleMap($roleMap) |
|
| 31 | + ->fetch(); |
|
| 32 | + |
|
| 33 | + $this->assign('inactiveUsers', $inactiveUsers); |
|
| 34 | + $this->assign('roles', $roleMap); |
|
| 35 | + $this->assign('canSuspend', |
|
| 36 | + $this->barrierTest('suspend', User::getCurrent($this->getDatabase()), PageUserManagement::class)); |
|
| 37 | + |
|
| 38 | + $immuneUsers = $this->getDatabase() |
|
| 39 | + ->query("SELECT user FROM userrole WHERE role IN ('toolRoot', 'checkuser') GROUP BY user;") |
|
| 40 | + ->fetchAll(PDO::FETCH_COLUMN); |
|
| 41 | 41 | |
| 42 | - $this->assign('immune', array_fill_keys($immuneUsers, true)); |
|
| 42 | + $this->assign('immune', array_fill_keys($immuneUsers, true)); |
|
| 43 | 43 | |
| 44 | - $this->setTemplate('statistics/inactive-users.tpl'); |
|
| 45 | - $this->assign('statsPageTitle', 'Inactive tool users'); |
|
| 46 | - } |
|
| 44 | + $this->setTemplate('statistics/inactive-users.tpl'); |
|
| 45 | + $this->assign('statsPageTitle', 'Inactive tool users'); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -16,65 +16,65 @@ |
||
| 16 | 16 | |
| 17 | 17 | class PageExpandedRequestList extends InternalPageBase |
| 18 | 18 | { |
| 19 | - use RequestListData; |
|
| 19 | + use RequestListData; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Main function for this page, when no specific actions are called. |
|
| 23 | - * @return void |
|
| 24 | - * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 25 | - */ |
|
| 26 | - protected function main() |
|
| 27 | - { |
|
| 28 | - $config = $this->getSiteConfiguration(); |
|
| 21 | + /** |
|
| 22 | + * Main function for this page, when no specific actions are called. |
|
| 23 | + * @return void |
|
| 24 | + * @todo This is very similar to the PageMain code, we could probably generalise this somehow |
|
| 25 | + */ |
|
| 26 | + protected function main() |
|
| 27 | + { |
|
| 28 | + $config = $this->getSiteConfiguration(); |
|
| 29 | 29 | |
| 30 | - $requestedStatus = WebRequest::getString('status'); |
|
| 31 | - $requestStates = $config->getRequestStates(); |
|
| 30 | + $requestedStatus = WebRequest::getString('status'); |
|
| 31 | + $requestStates = $config->getRequestStates(); |
|
| 32 | 32 | |
| 33 | - if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
| 33 | + if ($requestedStatus !== null && isset($requestStates[$requestedStatus])) { |
|
| 34 | 34 | |
| 35 | - $this->assignCSRFToken(); |
|
| 35 | + $this->assignCSRFToken(); |
|
| 36 | 36 | |
| 37 | - $database = $this->getDatabase(); |
|
| 37 | + $database = $this->getDatabase(); |
|
| 38 | 38 | |
| 39 | - $help = $requestStates[$requestedStatus]['queuehelp']; |
|
| 40 | - $this->assign('queuehelp', $help); |
|
| 39 | + $help = $requestStates[$requestedStatus]['queuehelp']; |
|
| 40 | + $this->assign('queuehelp', $help); |
|
| 41 | 41 | |
| 42 | - if ($config->getEmailConfirmationEnabled()) { |
|
| 43 | - $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 44 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 45 | - } |
|
| 46 | - else { |
|
| 47 | - $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 48 | - $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 49 | - } |
|
| 42 | + if ($config->getEmailConfirmationEnabled()) { |
|
| 43 | + $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 44 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
|
| 45 | + } |
|
| 46 | + else { |
|
| 47 | + $query = "SELECT * FROM request WHERE status = :type;"; |
|
| 48 | + $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $statement = $database->prepare($query); |
|
| 52 | - $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 51 | + $statement = $database->prepare($query); |
|
| 52 | + $totalRequestsStatement = $database->prepare($totalQuery); |
|
| 53 | 53 | |
| 54 | - $statement->bindValue(":type", $requestedStatus); |
|
| 55 | - $statement->execute(); |
|
| 54 | + $statement->bindValue(":type", $requestedStatus); |
|
| 55 | + $statement->execute(); |
|
| 56 | 56 | |
| 57 | - $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 57 | + $requests = $statement->fetchAll(PDO::FETCH_CLASS, Request::class); |
|
| 58 | 58 | |
| 59 | - /** @var Request $req */ |
|
| 60 | - foreach ($requests as $req) { |
|
| 61 | - $req->setDatabase($database); |
|
| 62 | - } |
|
| 59 | + /** @var Request $req */ |
|
| 60 | + foreach ($requests as $req) { |
|
| 61 | + $req->setDatabase($database); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - $this->assign('requests', $this->prepareRequestData($requests)); |
|
| 65 | - $this->assign('header', $requestedStatus); |
|
| 66 | - $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 67 | - $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 64 | + $this->assign('requests', $this->prepareRequestData($requests)); |
|
| 65 | + $this->assign('header', $requestedStatus); |
|
| 66 | + $this->assign('requestLimitShowOnly', $config->getMiserModeLimit()); |
|
| 67 | + $this->assign('defaultRequestState', $config->getDefaultRequestStateKey()); |
|
| 68 | 68 | |
| 69 | - $totalRequestsStatement->bindValue(':type', $requestedStatus); |
|
| 70 | - $totalRequestsStatement->execute(); |
|
| 71 | - $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 72 | - $totalRequestsStatement->closeCursor(); |
|
| 73 | - $this->assign('totalRequests', $totalRequests); |
|
| 69 | + $totalRequestsStatement->bindValue(':type', $requestedStatus); |
|
| 70 | + $totalRequestsStatement->execute(); |
|
| 71 | + $totalRequests = $totalRequestsStatement->fetchColumn(); |
|
| 72 | + $totalRequestsStatement->closeCursor(); |
|
| 73 | + $this->assign('totalRequests', $totalRequests); |
|
| 74 | 74 | |
| 75 | 75 | |
| 76 | - $this->setHtmlTitle('{$header|escape}{if $totalRequests > 0} [{$totalRequests|escape}]{/if}'); |
|
| 77 | - $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 78 | - } |
|
| 79 | - } |
|
| 76 | + $this->setHtmlTitle('{$header|escape}{if $totalRequests > 0} [{$totalRequests|escape}]{/if}'); |
|
| 77 | + $this->setTemplate('mainpage/expandedrequestlist.tpl'); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -42,8 +42,7 @@ |
||
| 42 | 42 | if ($config->getEmailConfirmationEnabled()) { |
| 43 | 43 | $query = "SELECT * FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
| 44 | 44 | $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type AND emailconfirm = 'Confirmed';"; |
| 45 | - } |
|
| 46 | - else { |
|
| 45 | + } else { |
|
| 47 | 46 | $query = "SELECT * FROM request WHERE status = :type;"; |
| 48 | 47 | $totalQuery = "SELECT COUNT(id) FROM request WHERE status = :type;"; |
| 49 | 48 | } |
@@ -19,81 +19,81 @@ |
||
| 19 | 19 | |
| 20 | 20 | class PageBreakReservation extends RequestActionBase |
| 21 | 21 | { |
| 22 | - protected function main() |
|
| 23 | - { |
|
| 24 | - $this->checkPosted(); |
|
| 25 | - $database = $this->getDatabase(); |
|
| 26 | - $request = $this->getRequest($database); |
|
| 22 | + protected function main() |
|
| 23 | + { |
|
| 24 | + $this->checkPosted(); |
|
| 25 | + $database = $this->getDatabase(); |
|
| 26 | + $request = $this->getRequest($database); |
|
| 27 | 27 | |
| 28 | - if ($request->getReserved() === null) { |
|
| 29 | - throw new ApplicationLogicException('Request is not reserved!'); |
|
| 30 | - } |
|
| 28 | + if ($request->getReserved() === null) { |
|
| 29 | + throw new ApplicationLogicException('Request is not reserved!'); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $currentUser = User::getCurrent($database); |
|
| 32 | + $currentUser = User::getCurrent($database); |
|
| 33 | 33 | |
| 34 | - if ($currentUser->getId() === $request->getReserved()) { |
|
| 35 | - $this->doUnreserve($request, $database); |
|
| 36 | - } |
|
| 37 | - else { |
|
| 38 | - // not the same user! |
|
| 39 | - if ($this->barrierTest('force', $currentUser)) { |
|
| 40 | - $this->doBreakReserve($request, $database); |
|
| 41 | - } |
|
| 42 | - else { |
|
| 43 | - throw new AccessDeniedException($this->getSecurityManager()); |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 34 | + if ($currentUser->getId() === $request->getReserved()) { |
|
| 35 | + $this->doUnreserve($request, $database); |
|
| 36 | + } |
|
| 37 | + else { |
|
| 38 | + // not the same user! |
|
| 39 | + if ($this->barrierTest('force', $currentUser)) { |
|
| 40 | + $this->doBreakReserve($request, $database); |
|
| 41 | + } |
|
| 42 | + else { |
|
| 43 | + throw new AccessDeniedException($this->getSecurityManager()); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @param Request $request |
|
| 50 | - * @param PdoDatabase $database |
|
| 51 | - * |
|
| 52 | - * @throws Exception |
|
| 53 | - */ |
|
| 54 | - protected function doUnreserve(Request $request, PdoDatabase $database) |
|
| 55 | - { |
|
| 56 | - // same user! we allow people to unreserve their own stuff |
|
| 57 | - $request->setReserved(null); |
|
| 58 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 59 | - $request->save(); |
|
| 48 | + /** |
|
| 49 | + * @param Request $request |
|
| 50 | + * @param PdoDatabase $database |
|
| 51 | + * |
|
| 52 | + * @throws Exception |
|
| 53 | + */ |
|
| 54 | + protected function doUnreserve(Request $request, PdoDatabase $database) |
|
| 55 | + { |
|
| 56 | + // same user! we allow people to unreserve their own stuff |
|
| 57 | + $request->setReserved(null); |
|
| 58 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 59 | + $request->save(); |
|
| 60 | 60 | |
| 61 | - Logger::unreserve($database, $request); |
|
| 62 | - $this->getNotificationHelper()->requestUnreserved($request); |
|
| 61 | + Logger::unreserve($database, $request); |
|
| 62 | + $this->getNotificationHelper()->requestUnreserved($request); |
|
| 63 | 63 | |
| 64 | - // Redirect home! |
|
| 65 | - $this->redirect(); |
|
| 66 | - } |
|
| 64 | + // Redirect home! |
|
| 65 | + $this->redirect(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @param Request $request |
|
| 70 | - * @param PdoDatabase $database |
|
| 71 | - * |
|
| 72 | - * @throws Exception |
|
| 73 | - */ |
|
| 74 | - protected function doBreakReserve(Request $request, PdoDatabase $database) |
|
| 75 | - { |
|
| 76 | - if (!WebRequest::postBoolean("confirm")) { |
|
| 77 | - $this->assignCSRFToken(); |
|
| 68 | + /** |
|
| 69 | + * @param Request $request |
|
| 70 | + * @param PdoDatabase $database |
|
| 71 | + * |
|
| 72 | + * @throws Exception |
|
| 73 | + */ |
|
| 74 | + protected function doBreakReserve(Request $request, PdoDatabase $database) |
|
| 75 | + { |
|
| 76 | + if (!WebRequest::postBoolean("confirm")) { |
|
| 77 | + $this->assignCSRFToken(); |
|
| 78 | 78 | |
| 79 | - $this->assign("request", $request->getId()); |
|
| 80 | - $this->assign("reservedUser", User::getById($request->getReserved(), $database)); |
|
| 81 | - $this->assign("updateversion", WebRequest::postInt('updateversion')); |
|
| 79 | + $this->assign("request", $request->getId()); |
|
| 80 | + $this->assign("reservedUser", User::getById($request->getReserved(), $database)); |
|
| 81 | + $this->assign("updateversion", WebRequest::postInt('updateversion')); |
|
| 82 | 82 | |
| 83 | - $this->skipAlerts(); |
|
| 83 | + $this->skipAlerts(); |
|
| 84 | 84 | |
| 85 | - $this->setTemplate("confirmations/breakreserve.tpl"); |
|
| 86 | - } |
|
| 87 | - else { |
|
| 88 | - $request->setReserved(null); |
|
| 89 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 90 | - $request->save(); |
|
| 85 | + $this->setTemplate("confirmations/breakreserve.tpl"); |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + $request->setReserved(null); |
|
| 89 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
| 90 | + $request->save(); |
|
| 91 | 91 | |
| 92 | - Logger::breakReserve($database, $request); |
|
| 93 | - $this->getNotificationHelper()->requestReserveBroken($request); |
|
| 92 | + Logger::breakReserve($database, $request); |
|
| 93 | + $this->getNotificationHelper()->requestReserveBroken($request); |
|
| 94 | 94 | |
| 95 | - // Redirect home! |
|
| 96 | - $this->redirect(); |
|
| 97 | - } |
|
| 98 | - } |
|
| 95 | + // Redirect home! |
|
| 96 | + $this->redirect(); |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -33,13 +33,11 @@ discard block |
||
| 33 | 33 | |
| 34 | 34 | if ($currentUser->getId() === $request->getReserved()) { |
| 35 | 35 | $this->doUnreserve($request, $database); |
| 36 | - } |
|
| 37 | - else { |
|
| 36 | + } else { |
|
| 38 | 37 | // not the same user! |
| 39 | 38 | if ($this->barrierTest('force', $currentUser)) { |
| 40 | 39 | $this->doBreakReserve($request, $database); |
| 41 | - } |
|
| 42 | - else { |
|
| 40 | + } else { |
|
| 43 | 41 | throw new AccessDeniedException($this->getSecurityManager()); |
| 44 | 42 | } |
| 45 | 43 | } |
@@ -83,8 +81,7 @@ discard block |
||
| 83 | 81 | $this->skipAlerts(); |
| 84 | 82 | |
| 85 | 83 | $this->setTemplate("confirmations/breakreserve.tpl"); |
| 86 | - } |
|
| 87 | - else { |
|
| 84 | + } else { |
|
| 88 | 85 | $request->setReserved(null); |
| 89 | 86 | $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
| 90 | 87 | $request->save(); |
@@ -19,54 +19,54 @@ |
||
| 19 | 19 | |
| 20 | 20 | abstract class RequestActionBase extends InternalPageBase |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * @param PdoDatabase $database |
|
| 24 | - * |
|
| 25 | - * @return Request |
|
| 26 | - * @throws ApplicationLogicException |
|
| 27 | - */ |
|
| 28 | - protected function getRequest(PdoDatabase $database) |
|
| 29 | - { |
|
| 30 | - $requestId = WebRequest::postInt('request'); |
|
| 31 | - if ($requestId === null) { |
|
| 32 | - throw new ApplicationLogicException('Request ID not found'); |
|
| 33 | - } |
|
| 22 | + /** |
|
| 23 | + * @param PdoDatabase $database |
|
| 24 | + * |
|
| 25 | + * @return Request |
|
| 26 | + * @throws ApplicationLogicException |
|
| 27 | + */ |
|
| 28 | + protected function getRequest(PdoDatabase $database) |
|
| 29 | + { |
|
| 30 | + $requestId = WebRequest::postInt('request'); |
|
| 31 | + if ($requestId === null) { |
|
| 32 | + throw new ApplicationLogicException('Request ID not found'); |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** @var Request $request */ |
|
| 36 | - $request = Request::getById($requestId, $database); |
|
| 35 | + /** @var Request $request */ |
|
| 36 | + $request = Request::getById($requestId, $database); |
|
| 37 | 37 | |
| 38 | - if ($request === false) { |
|
| 39 | - throw new ApplicationLogicException('Request not found'); |
|
| 40 | - } |
|
| 38 | + if ($request === false) { |
|
| 39 | + throw new ApplicationLogicException('Request not found'); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - return $request; |
|
| 43 | - } |
|
| 42 | + return $request; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - final protected function checkPosted() |
|
| 46 | - { |
|
| 47 | - // if the request was not posted, send the user away. |
|
| 48 | - if (!WebRequest::wasPosted()) { |
|
| 49 | - throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 50 | - } |
|
| 45 | + final protected function checkPosted() |
|
| 46 | + { |
|
| 47 | + // if the request was not posted, send the user away. |
|
| 48 | + if (!WebRequest::wasPosted()) { |
|
| 49 | + throw new ApplicationLogicException('This page does not support GET methods.'); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - // validate the CSRF token |
|
| 53 | - $this->validateCSRFToken(); |
|
| 54 | - } |
|
| 52 | + // validate the CSRF token |
|
| 53 | + $this->validateCSRFToken(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param Request $request |
|
| 58 | - * @param $parentTaskId |
|
| 59 | - * @param User $user |
|
| 60 | - * @param PdoDatabase $database |
|
| 61 | - */ |
|
| 62 | - protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database) |
|
| 63 | - { |
|
| 64 | - $welcomeTask = new JobQueue(); |
|
| 65 | - $welcomeTask->setTask(WelcomeUserTask::class); |
|
| 66 | - $welcomeTask->setRequest($request->getId()); |
|
| 67 | - $welcomeTask->setParent($parentTaskId); |
|
| 68 | - $welcomeTask->setTriggerUserId($user->getId()); |
|
| 69 | - $welcomeTask->setDatabase($database); |
|
| 70 | - $welcomeTask->save(); |
|
| 71 | - } |
|
| 56 | + /** |
|
| 57 | + * @param Request $request |
|
| 58 | + * @param $parentTaskId |
|
| 59 | + * @param User $user |
|
| 60 | + * @param PdoDatabase $database |
|
| 61 | + */ |
|
| 62 | + protected function enqueueWelcomeTask(Request $request, $parentTaskId, User $user, PdoDatabase $database) |
|
| 63 | + { |
|
| 64 | + $welcomeTask = new JobQueue(); |
|
| 65 | + $welcomeTask->setTask(WelcomeUserTask::class); |
|
| 66 | + $welcomeTask->setRequest($request->getId()); |
|
| 67 | + $welcomeTask->setParent($parentTaskId); |
|
| 68 | + $welcomeTask->setTriggerUserId($user->getId()); |
|
| 69 | + $welcomeTask->setDatabase($database); |
|
| 70 | + $welcomeTask->save(); |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | \ No newline at end of file |
@@ -15,52 +15,52 @@ |
||
| 15 | 15 | |
| 16 | 16 | class PageComment extends RequestActionBase |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Main function for this page, when no specific actions are called. |
|
| 20 | - * @return void |
|
| 21 | - */ |
|
| 22 | - protected function main() |
|
| 23 | - { |
|
| 24 | - $this->checkPosted(); |
|
| 25 | - $database = $this->getDatabase(); |
|
| 26 | - $request = $this->getRequest($database); |
|
| 18 | + /** |
|
| 19 | + * Main function for this page, when no specific actions are called. |
|
| 20 | + * @return void |
|
| 21 | + */ |
|
| 22 | + protected function main() |
|
| 23 | + { |
|
| 24 | + $this->checkPosted(); |
|
| 25 | + $database = $this->getDatabase(); |
|
| 26 | + $request = $this->getRequest($database); |
|
| 27 | 27 | |
| 28 | - $commentText = WebRequest::postString('comment'); |
|
| 29 | - if ($commentText === false || $commentText == '') { |
|
| 30 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 28 | + $commentText = WebRequest::postString('comment'); |
|
| 29 | + if ($commentText === false || $commentText == '') { |
|
| 30 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 31 | 31 | |
| 32 | - return; |
|
| 33 | - } |
|
| 32 | + return; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
| 36 | - $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
| 37 | - $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
| 35 | + //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
| 36 | + $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
| 37 | + $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
| 38 | 38 | |
| 39 | - $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
| 39 | + $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
| 40 | 40 | |
| 41 | - if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
| 42 | - $this->assignCSRFToken(); |
|
| 43 | - $this->assign("request", $request); |
|
| 44 | - $this->assign("comment", $commentText); |
|
| 45 | - $this->skipAlerts(); |
|
| 46 | - $this->setTemplate("privpol-warning.tpl"); |
|
| 41 | + if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
| 42 | + $this->assignCSRFToken(); |
|
| 43 | + $this->assign("request", $request); |
|
| 44 | + $this->assign("comment", $commentText); |
|
| 45 | + $this->skipAlerts(); |
|
| 46 | + $this->setTemplate("privpol-warning.tpl"); |
|
| 47 | 47 | |
| 48 | - return; |
|
| 49 | - } |
|
| 48 | + return; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user'; |
|
| 51 | + $visibility = WebRequest::postBoolean('adminOnly') ? 'admin' : 'user'; |
|
| 52 | 52 | |
| 53 | - $comment = new Comment(); |
|
| 54 | - $comment->setDatabase($database); |
|
| 53 | + $comment = new Comment(); |
|
| 54 | + $comment->setDatabase($database); |
|
| 55 | 55 | |
| 56 | - $comment->setRequest($request->getId()); |
|
| 57 | - $comment->setVisibility($visibility); |
|
| 58 | - $comment->setUser(User::getCurrent($database)->getId()); |
|
| 59 | - $comment->setComment($commentText); |
|
| 56 | + $comment->setRequest($request->getId()); |
|
| 57 | + $comment->setVisibility($visibility); |
|
| 58 | + $comment->setUser(User::getCurrent($database)->getId()); |
|
| 59 | + $comment->setComment($commentText); |
|
| 60 | 60 | |
| 61 | - $comment->save(); |
|
| 61 | + $comment->save(); |
|
| 62 | 62 | |
| 63 | - $this->getNotificationHelper()->commentCreated($comment, $request); |
|
| 64 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 65 | - } |
|
| 63 | + $this->getNotificationHelper()->commentCreated($comment, $request); |
|
| 64 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
| 65 | + } |
|
| 66 | 66 | } |
@@ -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 | } |
@@ -133,7 +133,7 @@ |
||
| 133 | 133 | if ($reservationId !== 0 && $reservationId !== null) { |
| 134 | 134 | if ($currentUser->getId() !== $reservationId) { |
| 135 | 135 | SessionAlert::error("Request is reserved by someone else."); |
| 136 | - $this->redirect('/viewRequest', null, ['id' => $request->getId()] ); |
|
| 136 | + $this->redirect('/viewRequest', null, ['id' => $request->getId()]); |
|
| 137 | 137 | return true; |
| 138 | 138 | } |
| 139 | 139 | } |
@@ -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 | } |
@@ -55,8 +55,7 @@ |
||
| 55 | 55 | && $creationMode === 'bot' |
| 56 | 56 | ) { |
| 57 | 57 | throw new AccessDeniedException($secMgr); |
| 58 | - } |
|
| 59 | - elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED |
|
| 58 | + } elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED |
|
| 60 | 59 | && $creationMode === 'oauth' |
| 61 | 60 | ) { |
| 62 | 61 | throw new AccessDeniedException($secMgr); |