@@ -14,22 +14,22 @@ |
||
14 | 14 | |
15 | 15 | class PageLogout extends InternalPageBase |
16 | 16 | { |
17 | - /** |
|
18 | - * Main function for this page, when no specific actions are called. |
|
19 | - */ |
|
20 | - protected function main() |
|
21 | - { |
|
22 | - if (WebRequest::wasPosted()) { |
|
23 | - Session::destroy(); |
|
24 | - $this->redirect("login"); |
|
25 | - return; |
|
26 | - } |
|
17 | + /** |
|
18 | + * Main function for this page, when no specific actions are called. |
|
19 | + */ |
|
20 | + protected function main() |
|
21 | + { |
|
22 | + if (WebRequest::wasPosted()) { |
|
23 | + Session::destroy(); |
|
24 | + $this->redirect("login"); |
|
25 | + return; |
|
26 | + } |
|
27 | 27 | |
28 | - $this->redirect(); |
|
29 | - } |
|
28 | + $this->redirect(); |
|
29 | + } |
|
30 | 30 | |
31 | - protected function isProtectedPage() |
|
32 | - { |
|
33 | - return false; |
|
34 | - } |
|
31 | + protected function isProtectedPage() |
|
32 | + { |
|
33 | + return false; |
|
34 | + } |
|
35 | 35 | } |
@@ -22,81 +22,81 @@ |
||
22 | 22 | |
23 | 23 | class PageOAuth extends InternalPageBase |
24 | 24 | { |
25 | - /** |
|
26 | - * Attach entry point |
|
27 | - * |
|
28 | - * must be posted, or will redirect to preferences |
|
29 | - */ |
|
30 | - protected function attach() |
|
31 | - { |
|
32 | - if (!WebRequest::wasPosted()) { |
|
33 | - $this->redirect('preferences'); |
|
34 | - |
|
35 | - return; |
|
36 | - } |
|
37 | - |
|
38 | - $database = $this->getDatabase(); |
|
39 | - |
|
40 | - $this->validateCSRFToken(); |
|
41 | - |
|
42 | - $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
43 | - $user = User::getCurrent($database); |
|
44 | - $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
45 | - |
|
46 | - try { |
|
47 | - $authoriseUrl = $oauth->getRequestToken(); |
|
48 | - $this->redirectUrl($authoriseUrl); |
|
49 | - } |
|
50 | - catch (CurlException $ex) { |
|
51 | - throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Detach account entry point |
|
57 | - * @throws Exception |
|
58 | - */ |
|
59 | - protected function detach() |
|
60 | - { |
|
61 | - if ($this->getSiteConfiguration()->getEnforceOAuth()) { |
|
62 | - throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
63 | - } |
|
64 | - |
|
65 | - $database = $this->getDatabase(); |
|
66 | - $user = User::getCurrent($database); |
|
67 | - $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
68 | - |
|
69 | - try { |
|
70 | - $oauth->refreshIdentity(); |
|
71 | - } |
|
72 | - catch (CurlException $ex) { |
|
73 | - // do nothing. The user's already revoked this access anyway. |
|
74 | - } |
|
75 | - catch (OAuthException $ex) { |
|
76 | - // do nothing. The user's already revoked this access anyway. |
|
77 | - } |
|
78 | - catch (OptimisticLockFailedException $e) { |
|
79 | - // do nothing. The user's already revoked this access anyway. |
|
80 | - } |
|
81 | - |
|
82 | - $oauth->detach(); |
|
83 | - |
|
84 | - // TODO: figure out why we need to force logout after a detach. |
|
85 | - $user->setForcelogout(true); |
|
86 | - $user->save(); |
|
87 | - |
|
88 | - // force the user to log out |
|
89 | - Session::destroy(); |
|
90 | - |
|
91 | - $this->redirect('login'); |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Main function for this page, when no specific actions are called. |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - protected function main() |
|
99 | - { |
|
100 | - $this->redirect('preferences'); |
|
101 | - } |
|
25 | + /** |
|
26 | + * Attach entry point |
|
27 | + * |
|
28 | + * must be posted, or will redirect to preferences |
|
29 | + */ |
|
30 | + protected function attach() |
|
31 | + { |
|
32 | + if (!WebRequest::wasPosted()) { |
|
33 | + $this->redirect('preferences'); |
|
34 | + |
|
35 | + return; |
|
36 | + } |
|
37 | + |
|
38 | + $database = $this->getDatabase(); |
|
39 | + |
|
40 | + $this->validateCSRFToken(); |
|
41 | + |
|
42 | + $oauthProtocolHelper = $this->getOAuthProtocolHelper(); |
|
43 | + $user = User::getCurrent($database); |
|
44 | + $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration()); |
|
45 | + |
|
46 | + try { |
|
47 | + $authoriseUrl = $oauth->getRequestToken(); |
|
48 | + $this->redirectUrl($authoriseUrl); |
|
49 | + } |
|
50 | + catch (CurlException $ex) { |
|
51 | + throw new ApplicationLogicException($ex->getMessage(), 0, $ex); |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Detach account entry point |
|
57 | + * @throws Exception |
|
58 | + */ |
|
59 | + protected function detach() |
|
60 | + { |
|
61 | + if ($this->getSiteConfiguration()->getEnforceOAuth()) { |
|
62 | + throw new AccessDeniedException($this->getSecurityManager(), $this->getDomainAccessManager()); |
|
63 | + } |
|
64 | + |
|
65 | + $database = $this->getDatabase(); |
|
66 | + $user = User::getCurrent($database); |
|
67 | + $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
68 | + |
|
69 | + try { |
|
70 | + $oauth->refreshIdentity(); |
|
71 | + } |
|
72 | + catch (CurlException $ex) { |
|
73 | + // do nothing. The user's already revoked this access anyway. |
|
74 | + } |
|
75 | + catch (OAuthException $ex) { |
|
76 | + // do nothing. The user's already revoked this access anyway. |
|
77 | + } |
|
78 | + catch (OptimisticLockFailedException $e) { |
|
79 | + // do nothing. The user's already revoked this access anyway. |
|
80 | + } |
|
81 | + |
|
82 | + $oauth->detach(); |
|
83 | + |
|
84 | + // TODO: figure out why we need to force logout after a detach. |
|
85 | + $user->setForcelogout(true); |
|
86 | + $user->save(); |
|
87 | + |
|
88 | + // force the user to log out |
|
89 | + Session::destroy(); |
|
90 | + |
|
91 | + $this->redirect('login'); |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Main function for this page, when no specific actions are called. |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + protected function main() |
|
99 | + { |
|
100 | + $this->redirect('preferences'); |
|
101 | + } |
|
102 | 102 | } |
@@ -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(), $this->getDomainAccessManager()); |
|
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(), $this->getDomainAccessManager()); |
|
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(), $this->getDomainAccessManager()); |
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(); |
@@ -18,58 +18,58 @@ |
||
18 | 18 | |
19 | 19 | class PageReservation extends RequestActionBase |
20 | 20 | { |
21 | - /** |
|
22 | - * Main function for this page, when no specific actions are called. |
|
23 | - * @throws ApplicationLogicException |
|
24 | - */ |
|
25 | - protected function main() |
|
26 | - { |
|
27 | - $this->checkPosted(); |
|
28 | - $database = $this->getDatabase(); |
|
29 | - $request = $this->getRequest($database); |
|
21 | + /** |
|
22 | + * Main function for this page, when no specific actions are called. |
|
23 | + * @throws ApplicationLogicException |
|
24 | + */ |
|
25 | + protected function main() |
|
26 | + { |
|
27 | + $this->checkPosted(); |
|
28 | + $database = $this->getDatabase(); |
|
29 | + $request = $this->getRequest($database); |
|
30 | 30 | |
31 | - $closureDate = $request->getClosureDate(); |
|
31 | + $closureDate = $request->getClosureDate(); |
|
32 | 32 | |
33 | - $date = new DateTime(); |
|
34 | - $date->modify("-7 days"); |
|
35 | - $oneweek = $date->format("Y-m-d H:i:s"); |
|
33 | + $date = new DateTime(); |
|
34 | + $date->modify("-7 days"); |
|
35 | + $oneweek = $date->format("Y-m-d H:i:s"); |
|
36 | 36 | |
37 | - $currentUser = User::getCurrent($database); |
|
38 | - if ($request->getStatus() == RequestStatus::CLOSED && $closureDate < $oneweek) { |
|
39 | - if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
40 | - throw new ApplicationLogicException( |
|
41 | - "You are not allowed to reserve a request that has been closed for over a week."); |
|
42 | - } |
|
43 | - } |
|
37 | + $currentUser = User::getCurrent($database); |
|
38 | + if ($request->getStatus() == RequestStatus::CLOSED && $closureDate < $oneweek) { |
|
39 | + if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
40 | + throw new ApplicationLogicException( |
|
41 | + "You are not allowed to reserve a request that has been closed for over a week."); |
|
42 | + } |
|
43 | + } |
|
44 | 44 | |
45 | - if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) { |
|
46 | - throw new ApplicationLogicException("Request is already reserved!"); |
|
47 | - } |
|
45 | + if ($request->getReserved() !== null && $request->getReserved() != $currentUser->getId()) { |
|
46 | + throw new ApplicationLogicException("Request is already reserved!"); |
|
47 | + } |
|
48 | 48 | |
49 | - if ($request->getReserved() === null) { |
|
50 | - // Check the number of requests a user has reserved already |
|
51 | - $doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;"); |
|
52 | - $doubleReserveCountQuery->bindValue(":userid", $currentUser->getId()); |
|
53 | - $doubleReserveCountQuery->execute(); |
|
54 | - $doubleReserveCount = $doubleReserveCountQuery->fetchColumn(); |
|
55 | - $doubleReserveCountQuery->closeCursor(); |
|
49 | + if ($request->getReserved() === null) { |
|
50 | + // Check the number of requests a user has reserved already |
|
51 | + $doubleReserveCountQuery = $database->prepare("SELECT COUNT(*) FROM request WHERE reserved = :userid;"); |
|
52 | + $doubleReserveCountQuery->bindValue(":userid", $currentUser->getId()); |
|
53 | + $doubleReserveCountQuery->execute(); |
|
54 | + $doubleReserveCount = $doubleReserveCountQuery->fetchColumn(); |
|
55 | + $doubleReserveCountQuery->closeCursor(); |
|
56 | 56 | |
57 | - // User already has at least one reserved. |
|
58 | - if ($doubleReserveCount != 0) { |
|
59 | - SessionAlert::warning("You have multiple requests reserved!"); |
|
60 | - } |
|
57 | + // User already has at least one reserved. |
|
58 | + if ($doubleReserveCount != 0) { |
|
59 | + SessionAlert::warning("You have multiple requests reserved!"); |
|
60 | + } |
|
61 | 61 | |
62 | - $request->setReserved($currentUser->getId()); |
|
63 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
64 | - $request->save(); |
|
62 | + $request->setReserved($currentUser->getId()); |
|
63 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
64 | + $request->save(); |
|
65 | 65 | |
66 | - Logger::reserve($database, $request); |
|
66 | + Logger::reserve($database, $request); |
|
67 | 67 | |
68 | - $this->getNotificationHelper()->requestReserved($request); |
|
68 | + $this->getNotificationHelper()->requestReserved($request); |
|
69 | 69 | |
70 | - SessionAlert::success("Reserved request {$request->getId()}."); |
|
71 | - } |
|
70 | + SessionAlert::success("Reserved request {$request->getId()}."); |
|
71 | + } |
|
72 | 72 | |
73 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
74 | - } |
|
73 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
74 | + } |
|
75 | 75 | } |
@@ -15,39 +15,39 @@ |
||
15 | 15 | |
16 | 16 | class PageManuallyConfirm extends RequestActionBase |
17 | 17 | { |
18 | - /** |
|
19 | - * This endpoint manually confirms a request, bypassing email confirmation. |
|
20 | - * |
|
21 | - * Only administrators are allowed to do this, for obvious reasons. |
|
22 | - * |
|
23 | - * @throws ApplicationLogicException|OptimisticLockFailedException |
|
24 | - */ |
|
25 | - protected function main() |
|
26 | - { |
|
27 | - // This method throws an error if we don't post |
|
28 | - $this->checkPosted(); |
|
29 | - |
|
30 | - // Retrieve the database. |
|
31 | - $database = $this->getDatabase(); |
|
32 | - |
|
33 | - // Find the request |
|
34 | - // This method throws exceptions if there is an error with the request. |
|
35 | - $request = $this->getRequest($database); |
|
36 | - $version = WebRequest::postInt('version'); |
|
37 | - |
|
38 | - $request->setUpdateVersion($version); |
|
39 | - |
|
40 | - // Mark the request as confirmed. |
|
41 | - $request->setEmailConfirm("Confirmed"); |
|
42 | - $request->save(); |
|
43 | - |
|
44 | - // Log that the request was manually confirmed |
|
45 | - Logger::manuallyConfirmRequest($database, $request); |
|
46 | - |
|
47 | - // Notify the IRC channel |
|
48 | - $this->getNotificationHelper()->requestReceived($request); |
|
49 | - |
|
50 | - // Redirect back to the main request, now it should show the request. |
|
51 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
52 | - } |
|
18 | + /** |
|
19 | + * This endpoint manually confirms a request, bypassing email confirmation. |
|
20 | + * |
|
21 | + * Only administrators are allowed to do this, for obvious reasons. |
|
22 | + * |
|
23 | + * @throws ApplicationLogicException|OptimisticLockFailedException |
|
24 | + */ |
|
25 | + protected function main() |
|
26 | + { |
|
27 | + // This method throws an error if we don't post |
|
28 | + $this->checkPosted(); |
|
29 | + |
|
30 | + // Retrieve the database. |
|
31 | + $database = $this->getDatabase(); |
|
32 | + |
|
33 | + // Find the request |
|
34 | + // This method throws exceptions if there is an error with the request. |
|
35 | + $request = $this->getRequest($database); |
|
36 | + $version = WebRequest::postInt('version'); |
|
37 | + |
|
38 | + $request->setUpdateVersion($version); |
|
39 | + |
|
40 | + // Mark the request as confirmed. |
|
41 | + $request->setEmailConfirm("Confirmed"); |
|
42 | + $request->save(); |
|
43 | + |
|
44 | + // Log that the request was manually confirmed |
|
45 | + Logger::manuallyConfirmRequest($database, $request); |
|
46 | + |
|
47 | + // Notify the IRC channel |
|
48 | + $this->getNotificationHelper()->requestReceived($request); |
|
49 | + |
|
50 | + // Redirect back to the main request, now it should show the request. |
|
51 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
52 | + } |
|
53 | 53 | } |
@@ -25,248 +25,248 @@ |
||
25 | 25 | |
26 | 26 | class PageCloseRequest extends RequestActionBase |
27 | 27 | { |
28 | - protected function main() |
|
29 | - { |
|
30 | - $this->processClose(); |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Main function for this page, when no specific actions are called. |
|
35 | - * @throws ApplicationLogicException |
|
36 | - */ |
|
37 | - final protected function processClose() |
|
38 | - { |
|
39 | - $this->checkPosted(); |
|
40 | - $database = $this->getDatabase(); |
|
41 | - |
|
42 | - $currentUser = User::getCurrent($database); |
|
43 | - $template = $this->getTemplate($database); |
|
44 | - $request = $this->getRequest($database); |
|
45 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
46 | - |
|
47 | - if ($request->getStatus() === RequestStatus::CLOSED) { |
|
48 | - throw new ApplicationLogicException('Request is already closed'); |
|
49 | - } |
|
50 | - |
|
51 | - if ($this->confirmEmailAlreadySent($request, $template)) { |
|
52 | - return; |
|
53 | - } |
|
54 | - |
|
55 | - if ($this->checkReserveProtect($request, $currentUser)) { |
|
56 | - return; |
|
57 | - } |
|
58 | - |
|
59 | - if ($this->confirmAccountCreated($request, $template)) { |
|
60 | - return; |
|
61 | - } |
|
62 | - |
|
63 | - // I think we're good here... |
|
64 | - $request->setStatus(RequestStatus::CLOSED); |
|
65 | - $request->setQueue(null); |
|
66 | - $request->setReserved(null); |
|
67 | - |
|
68 | - Logger::closeRequest($database, $request, $template->getId(), null); |
|
69 | - |
|
70 | - $request->save(); |
|
71 | - |
|
72 | - $this->processWelcome($template->getDefaultAction(), null); |
|
73 | - |
|
74 | - // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
75 | - // be rolled back. |
|
76 | - |
|
77 | - $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
78 | - $sanitisedTemplateName = htmlentities($template->getName(), ENT_COMPAT, 'UTF-8'); |
|
79 | - SessionAlert::success("Request {$request->getId()} has been closed as {$sanitisedTemplateName}"); |
|
80 | - |
|
81 | - $this->sendMail($request, $template->getText(), $currentUser, false); |
|
82 | - |
|
83 | - $this->redirect(); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param PdoDatabase $database |
|
88 | - * |
|
89 | - * @return EmailTemplate |
|
90 | - * @throws ApplicationLogicException |
|
91 | - */ |
|
92 | - protected function getTemplate(PdoDatabase $database) |
|
93 | - { |
|
94 | - $templateId = WebRequest::postInt('template'); |
|
95 | - if ($templateId === null) { |
|
96 | - throw new ApplicationLogicException('No template specified'); |
|
97 | - } |
|
98 | - |
|
99 | - /** @var EmailTemplate $template */ |
|
100 | - $template = EmailTemplate::getById($templateId, $database); |
|
101 | - if ($template === false || !$template->getActive()) { |
|
102 | - throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
103 | - } |
|
104 | - |
|
105 | - return $template; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @param Request $request |
|
110 | - * @param EmailTemplate $template |
|
111 | - * |
|
112 | - * @return bool |
|
113 | - */ |
|
114 | - protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
115 | - { |
|
116 | - if ($this->checkEmailAlreadySent($request)) { |
|
117 | - $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
118 | - |
|
119 | - return true; |
|
120 | - } |
|
121 | - |
|
122 | - return false; |
|
123 | - } |
|
124 | - |
|
125 | - protected function checkEmailAlreadySent(Request $request) |
|
126 | - { |
|
127 | - if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
128 | - return true; |
|
129 | - } |
|
130 | - |
|
131 | - return false; |
|
132 | - } |
|
133 | - |
|
134 | - protected function checkReserveProtect(Request $request, User $currentUser) |
|
135 | - { |
|
136 | - $reservationId = $request->getReserved(); |
|
137 | - |
|
138 | - if ($reservationId !== 0 && $reservationId !== null) { |
|
139 | - if ($currentUser->getId() !== $reservationId) { |
|
140 | - SessionAlert::error("Request is reserved by someone else."); |
|
141 | - $this->redirect('/viewRequest', null, ['id' => $request->getId()]); |
|
142 | - return true; |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - return false; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * @param Request $request |
|
151 | - * @param EmailTemplate $template |
|
152 | - * |
|
153 | - * @return bool |
|
154 | - * @throws Exception |
|
155 | - */ |
|
156 | - protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
157 | - { |
|
158 | - if ($template->getDefaultAction() === EmailTemplate::ACTION_CREATED && $this->checkAccountCreated($request)) { |
|
159 | - $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
160 | - |
|
161 | - return true; |
|
162 | - } |
|
163 | - |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - protected function checkAccountCreated(Request $request) |
|
168 | - { |
|
169 | - if (!WebRequest::postBoolean('createOverride')) { |
|
170 | - $parameters = array( |
|
171 | - 'action' => 'query', |
|
172 | - 'list' => 'users', |
|
173 | - 'format' => 'php', |
|
174 | - 'ususers' => $request->getName(), |
|
175 | - ); |
|
176 | - |
|
177 | - // FIXME: domains! |
|
178 | - /** @var Domain $domain */ |
|
179 | - $domain = Domain::getById(1, $this->getDatabase()); |
|
180 | - |
|
181 | - $content = $this->getHttpHelper()->get($domain->getWikiApiPath(), $parameters); |
|
182 | - |
|
183 | - $apiResult = unserialize($content); |
|
184 | - $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
185 | - |
|
186 | - if (!$exists) { |
|
187 | - return true; |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - return false; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * @param Request $request |
|
196 | - * @param string $mailText |
|
197 | - * @param User $currentUser |
|
198 | - * @param boolean $ccMailingList |
|
199 | - */ |
|
200 | - protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
201 | - { |
|
202 | - if ( |
|
203 | - ($request->getEmail() != $this->getSiteConfiguration()->getDataClearEmail()) && |
|
204 | - ($request->getIp() != $this->getSiteConfiguration()->getDataClearIp()) |
|
205 | - ) { |
|
206 | - $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
207 | - $requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList); |
|
208 | - |
|
209 | - $request->setEmailSent(true); |
|
210 | - $request->save(); |
|
211 | - } |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @param Request $request |
|
216 | - * @param EmailTemplate $template |
|
217 | - * @param string $templateName |
|
218 | - * |
|
219 | - * @throws Exception |
|
220 | - * @return void |
|
221 | - */ |
|
222 | - protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
223 | - { |
|
224 | - $this->assignCSRFToken(); |
|
225 | - |
|
226 | - $this->assign('request', $request->getId()); |
|
227 | - $this->assign('template', $template->getId()); |
|
228 | - |
|
229 | - $this->assign('updateversion', $request->getUpdateVersion()); |
|
230 | - |
|
231 | - $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
232 | - $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
233 | - $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
234 | - $this->assign('skipAutoWelcome', WebRequest::postBoolean('skipAutoWelcome') ? 'true' : 'false'); |
|
235 | - |
|
236 | - $this->skipAlerts(); |
|
237 | - |
|
238 | - $this->setTemplate($templateName); |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * @param string $action |
|
243 | - * @param int|null $parentTaskId |
|
244 | - * |
|
245 | - * @throws ApplicationLogicException |
|
246 | - */ |
|
247 | - final protected function processWelcome(string $action, ?int $parentTaskId): void |
|
248 | - { |
|
249 | - $database = $this->getDatabase(); |
|
250 | - $currentUser = User::getCurrent($database); |
|
251 | - $preferencesManager = PreferenceManager::getForCurrent($database); |
|
252 | - |
|
253 | - if ($action !== EmailTemplate::ACTION_CREATED) { |
|
254 | - return; |
|
255 | - } |
|
256 | - |
|
257 | - if ($preferencesManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE) === null) { |
|
258 | - return; |
|
259 | - } |
|
260 | - |
|
261 | - $oauth = new OAuthUserHelper($currentUser, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
262 | - if (!$oauth->canWelcome()) { |
|
263 | - return; |
|
264 | - } |
|
265 | - |
|
266 | - if (WebRequest::postBoolean('skipAutoWelcome')) { |
|
267 | - return; |
|
268 | - } |
|
269 | - |
|
270 | - $this->enqueueWelcomeTask($this->getRequest($database), $parentTaskId, $currentUser, $database); |
|
271 | - } |
|
28 | + protected function main() |
|
29 | + { |
|
30 | + $this->processClose(); |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Main function for this page, when no specific actions are called. |
|
35 | + * @throws ApplicationLogicException |
|
36 | + */ |
|
37 | + final protected function processClose() |
|
38 | + { |
|
39 | + $this->checkPosted(); |
|
40 | + $database = $this->getDatabase(); |
|
41 | + |
|
42 | + $currentUser = User::getCurrent($database); |
|
43 | + $template = $this->getTemplate($database); |
|
44 | + $request = $this->getRequest($database); |
|
45 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
46 | + |
|
47 | + if ($request->getStatus() === RequestStatus::CLOSED) { |
|
48 | + throw new ApplicationLogicException('Request is already closed'); |
|
49 | + } |
|
50 | + |
|
51 | + if ($this->confirmEmailAlreadySent($request, $template)) { |
|
52 | + return; |
|
53 | + } |
|
54 | + |
|
55 | + if ($this->checkReserveProtect($request, $currentUser)) { |
|
56 | + return; |
|
57 | + } |
|
58 | + |
|
59 | + if ($this->confirmAccountCreated($request, $template)) { |
|
60 | + return; |
|
61 | + } |
|
62 | + |
|
63 | + // I think we're good here... |
|
64 | + $request->setStatus(RequestStatus::CLOSED); |
|
65 | + $request->setQueue(null); |
|
66 | + $request->setReserved(null); |
|
67 | + |
|
68 | + Logger::closeRequest($database, $request, $template->getId(), null); |
|
69 | + |
|
70 | + $request->save(); |
|
71 | + |
|
72 | + $this->processWelcome($template->getDefaultAction(), null); |
|
73 | + |
|
74 | + // Perform the notifications and stuff *after* we've successfully saved, since the save can throw an OLE and |
|
75 | + // be rolled back. |
|
76 | + |
|
77 | + $this->getNotificationHelper()->requestClosed($request, $template->getName()); |
|
78 | + $sanitisedTemplateName = htmlentities($template->getName(), ENT_COMPAT, 'UTF-8'); |
|
79 | + SessionAlert::success("Request {$request->getId()} has been closed as {$sanitisedTemplateName}"); |
|
80 | + |
|
81 | + $this->sendMail($request, $template->getText(), $currentUser, false); |
|
82 | + |
|
83 | + $this->redirect(); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param PdoDatabase $database |
|
88 | + * |
|
89 | + * @return EmailTemplate |
|
90 | + * @throws ApplicationLogicException |
|
91 | + */ |
|
92 | + protected function getTemplate(PdoDatabase $database) |
|
93 | + { |
|
94 | + $templateId = WebRequest::postInt('template'); |
|
95 | + if ($templateId === null) { |
|
96 | + throw new ApplicationLogicException('No template specified'); |
|
97 | + } |
|
98 | + |
|
99 | + /** @var EmailTemplate $template */ |
|
100 | + $template = EmailTemplate::getById($templateId, $database); |
|
101 | + if ($template === false || !$template->getActive()) { |
|
102 | + throw new ApplicationLogicException('Invalid or inactive template specified'); |
|
103 | + } |
|
104 | + |
|
105 | + return $template; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @param Request $request |
|
110 | + * @param EmailTemplate $template |
|
111 | + * |
|
112 | + * @return bool |
|
113 | + */ |
|
114 | + protected function confirmEmailAlreadySent(Request $request, EmailTemplate $template) |
|
115 | + { |
|
116 | + if ($this->checkEmailAlreadySent($request)) { |
|
117 | + $this->showConfirmation($request, $template, 'close-confirmations/email-sent.tpl'); |
|
118 | + |
|
119 | + return true; |
|
120 | + } |
|
121 | + |
|
122 | + return false; |
|
123 | + } |
|
124 | + |
|
125 | + protected function checkEmailAlreadySent(Request $request) |
|
126 | + { |
|
127 | + if ($request->getEmailSent() && !WebRequest::postBoolean('emailSentOverride')) { |
|
128 | + return true; |
|
129 | + } |
|
130 | + |
|
131 | + return false; |
|
132 | + } |
|
133 | + |
|
134 | + protected function checkReserveProtect(Request $request, User $currentUser) |
|
135 | + { |
|
136 | + $reservationId = $request->getReserved(); |
|
137 | + |
|
138 | + if ($reservationId !== 0 && $reservationId !== null) { |
|
139 | + if ($currentUser->getId() !== $reservationId) { |
|
140 | + SessionAlert::error("Request is reserved by someone else."); |
|
141 | + $this->redirect('/viewRequest', null, ['id' => $request->getId()]); |
|
142 | + return true; |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + return false; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * @param Request $request |
|
151 | + * @param EmailTemplate $template |
|
152 | + * |
|
153 | + * @return bool |
|
154 | + * @throws Exception |
|
155 | + */ |
|
156 | + protected function confirmAccountCreated(Request $request, EmailTemplate $template) |
|
157 | + { |
|
158 | + if ($template->getDefaultAction() === EmailTemplate::ACTION_CREATED && $this->checkAccountCreated($request)) { |
|
159 | + $this->showConfirmation($request, $template, 'close-confirmations/account-created.tpl'); |
|
160 | + |
|
161 | + return true; |
|
162 | + } |
|
163 | + |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + protected function checkAccountCreated(Request $request) |
|
168 | + { |
|
169 | + if (!WebRequest::postBoolean('createOverride')) { |
|
170 | + $parameters = array( |
|
171 | + 'action' => 'query', |
|
172 | + 'list' => 'users', |
|
173 | + 'format' => 'php', |
|
174 | + 'ususers' => $request->getName(), |
|
175 | + ); |
|
176 | + |
|
177 | + // FIXME: domains! |
|
178 | + /** @var Domain $domain */ |
|
179 | + $domain = Domain::getById(1, $this->getDatabase()); |
|
180 | + |
|
181 | + $content = $this->getHttpHelper()->get($domain->getWikiApiPath(), $parameters); |
|
182 | + |
|
183 | + $apiResult = unserialize($content); |
|
184 | + $exists = !isset($apiResult['query']['users']['0']['missing']); |
|
185 | + |
|
186 | + if (!$exists) { |
|
187 | + return true; |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + return false; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * @param Request $request |
|
196 | + * @param string $mailText |
|
197 | + * @param User $currentUser |
|
198 | + * @param boolean $ccMailingList |
|
199 | + */ |
|
200 | + protected function sendMail(Request $request, $mailText, User $currentUser, $ccMailingList) |
|
201 | + { |
|
202 | + if ( |
|
203 | + ($request->getEmail() != $this->getSiteConfiguration()->getDataClearEmail()) && |
|
204 | + ($request->getIp() != $this->getSiteConfiguration()->getDataClearIp()) |
|
205 | + ) { |
|
206 | + $requestEmailHelper = new RequestEmailHelper($this->getEmailHelper()); |
|
207 | + $requestEmailHelper->sendMail($request, $mailText, $currentUser, $ccMailingList); |
|
208 | + |
|
209 | + $request->setEmailSent(true); |
|
210 | + $request->save(); |
|
211 | + } |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @param Request $request |
|
216 | + * @param EmailTemplate $template |
|
217 | + * @param string $templateName |
|
218 | + * |
|
219 | + * @throws Exception |
|
220 | + * @return void |
|
221 | + */ |
|
222 | + protected function showConfirmation(Request $request, EmailTemplate $template, $templateName) |
|
223 | + { |
|
224 | + $this->assignCSRFToken(); |
|
225 | + |
|
226 | + $this->assign('request', $request->getId()); |
|
227 | + $this->assign('template', $template->getId()); |
|
228 | + |
|
229 | + $this->assign('updateversion', $request->getUpdateVersion()); |
|
230 | + |
|
231 | + $this->assign('emailSentOverride', WebRequest::postBoolean('emailSentOverride') ? 'true' : 'false'); |
|
232 | + $this->assign('reserveOverride', WebRequest::postBoolean('reserveOverride') ? 'true' : 'false'); |
|
233 | + $this->assign('createOverride', WebRequest::postBoolean('createOverride') ? 'true' : 'false'); |
|
234 | + $this->assign('skipAutoWelcome', WebRequest::postBoolean('skipAutoWelcome') ? 'true' : 'false'); |
|
235 | + |
|
236 | + $this->skipAlerts(); |
|
237 | + |
|
238 | + $this->setTemplate($templateName); |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * @param string $action |
|
243 | + * @param int|null $parentTaskId |
|
244 | + * |
|
245 | + * @throws ApplicationLogicException |
|
246 | + */ |
|
247 | + final protected function processWelcome(string $action, ?int $parentTaskId): void |
|
248 | + { |
|
249 | + $database = $this->getDatabase(); |
|
250 | + $currentUser = User::getCurrent($database); |
|
251 | + $preferencesManager = PreferenceManager::getForCurrent($database); |
|
252 | + |
|
253 | + if ($action !== EmailTemplate::ACTION_CREATED) { |
|
254 | + return; |
|
255 | + } |
|
256 | + |
|
257 | + if ($preferencesManager->getPreference(PreferenceManager::PREF_WELCOMETEMPLATE) === null) { |
|
258 | + return; |
|
259 | + } |
|
260 | + |
|
261 | + $oauth = new OAuthUserHelper($currentUser, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration()); |
|
262 | + if (!$oauth->canWelcome()) { |
|
263 | + return; |
|
264 | + } |
|
265 | + |
|
266 | + if (WebRequest::postBoolean('skipAutoWelcome')) { |
|
267 | + return; |
|
268 | + } |
|
269 | + |
|
270 | + $this->enqueueWelcomeTask($this->getRequest($database), $parentTaskId, $currentUser, $database); |
|
271 | + } |
|
272 | 272 | } |
@@ -19,55 +19,55 @@ |
||
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->setDomain(1); // FIXME: domains! |
|
66 | - $welcomeTask->setTask(WelcomeUserTask::class); |
|
67 | - $welcomeTask->setRequest($request->getId()); |
|
68 | - $welcomeTask->setParent($parentTaskId); |
|
69 | - $welcomeTask->setTriggerUserId($user->getId()); |
|
70 | - $welcomeTask->setDatabase($database); |
|
71 | - $welcomeTask->save(); |
|
72 | - } |
|
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->setDomain(1); // FIXME: domains! |
|
66 | + $welcomeTask->setTask(WelcomeUserTask::class); |
|
67 | + $welcomeTask->setRequest($request->getId()); |
|
68 | + $welcomeTask->setParent($parentTaskId); |
|
69 | + $welcomeTask->setTriggerUserId($user->getId()); |
|
70 | + $welcomeTask->setDatabase($database); |
|
71 | + $welcomeTask->save(); |
|
72 | + } |
|
73 | 73 | } |
74 | 74 | \ No newline at end of file |
@@ -21,85 +21,85 @@ |
||
21 | 21 | |
22 | 22 | class PageDeferRequest extends RequestActionBase |
23 | 23 | { |
24 | - /** |
|
25 | - * Main function for this page, when no specific actions are called. |
|
26 | - * @throws ApplicationLogicException |
|
27 | - */ |
|
28 | - protected function main() |
|
29 | - { |
|
30 | - $this->checkPosted(); |
|
31 | - $database = $this->getDatabase(); |
|
32 | - $request = $this->getRequest($database); |
|
33 | - $currentUser = User::getCurrent($database); |
|
34 | - |
|
35 | - $target = WebRequest::postString('target'); |
|
36 | - |
|
37 | - // FIXME: domains! |
|
38 | - $requestQueue = RequestQueue::getByApiName($database, $target, 1); |
|
39 | - |
|
40 | - if ($requestQueue === false) { |
|
41 | - throw new ApplicationLogicException('Defer target not valid'); |
|
42 | - } |
|
43 | - |
|
44 | - if ($request->getQueue() == $requestQueue->getId() && $request->getStatus() == RequestStatus::OPEN) { |
|
45 | - SessionAlert::warning('This request is already in the specified queue.'); |
|
46 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
47 | - |
|
48 | - return; |
|
49 | - } |
|
50 | - |
|
51 | - $closureDate = $request->getClosureDate(); |
|
52 | - $date = new DateTime(); |
|
53 | - $date->modify("-7 days"); |
|
54 | - |
|
55 | - if ($request->getStatus() == RequestStatus::CLOSED && $closureDate < $date) { |
|
56 | - if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
57 | - throw new ApplicationLogicException( |
|
58 | - "You are not allowed to re-open a request that has been closed for over a week."); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
63 | - if (!$this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData')) { |
|
64 | - throw new ApplicationLogicException( |
|
65 | - "You are not allowed to re-open a request for which the private data has been purged."); |
|
66 | - } |
|
67 | - } |
|
68 | - |
|
69 | - if ($request->getStatus() === RequestStatus::JOBQUEUE) { |
|
70 | - /** @var JobQueue[] $pendingJobs */ |
|
71 | - // FIXME: domains |
|
72 | - $pendingJobs = JobQueueSearchHelper::get($database, 1) |
|
73 | - ->byRequest($request->getId()) |
|
74 | - ->statusIn([ |
|
75 | - JobQueue::STATUS_QUEUED, |
|
76 | - JobQueue::STATUS_READY, |
|
77 | - JobQueue::STATUS_WAITING, |
|
78 | - ]) |
|
79 | - ->fetch(); |
|
80 | - |
|
81 | - foreach ($pendingJobs as $job) { |
|
82 | - $job->setStatus(JobQueue::STATUS_CANCELLED); |
|
83 | - $job->setError('Cancelled by request deferral'); |
|
84 | - $job->save(); |
|
85 | - |
|
86 | - Logger::backgroundJobCancelled($database, $job); |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - $request->setReserved(null); |
|
91 | - $request->setStatus(RequestStatus::OPEN); |
|
92 | - $request->setQueue($requestQueue->getId()); |
|
93 | - $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
94 | - $request->save(); |
|
95 | - |
|
96 | - Logger::deferRequest($database, $request, $requestQueue->getLogName()); |
|
97 | - |
|
98 | - $this->getNotificationHelper()->requestDeferred($request); |
|
99 | - |
|
100 | - $deto = htmlentities($requestQueue->getDisplayName(), ENT_COMPAT, 'UTF-8'); |
|
101 | - SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
102 | - |
|
103 | - $this->redirect(); |
|
104 | - } |
|
24 | + /** |
|
25 | + * Main function for this page, when no specific actions are called. |
|
26 | + * @throws ApplicationLogicException |
|
27 | + */ |
|
28 | + protected function main() |
|
29 | + { |
|
30 | + $this->checkPosted(); |
|
31 | + $database = $this->getDatabase(); |
|
32 | + $request = $this->getRequest($database); |
|
33 | + $currentUser = User::getCurrent($database); |
|
34 | + |
|
35 | + $target = WebRequest::postString('target'); |
|
36 | + |
|
37 | + // FIXME: domains! |
|
38 | + $requestQueue = RequestQueue::getByApiName($database, $target, 1); |
|
39 | + |
|
40 | + if ($requestQueue === false) { |
|
41 | + throw new ApplicationLogicException('Defer target not valid'); |
|
42 | + } |
|
43 | + |
|
44 | + if ($request->getQueue() == $requestQueue->getId() && $request->getStatus() == RequestStatus::OPEN) { |
|
45 | + SessionAlert::warning('This request is already in the specified queue.'); |
|
46 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
47 | + |
|
48 | + return; |
|
49 | + } |
|
50 | + |
|
51 | + $closureDate = $request->getClosureDate(); |
|
52 | + $date = new DateTime(); |
|
53 | + $date->modify("-7 days"); |
|
54 | + |
|
55 | + if ($request->getStatus() == RequestStatus::CLOSED && $closureDate < $date) { |
|
56 | + if (!$this->barrierTest('reopenOldRequest', $currentUser, 'RequestData')) { |
|
57 | + throw new ApplicationLogicException( |
|
58 | + "You are not allowed to re-open a request that has been closed for over a week."); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) { |
|
63 | + if (!$this->barrierTest('reopenClearedRequest', $currentUser, 'RequestData')) { |
|
64 | + throw new ApplicationLogicException( |
|
65 | + "You are not allowed to re-open a request for which the private data has been purged."); |
|
66 | + } |
|
67 | + } |
|
68 | + |
|
69 | + if ($request->getStatus() === RequestStatus::JOBQUEUE) { |
|
70 | + /** @var JobQueue[] $pendingJobs */ |
|
71 | + // FIXME: domains |
|
72 | + $pendingJobs = JobQueueSearchHelper::get($database, 1) |
|
73 | + ->byRequest($request->getId()) |
|
74 | + ->statusIn([ |
|
75 | + JobQueue::STATUS_QUEUED, |
|
76 | + JobQueue::STATUS_READY, |
|
77 | + JobQueue::STATUS_WAITING, |
|
78 | + ]) |
|
79 | + ->fetch(); |
|
80 | + |
|
81 | + foreach ($pendingJobs as $job) { |
|
82 | + $job->setStatus(JobQueue::STATUS_CANCELLED); |
|
83 | + $job->setError('Cancelled by request deferral'); |
|
84 | + $job->save(); |
|
85 | + |
|
86 | + Logger::backgroundJobCancelled($database, $job); |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + $request->setReserved(null); |
|
91 | + $request->setStatus(RequestStatus::OPEN); |
|
92 | + $request->setQueue($requestQueue->getId()); |
|
93 | + $request->setUpdateVersion(WebRequest::postInt('updateversion')); |
|
94 | + $request->save(); |
|
95 | + |
|
96 | + Logger::deferRequest($database, $request, $requestQueue->getLogName()); |
|
97 | + |
|
98 | + $this->getNotificationHelper()->requestDeferred($request); |
|
99 | + |
|
100 | + $deto = htmlentities($requestQueue->getDisplayName(), ENT_COMPAT, 'UTF-8'); |
|
101 | + SessionAlert::success("Request {$request->getId()} deferred to {$deto}"); |
|
102 | + |
|
103 | + $this->redirect(); |
|
104 | + } |
|
105 | 105 | } |
@@ -16,55 +16,55 @@ |
||
16 | 16 | |
17 | 17 | class PageComment extends RequestActionBase |
18 | 18 | { |
19 | - /** |
|
20 | - * Main function for this page, when no specific actions are called. |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - protected function main() |
|
24 | - { |
|
25 | - $this->checkPosted(); |
|
26 | - $database = $this->getDatabase(); |
|
27 | - $request = $this->getRequest($database); |
|
19 | + /** |
|
20 | + * Main function for this page, when no specific actions are called. |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + protected function main() |
|
24 | + { |
|
25 | + $this->checkPosted(); |
|
26 | + $database = $this->getDatabase(); |
|
27 | + $request = $this->getRequest($database); |
|
28 | 28 | |
29 | - $commentText = WebRequest::postString('comment'); |
|
30 | - if ($commentText === false || $commentText == '') { |
|
31 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
29 | + $commentText = WebRequest::postString('comment'); |
|
30 | + if ($commentText === false || $commentText == '') { |
|
31 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
32 | 32 | |
33 | - return; |
|
34 | - } |
|
33 | + return; |
|
34 | + } |
|
35 | 35 | |
36 | - //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
37 | - $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
38 | - $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
36 | + //Look for and detect IPv4/IPv6 addresses in comment text, and warn the commenter. |
|
37 | + $ipv4Regex = '/\b' . RegexConstants::IPV4 . '\b/'; |
|
38 | + $ipv6Regex = '/\b' . RegexConstants::IPV6 . '\b/'; |
|
39 | 39 | |
40 | - $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
40 | + $overridePolicy = WebRequest::postBoolean('privpol-check-override'); |
|
41 | 41 | |
42 | - if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
43 | - $this->assignCSRFToken(); |
|
44 | - $this->assign("request", $request); |
|
45 | - $this->assign("comment", $commentText); |
|
46 | - $this->skipAlerts(); |
|
47 | - $this->setTemplate("privpol-warning.tpl"); |
|
42 | + if ((preg_match($ipv4Regex, $commentText) || preg_match($ipv6Regex, $commentText)) && !$overridePolicy) { |
|
43 | + $this->assignCSRFToken(); |
|
44 | + $this->assign("request", $request); |
|
45 | + $this->assign("comment", $commentText); |
|
46 | + $this->skipAlerts(); |
|
47 | + $this->setTemplate("privpol-warning.tpl"); |
|
48 | 48 | |
49 | - return; |
|
50 | - } |
|
49 | + return; |
|
50 | + } |
|
51 | 51 | |
52 | - $visibility = WebRequest::postString('visibility') ?? 'user'; |
|
53 | - if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
54 | - throw new ApplicationLogicException('Invalid comment visibility'); |
|
55 | - } |
|
52 | + $visibility = WebRequest::postString('visibility') ?? 'user'; |
|
53 | + if ($visibility !== 'user' && $visibility !== 'admin' && $visibility !== 'checkuser') { |
|
54 | + throw new ApplicationLogicException('Invalid comment visibility'); |
|
55 | + } |
|
56 | 56 | |
57 | - $comment = new Comment(); |
|
58 | - $comment->setDatabase($database); |
|
57 | + $comment = new Comment(); |
|
58 | + $comment->setDatabase($database); |
|
59 | 59 | |
60 | - $comment->setRequest($request->getId()); |
|
61 | - $comment->setVisibility($visibility); |
|
62 | - $comment->setUser(User::getCurrent($database)->getId()); |
|
63 | - $comment->setComment($commentText); |
|
60 | + $comment->setRequest($request->getId()); |
|
61 | + $comment->setVisibility($visibility); |
|
62 | + $comment->setUser(User::getCurrent($database)->getId()); |
|
63 | + $comment->setComment($commentText); |
|
64 | 64 | |
65 | - $comment->save(); |
|
65 | + $comment->save(); |
|
66 | 66 | |
67 | - $this->getNotificationHelper()->commentCreated($comment, $request); |
|
68 | - $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
69 | - } |
|
67 | + $this->getNotificationHelper()->commentCreated($comment, $request); |
|
68 | + $this->redirect('viewRequest', null, array('id' => $request->getId())); |
|
69 | + } |
|
70 | 70 | } |