Failed Conditions
Push — newinternal ( 216d62...410e59 )
by Simon
05:28 queued 13s
created
includes/Pages/RequestAction/PageDropRequest.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -15,22 +15,22 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
includes/Pages/RequestAction/PageCreateRequest.php 1 patch
Indentation   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -34,151 +34,151 @@
 block discarded – undo
34 34
  */
35 35
 class PageCreateRequest extends RequestActionBase
36 36
 {
37
-    /**
38
-     * Main function for this page, when no specific actions are called.
39
-     * @return void
40
-     * @throws AccessDeniedException
41
-     * @throws ApplicationLogicException
42
-     */
43
-    protected function main()
44
-    {
45
-        $this->checkPosted();
46
-
47
-        $database = $this->getDatabase();
48
-
49
-        $request = $this->getRequest($database);
50
-        $template = $this->getTemplate($database);
51
-        $creationMode = $this->getCreationMode();
52
-        $user = User::getCurrent($database);
53
-
54
-        $secMgr = $this->getSecurityManager();
55
-        if ($secMgr->allows('RequestCreation', User::CREATION_BOT, $user) !== SecurityManager::ALLOWED
56
-            && $creationMode === 'bot'
57
-        ) {
58
-            throw new AccessDeniedException($secMgr);
59
-        }
60
-        elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED
61
-            && $creationMode === 'oauth'
62
-        ) {
63
-            throw new AccessDeniedException($secMgr);
64
-        }
65
-
66
-        if ($request->getEmailSent()) {
67
-            throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation');
68
-        }
69
-
70
-        $request->setStatus(RequestStatus::JOBQUEUE);
71
-        $request->setReserved(null);
72
-        $request->save();
73
-
74
-        Logger::enqueuedJobQueue($database, $request);
75
-
76
-        $creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database);
77
-
78
-        if ($user->getWelcomeTemplate() !== null) {
79
-            $this->enqueueWelcomeTask($request, $creationTaskId, $user, $database);
80
-        }
81
-
82
-        SessionAlert::success("Request {$request->getId()} has been queued for autocreation");
83
-
84
-        $this->redirect();
85
-    }
86
-
87
-    protected function getCreationMode()
88
-    {
89
-        $creationMode = WebRequest::postString('mode');
90
-        if ($creationMode !== 'oauth' && $creationMode !== 'bot') {
91
-            throw new ApplicationLogicException('Unknown creation mode');
92
-        }
93
-
94
-        return $creationMode;
95
-    }
96
-
97
-    /**
98
-     * @param PdoDatabase $database
99
-     *
100
-     * @return EmailTemplate
101
-     * @throws ApplicationLogicException
102
-     */
103
-    protected function getTemplate(PdoDatabase $database)
104
-    {
105
-        $templateId = WebRequest::postInt('template');
106
-        if ($templateId === null) {
107
-            throw new ApplicationLogicException('No template specified');
108
-        }
109
-
110
-        /** @var EmailTemplate $template */
111
-        $template = EmailTemplate::getById($templateId, $database);
112
-        if ($template === false || !$template->getActive()) {
113
-            throw new ApplicationLogicException('Invalid or inactive template specified');
114
-        }
115
-
116
-        if ($template->getDefaultAction() !== EmailTemplate::CREATED) {
117
-            throw new ApplicationLogicException('Specified template is not a creation template!');
118
-        }
119
-
120
-        return $template;
121
-    }
122
-
123
-    /**
124
-     * @param PdoDatabase $database
125
-     *
126
-     * @return Request
127
-     * @throws ApplicationLogicException
128
-     */
129
-    protected function getRequest(PdoDatabase $database)
130
-    {
131
-        $request = parent::getRequest($database);
132
-
133
-        if ($request->getStatus() == RequestStatus::CLOSED) {
134
-            throw new ApplicationLogicException('Request is already closed');
135
-        }
136
-
137
-        return $request;
138
-    }
139
-
140
-    /**
141
-     * @param               $creationMode
142
-     * @param Request       $request
143
-     * @param EmailTemplate $template
144
-     * @param User          $user
145
-     *
146
-     * @param PdoDatabase   $database
147
-     *
148
-     * @return int
149
-     * @throws ApplicationLogicException
150
-     */
151
-    protected function enqueueCreationTask(
152
-        $creationMode,
153
-        Request $request,
154
-        EmailTemplate $template,
155
-        User $user,
156
-        PdoDatabase $database
157
-    ) {
158
-        $creationTaskClass = null;
159
-
160
-        if ($creationMode == "oauth") {
161
-            $creationTaskClass = UserCreationTask::class;
162
-        }
163
-
164
-        if ($creationMode == "bot") {
165
-            $creationTaskClass = BotCreationTask::class;
166
-        }
167
-
168
-        if ($creationTaskClass === null) {
169
-            throw new ApplicationLogicException('Cannot determine creation mode');
170
-        }
171
-
172
-        $creationTask = new JobQueue();
173
-        $creationTask->setTask($creationTaskClass);
174
-        $creationTask->setRequest($request->getId());
175
-        $creationTask->setEmailTemplate($template->getId());
176
-        $creationTask->setTriggerUserId($user->getId());
177
-        $creationTask->setDatabase($database);
178
-        $creationTask->save();
179
-
180
-        $creationTaskId = $creationTask->getId();
181
-
182
-        return $creationTaskId;
183
-    }
37
+	/**
38
+	 * Main function for this page, when no specific actions are called.
39
+	 * @return void
40
+	 * @throws AccessDeniedException
41
+	 * @throws ApplicationLogicException
42
+	 */
43
+	protected function main()
44
+	{
45
+		$this->checkPosted();
46
+
47
+		$database = $this->getDatabase();
48
+
49
+		$request = $this->getRequest($database);
50
+		$template = $this->getTemplate($database);
51
+		$creationMode = $this->getCreationMode();
52
+		$user = User::getCurrent($database);
53
+
54
+		$secMgr = $this->getSecurityManager();
55
+		if ($secMgr->allows('RequestCreation', User::CREATION_BOT, $user) !== SecurityManager::ALLOWED
56
+			&& $creationMode === 'bot'
57
+		) {
58
+			throw new AccessDeniedException($secMgr);
59
+		}
60
+		elseif ($secMgr->allows('RequestCreation', User::CREATION_OAUTH, $user) !== SecurityManager::ALLOWED
61
+			&& $creationMode === 'oauth'
62
+		) {
63
+			throw new AccessDeniedException($secMgr);
64
+		}
65
+
66
+		if ($request->getEmailSent()) {
67
+			throw new ApplicationLogicException('This requester has already had an email sent to them. Please fall back to manual creation');
68
+		}
69
+
70
+		$request->setStatus(RequestStatus::JOBQUEUE);
71
+		$request->setReserved(null);
72
+		$request->save();
73
+
74
+		Logger::enqueuedJobQueue($database, $request);
75
+
76
+		$creationTaskId = $this->enqueueCreationTask($creationMode, $request, $template, $user, $database);
77
+
78
+		if ($user->getWelcomeTemplate() !== null) {
79
+			$this->enqueueWelcomeTask($request, $creationTaskId, $user, $database);
80
+		}
81
+
82
+		SessionAlert::success("Request {$request->getId()} has been queued for autocreation");
83
+
84
+		$this->redirect();
85
+	}
86
+
87
+	protected function getCreationMode()
88
+	{
89
+		$creationMode = WebRequest::postString('mode');
90
+		if ($creationMode !== 'oauth' && $creationMode !== 'bot') {
91
+			throw new ApplicationLogicException('Unknown creation mode');
92
+		}
93
+
94
+		return $creationMode;
95
+	}
96
+
97
+	/**
98
+	 * @param PdoDatabase $database
99
+	 *
100
+	 * @return EmailTemplate
101
+	 * @throws ApplicationLogicException
102
+	 */
103
+	protected function getTemplate(PdoDatabase $database)
104
+	{
105
+		$templateId = WebRequest::postInt('template');
106
+		if ($templateId === null) {
107
+			throw new ApplicationLogicException('No template specified');
108
+		}
109
+
110
+		/** @var EmailTemplate $template */
111
+		$template = EmailTemplate::getById($templateId, $database);
112
+		if ($template === false || !$template->getActive()) {
113
+			throw new ApplicationLogicException('Invalid or inactive template specified');
114
+		}
115
+
116
+		if ($template->getDefaultAction() !== EmailTemplate::CREATED) {
117
+			throw new ApplicationLogicException('Specified template is not a creation template!');
118
+		}
119
+
120
+		return $template;
121
+	}
122
+
123
+	/**
124
+	 * @param PdoDatabase $database
125
+	 *
126
+	 * @return Request
127
+	 * @throws ApplicationLogicException
128
+	 */
129
+	protected function getRequest(PdoDatabase $database)
130
+	{
131
+		$request = parent::getRequest($database);
132
+
133
+		if ($request->getStatus() == RequestStatus::CLOSED) {
134
+			throw new ApplicationLogicException('Request is already closed');
135
+		}
136
+
137
+		return $request;
138
+	}
139
+
140
+	/**
141
+	 * @param               $creationMode
142
+	 * @param Request       $request
143
+	 * @param EmailTemplate $template
144
+	 * @param User          $user
145
+	 *
146
+	 * @param PdoDatabase   $database
147
+	 *
148
+	 * @return int
149
+	 * @throws ApplicationLogicException
150
+	 */
151
+	protected function enqueueCreationTask(
152
+		$creationMode,
153
+		Request $request,
154
+		EmailTemplate $template,
155
+		User $user,
156
+		PdoDatabase $database
157
+	) {
158
+		$creationTaskClass = null;
159
+
160
+		if ($creationMode == "oauth") {
161
+			$creationTaskClass = UserCreationTask::class;
162
+		}
163
+
164
+		if ($creationMode == "bot") {
165
+			$creationTaskClass = BotCreationTask::class;
166
+		}
167
+
168
+		if ($creationTaskClass === null) {
169
+			throw new ApplicationLogicException('Cannot determine creation mode');
170
+		}
171
+
172
+		$creationTask = new JobQueue();
173
+		$creationTask->setTask($creationTaskClass);
174
+		$creationTask->setRequest($request->getId());
175
+		$creationTask->setEmailTemplate($template->getId());
176
+		$creationTask->setTriggerUserId($user->getId());
177
+		$creationTask->setDatabase($database);
178
+		$creationTask->save();
179
+
180
+		$creationTaskId = $creationTask->getId();
181
+
182
+		return $creationTaskId;
183
+	}
184 184
 }
185 185
\ No newline at end of file
Please login to merge, or discard this patch.
includes/Pages/PageMain.php 2 patches
Indentation   +157 added lines, -157 removed lines patch added patch discarded remove patch
@@ -20,60 +20,60 @@  discard block
 block discarded – undo
20 20
 
21 21
 class PageMain extends InternalPageBase
22 22
 {
23
-    /**
24
-     * Main function for this page, when no actions are called.
25
-     */
26
-    protected function main()
27
-    {
28
-        $this->assignCSRFToken();
29
-
30
-        $config = $this->getSiteConfiguration();
31
-        $database = $this->getDatabase();
32
-        $currentUser = User::getCurrent($database);
33
-
34
-        // general template configuration
35
-        $this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
36
-        $this->assign('requestLimitShowOnly', $config->getMiserModeLimit());
37
-
38
-        // Get map of possible usernames
39
-        $userList = UserSearchHelper::get($database)->withReservedRequest();
40
-        $this->assign('userList', $userList);
41
-
42
-        $seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class);
43
-
44
-        // Fetch request data
45
-        $requestSectionData = array();
46
-        if ($seeAllRequests) {
47
-            $this->setupStatusSections($database, $config, $requestSectionData);
48
-            $this->setupHospitalQueue($database, $config, $requestSectionData);
49
-            $this->setupJobQueue($database, $config, $requestSectionData);
50
-        }
51
-        $this->setupLastFiveClosedData($database, $seeAllRequests);
52
-
53
-        // Assign data to template
54
-        $this->assign('requestSectionData', $requestSectionData);
55
-
56
-        // Extra rights
57
-        $this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
58
-        $this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
59
-
60
-        $this->setTemplate('mainpage/mainpage.tpl');
61
-    }
62
-
63
-    /**
64
-     * @param PdoDatabase $database
65
-     * @param bool        $seeAllRequests
66
-     *
67
-     * @internal param User $currentUser
68
-     */
69
-    private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests)
70
-    {
71
-        $this->assign('showLastFive', $seeAllRequests);
72
-        if (!$seeAllRequests) {
73
-            return;
74
-        }
75
-
76
-        $query = <<<SQL
23
+	/**
24
+	 * Main function for this page, when no actions are called.
25
+	 */
26
+	protected function main()
27
+	{
28
+		$this->assignCSRFToken();
29
+
30
+		$config = $this->getSiteConfiguration();
31
+		$database = $this->getDatabase();
32
+		$currentUser = User::getCurrent($database);
33
+
34
+		// general template configuration
35
+		$this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
36
+		$this->assign('requestLimitShowOnly', $config->getMiserModeLimit());
37
+
38
+		// Get map of possible usernames
39
+		$userList = UserSearchHelper::get($database)->withReservedRequest();
40
+		$this->assign('userList', $userList);
41
+
42
+		$seeAllRequests = $this->barrierTest('seeAllRequests', $currentUser, PageViewRequest::class);
43
+
44
+		// Fetch request data
45
+		$requestSectionData = array();
46
+		if ($seeAllRequests) {
47
+			$this->setupStatusSections($database, $config, $requestSectionData);
48
+			$this->setupHospitalQueue($database, $config, $requestSectionData);
49
+			$this->setupJobQueue($database, $config, $requestSectionData);
50
+		}
51
+		$this->setupLastFiveClosedData($database, $seeAllRequests);
52
+
53
+		// Assign data to template
54
+		$this->assign('requestSectionData', $requestSectionData);
55
+
56
+		// Extra rights
57
+		$this->assign('canBan', $this->barrierTest('set', $currentUser, PageBan::class));
58
+		$this->assign('canBreakReservation', $this->barrierTest('force', $currentUser, PageBreakReservation::class));
59
+
60
+		$this->setTemplate('mainpage/mainpage.tpl');
61
+	}
62
+
63
+	/**
64
+	 * @param PdoDatabase $database
65
+	 * @param bool        $seeAllRequests
66
+	 *
67
+	 * @internal param User $currentUser
68
+	 */
69
+	private function setupLastFiveClosedData(PdoDatabase $database, $seeAllRequests)
70
+	{
71
+		$this->assign('showLastFive', $seeAllRequests);
72
+		if (!$seeAllRequests) {
73
+			return;
74
+		}
75
+
76
+		$query = <<<SQL
77 77
 		SELECT request.id, request.name, request.updateversion
78 78
 		FROM request /* PageMain::main() */
79 79
 		JOIN log ON log.objectid = request.id AND log.objecttype = 'Request'
@@ -82,107 +82,107 @@  discard block
 block discarded – undo
82 82
 		LIMIT 5;
83 83
 SQL;
84 84
 
85
-        $statement = $database->prepare($query);
86
-        $statement->execute();
87
-
88
-        $last5result = $statement->fetchAll(PDO::FETCH_ASSOC);
89
-
90
-        $this->assign('lastFive', $last5result);
91
-    }
92
-
93
-    /**
94
-     * @param PdoDatabase       $database
95
-     * @param SiteConfiguration $config
96
-     * @param                   $requestSectionData
97
-     */
98
-    private function setupHospitalQueue(
99
-        PdoDatabase $database,
100
-        SiteConfiguration $config,
101
-        &$requestSectionData
102
-    ) {
103
-        $search = RequestSearchHelper::get($database)
104
-            ->limit($config->getMiserModeLimit())
105
-            ->excludingStatus('Closed')
106
-            ->isHospitalised();
107
-
108
-        if ($config->getEmailConfirmationEnabled()) {
109
-            $search->withConfirmedEmail();
110
-        }
111
-
112
-        $results = $search->getRecordCount($requestCount)->fetch();
113
-
114
-        if($requestCount > 0) {
115
-            $requestSectionData['Hospital - Requests failed auto-creation'] = array(
116
-                'requests' => $results,
117
-                'total'    => $requestCount,
118
-                'api'      => 'hospital',
119
-                'type'     => 'hospital',
120
-                'special'  => 'Job Queue',
121
-                'help'     => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.'
122
-            );
123
-        }
124
-    }
125
-
126
-    /**
127
-     * @param PdoDatabase       $database
128
-     * @param SiteConfiguration $config
129
-     * @param                   $requestSectionData
130
-     */
131
-    private function setupJobQueue(
132
-        PdoDatabase $database,
133
-        SiteConfiguration $config,
134
-        &$requestSectionData
135
-    ) {
136
-        $search = RequestSearchHelper::get($database)
137
-            ->limit($config->getMiserModeLimit())
138
-            ->byStatus(RequestStatus::JOBQUEUE);
139
-
140
-        if ($config->getEmailConfirmationEnabled()) {
141
-            $search->withConfirmedEmail();
142
-        }
143
-
144
-        $results = $search->getRecordCount($requestCount)->fetch();
145
-
146
-        if($requestCount > 0) {
147
-            $requestSectionData['Requests queued in the Job Queue'] = array(
148
-                'requests' => $results,
149
-                'total'    => $requestCount,
150
-                'api'      => 'JobQueue',
151
-                'type'     => 'JobQueue',
152
-                'special'  => 'Job Queue',
153
-                'help'     => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.'
154
-            );
155
-        }
156
-    }
157
-
158
-    /**
159
-     * @param PdoDatabase       $database
160
-     * @param SiteConfiguration $config
161
-     * @param                   $requestSectionData
162
-     */
163
-    private function setupStatusSections(
164
-        PdoDatabase $database,
165
-        SiteConfiguration $config,
166
-        &$requestSectionData
167
-    ) {
168
-        $search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised();
169
-
170
-        if ($config->getEmailConfirmationEnabled()) {
171
-            $search->withConfirmedEmail();
172
-        }
173
-
174
-        $requestStates = $config->getRequestStates();
175
-        $requestsByStatus = $search->fetchByStatus(array_keys($requestStates));
176
-
177
-        foreach ($requestStates as $type => $v) {
178
-            $requestSectionData[$v['header']] = array(
179
-                'requests' => $requestsByStatus[$type]['data'],
180
-                'total'    => $requestsByStatus[$type]['count'],
181
-                'api'      => $v['api'],
182
-                'type'     => $type,
183
-                'special'  => null,
184
-                'help'     => null,
185
-            );
186
-        }
187
-    }
85
+		$statement = $database->prepare($query);
86
+		$statement->execute();
87
+
88
+		$last5result = $statement->fetchAll(PDO::FETCH_ASSOC);
89
+
90
+		$this->assign('lastFive', $last5result);
91
+	}
92
+
93
+	/**
94
+	 * @param PdoDatabase       $database
95
+	 * @param SiteConfiguration $config
96
+	 * @param                   $requestSectionData
97
+	 */
98
+	private function setupHospitalQueue(
99
+		PdoDatabase $database,
100
+		SiteConfiguration $config,
101
+		&$requestSectionData
102
+	) {
103
+		$search = RequestSearchHelper::get($database)
104
+			->limit($config->getMiserModeLimit())
105
+			->excludingStatus('Closed')
106
+			->isHospitalised();
107
+
108
+		if ($config->getEmailConfirmationEnabled()) {
109
+			$search->withConfirmedEmail();
110
+		}
111
+
112
+		$results = $search->getRecordCount($requestCount)->fetch();
113
+
114
+		if($requestCount > 0) {
115
+			$requestSectionData['Hospital - Requests failed auto-creation'] = array(
116
+				'requests' => $results,
117
+				'total'    => $requestCount,
118
+				'api'      => 'hospital',
119
+				'type'     => 'hospital',
120
+				'special'  => 'Job Queue',
121
+				'help'     => 'This queue lists all the requests which have been attempted to be created in the background, but for which this has failed for one reason or another. Check the job queue to find the error. Requests here may need to be created manually, or it may be possible to re-queue the request for auto-creation by the tool, or it may have been created already. Use your own technical discretion here.'
122
+			);
123
+		}
124
+	}
125
+
126
+	/**
127
+	 * @param PdoDatabase       $database
128
+	 * @param SiteConfiguration $config
129
+	 * @param                   $requestSectionData
130
+	 */
131
+	private function setupJobQueue(
132
+		PdoDatabase $database,
133
+		SiteConfiguration $config,
134
+		&$requestSectionData
135
+	) {
136
+		$search = RequestSearchHelper::get($database)
137
+			->limit($config->getMiserModeLimit())
138
+			->byStatus(RequestStatus::JOBQUEUE);
139
+
140
+		if ($config->getEmailConfirmationEnabled()) {
141
+			$search->withConfirmedEmail();
142
+		}
143
+
144
+		$results = $search->getRecordCount($requestCount)->fetch();
145
+
146
+		if($requestCount > 0) {
147
+			$requestSectionData['Requests queued in the Job Queue'] = array(
148
+				'requests' => $results,
149
+				'total'    => $requestCount,
150
+				'api'      => 'JobQueue',
151
+				'type'     => 'JobQueue',
152
+				'special'  => 'Job Queue',
153
+				'help'     => 'This section lists all the requests which are currently waiting to be created by the tool. Requests should automatically disappear from here within a few minutes.'
154
+			);
155
+		}
156
+	}
157
+
158
+	/**
159
+	 * @param PdoDatabase       $database
160
+	 * @param SiteConfiguration $config
161
+	 * @param                   $requestSectionData
162
+	 */
163
+	private function setupStatusSections(
164
+		PdoDatabase $database,
165
+		SiteConfiguration $config,
166
+		&$requestSectionData
167
+	) {
168
+		$search = RequestSearchHelper::get($database)->limit($config->getMiserModeLimit())->notHospitalised();
169
+
170
+		if ($config->getEmailConfirmationEnabled()) {
171
+			$search->withConfirmedEmail();
172
+		}
173
+
174
+		$requestStates = $config->getRequestStates();
175
+		$requestsByStatus = $search->fetchByStatus(array_keys($requestStates));
176
+
177
+		foreach ($requestStates as $type => $v) {
178
+			$requestSectionData[$v['header']] = array(
179
+				'requests' => $requestsByStatus[$type]['data'],
180
+				'total'    => $requestsByStatus[$type]['count'],
181
+				'api'      => $v['api'],
182
+				'type'     => $type,
183
+				'special'  => null,
184
+				'help'     => null,
185
+			);
186
+		}
187
+	}
188 188
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 
112 112
         $results = $search->getRecordCount($requestCount)->fetch();
113 113
 
114
-        if($requestCount > 0) {
114
+        if ($requestCount > 0) {
115 115
             $requestSectionData['Hospital - Requests failed auto-creation'] = array(
116 116
                 'requests' => $results,
117 117
                 'total'    => $requestCount,
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 
144 144
         $results = $search->getRecordCount($requestCount)->fetch();
145 145
 
146
-        if($requestCount > 0) {
146
+        if ($requestCount > 0) {
147 147
             $requestSectionData['Requests queued in the Job Queue'] = array(
148 148
                 'requests' => $results,
149 149
                 'total'    => $requestCount,
Please login to merge, or discard this patch.
includes/Pages/PageUserManagement.php 2 patches
Indentation   +541 added lines, -541 removed lines patch added patch discarded remove patch
@@ -24,545 +24,545 @@
 block discarded – undo
24 24
  */
25 25
 class PageUserManagement extends InternalPageBase
26 26
 {
27
-    /** @var string */
28
-    private $adminMailingList = '[email protected]';
29
-
30
-    /**
31
-     * Main function for this page, when no specific actions are called.
32
-     */
33
-    protected function main()
34
-    {
35
-        $this->setHtmlTitle('User Management');
36
-
37
-        $database = $this->getDatabase();
38
-        $currentUser = User::getCurrent($database);
39
-
40
-        // A bit hacky, but it's better than my last solution of creating an object for each user and passing that to
41
-        // the template. I still don't have a particularly good way of handling this.
42
-        OAuthUserHelper::prepareTokenCountStatement($database);
43
-
44
-        if (WebRequest::getBoolean("showAll")) {
45
-            $this->assign("showAll", true);
46
-
47
-            $suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch();
48
-            $this->assign("suspendedUsers", $suspendedUsers);
49
-
50
-            $declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch();
51
-            $this->assign("declinedUsers", $declinedUsers);
52
-
53
-            UserSearchHelper::get($database)->getRoleMap($roleMap);
54
-        }
55
-        else {
56
-            $this->assign("showAll", false);
57
-            $this->assign("suspendedUsers", array());
58
-            $this->assign("declinedUsers", array());
59
-
60
-            UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
61
-        }
62
-
63
-        $newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch();
64
-        $normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch();
65
-        $adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch();
66
-        $checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch();
67
-        $toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch();
68
-        $this->assign('newUsers', $newUsers);
69
-        $this->assign('normalUsers', $normalUsers);
70
-        $this->assign('adminUsers', $adminUsers);
71
-        $this->assign('checkUsers', $checkUsers);
72
-        $this->assign('toolRoots', $toolRoots);
73
-
74
-        $this->assign('roles', $roleMap);
75
-
76
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
77
-            return UserSearchHelper::get($database)->fetchColumn('username');
78
-        });
79
-
80
-        $this->assign('canApprove', $this->barrierTest('approve', $currentUser));
81
-        $this->assign('canDecline', $this->barrierTest('decline', $currentUser));
82
-        $this->assign('canRename', $this->barrierTest('rename', $currentUser));
83
-        $this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
84
-        $this->assign('canSuspend', $this->barrierTest('suspend', $currentUser));
85
-        $this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
86
-
87
-        $this->setTemplate("usermanagement/main.tpl");
88
-    }
89
-
90
-    #region Access control
91
-
92
-    /**
93
-     * Action target for editing the roles assigned to a user
94
-     */
95
-    protected function editRoles()
96
-    {
97
-        $this->setHtmlTitle('User Management');
98
-        $database = $this->getDatabase();
99
-        $userId = WebRequest::getInt('user');
100
-
101
-        /** @var User $user */
102
-        $user = User::getById($userId, $database);
103
-
104
-        if ($user === false) {
105
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
106
-        }
107
-
108
-        $roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database));
109
-
110
-        // Dual-mode action
111
-        if (WebRequest::wasPosted()) {
112
-            $this->validateCSRFToken();
113
-
114
-            $reason = WebRequest::postString('reason');
115
-            if ($reason === false || trim($reason) === '') {
116
-                throw new ApplicationLogicException('No reason specified for roles change');
117
-            }
118
-
119
-            /** @var UserRole[] $delete */
120
-            $delete = array();
121
-            /** @var string[] $delete */
122
-            $add = array();
123
-
124
-            foreach ($roleData as $name => $r) {
125
-                if ($r['allowEdit'] !== 1) {
126
-                    // not allowed, to touch this, so ignore it
127
-                    continue;
128
-                }
129
-
130
-                $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
131
-                if ($newValue !== $r['active']) {
132
-                    if ($newValue === 0) {
133
-                        $delete[] = $r['object'];
134
-                    }
135
-
136
-                    if ($newValue === 1) {
137
-                        $add[] = $name;
138
-                    }
139
-                }
140
-            }
141
-
142
-            // Check there's something to do
143
-            if ((count($add) + count($delete)) === 0) {
144
-                $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
145
-                SessionAlert::warning('No changes made to roles.');
146
-
147
-                return;
148
-            }
149
-
150
-            $removed = array();
151
-
152
-            /** @var UserRole $d */
153
-            foreach ($delete as $d) {
154
-                $removed[] = $d->getRole();
155
-                $d->delete();
156
-            }
157
-
158
-            foreach ($add as $x) {
159
-                $a = new UserRole();
160
-                $a->setUser($user->getId());
161
-                $a->setRole($x);
162
-                $a->setDatabase($database);
163
-                $a->save();
164
-            }
165
-
166
-            Logger::userRolesEdited($database, $user, $reason, $add, $removed);
167
-
168
-            // dummy save for optimistic locking. If this fails, the entire txn will roll back.
169
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
170
-            $user->save();
171
-
172
-            $this->getNotificationHelper()->userRolesEdited($user, $reason);
173
-            SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
174
-
175
-            $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
176
-
177
-            return;
178
-        }
179
-        else {
180
-            $this->assignCSRFToken();
181
-            $this->setTemplate('usermanagement/roleedit.tpl');
182
-            $this->assign('user', $user);
183
-            $this->assign('roleData', $roleData);
184
-        }
185
-    }
186
-
187
-    /**
188
-     * Action target for suspending users
189
-     *
190
-     * @throws ApplicationLogicException
191
-     */
192
-    protected function suspend()
193
-    {
194
-        $this->setHtmlTitle('User Management');
195
-
196
-        $database = $this->getDatabase();
197
-
198
-        $userId = WebRequest::getInt('user');
199
-
200
-        /** @var User $user */
201
-        $user = User::getById($userId, $database);
202
-
203
-        if ($user === false) {
204
-            throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.');
205
-        }
206
-
207
-        if ($user->isSuspended()) {
208
-            throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.');
209
-        }
210
-
211
-        // Dual-mode action
212
-        if (WebRequest::wasPosted()) {
213
-            $this->validateCSRFToken();
214
-            $reason = WebRequest::postString('reason');
215
-
216
-            if ($reason === null || trim($reason) === "") {
217
-                throw new ApplicationLogicException('No reason provided');
218
-            }
219
-
220
-            $user->setStatus(User::STATUS_SUSPENDED);
221
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
222
-            $user->save();
223
-            Logger::suspendedUser($database, $user, $reason);
224
-
225
-            $this->getNotificationHelper()->userSuspended($user, $reason);
226
-            SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
227
-
228
-            // send email
229
-            $this->sendStatusChangeEmail(
230
-                'Your WP:ACC account has been suspended',
231
-                'usermanagement/emails/suspended.tpl',
232
-                $reason,
233
-                $user,
234
-                User::getCurrent($database)->getUsername()
235
-            );
236
-
237
-            $this->redirect('userManagement');
238
-
239
-            return;
240
-        }
241
-        else {
242
-            $this->assignCSRFToken();
243
-            $this->setTemplate('usermanagement/changelevel-reason.tpl');
244
-            $this->assign('user', $user);
245
-            $this->assign('status', 'Suspended');
246
-            $this->assign("showReason", true);
247
-        }
248
-    }
249
-
250
-    /**
251
-     * Entry point for the decline action
252
-     *
253
-     * @throws ApplicationLogicException
254
-     */
255
-    protected function decline()
256
-    {
257
-        $this->setHtmlTitle('User Management');
258
-
259
-        $database = $this->getDatabase();
260
-
261
-        $userId = WebRequest::getInt('user');
262
-        $user = User::getById($userId, $database);
263
-
264
-        if ($user === false) {
265
-            throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.');
266
-        }
267
-
268
-        if (!$user->isNewUser()) {
269
-            throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.');
270
-        }
271
-
272
-        // Dual-mode action
273
-        if (WebRequest::wasPosted()) {
274
-            $this->validateCSRFToken();
275
-            $reason = WebRequest::postString('reason');
276
-
277
-            if ($reason === null || trim($reason) === "") {
278
-                throw new ApplicationLogicException('No reason provided');
279
-            }
280
-
281
-            $user->setStatus(User::STATUS_DECLINED);
282
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
283
-            $user->save();
284
-            Logger::declinedUser($database, $user, $reason);
285
-
286
-            $this->getNotificationHelper()->userDeclined($user, $reason);
287
-            SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
288
-
289
-            // send email
290
-            $this->sendStatusChangeEmail(
291
-                'Your WP:ACC account has been declined',
292
-                'usermanagement/emails/declined.tpl',
293
-                $reason,
294
-                $user,
295
-                User::getCurrent($database)->getUsername()
296
-            );
297
-
298
-            $this->redirect('userManagement');
299
-
300
-            return;
301
-        }
302
-        else {
303
-            $this->assignCSRFToken();
304
-            $this->setTemplate('usermanagement/changelevel-reason.tpl');
305
-            $this->assign('user', $user);
306
-            $this->assign('status', 'Declined');
307
-            $this->assign("showReason", true);
308
-        }
309
-    }
310
-
311
-    /**
312
-     * Entry point for the approve action
313
-     *
314
-     * @throws ApplicationLogicException
315
-     */
316
-    protected function approve()
317
-    {
318
-        $this->setHtmlTitle('User Management');
319
-
320
-        $database = $this->getDatabase();
321
-
322
-        $userId = WebRequest::getInt('user');
323
-        $user = User::getById($userId, $database);
324
-
325
-        if ($user === false) {
326
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
327
-        }
328
-
329
-        if ($user->isActive()) {
330
-            throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
331
-        }
332
-
333
-        // Dual-mode action
334
-        if (WebRequest::wasPosted()) {
335
-            $this->validateCSRFToken();
336
-            $user->setStatus(User::STATUS_ACTIVE);
337
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
338
-            $user->save();
339
-            Logger::approvedUser($database, $user);
340
-
341
-            $this->getNotificationHelper()->userApproved($user);
342
-            SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
343
-
344
-            // send email
345
-            $this->sendStatusChangeEmail(
346
-                'Your WP:ACC account has been approved',
347
-                'usermanagement/emails/approved.tpl',
348
-                null,
349
-                $user,
350
-                User::getCurrent($database)->getUsername()
351
-            );
352
-
353
-            $this->redirect("userManagement");
354
-
355
-            return;
356
-        }
357
-        else {
358
-            $this->assignCSRFToken();
359
-            $this->setTemplate("usermanagement/changelevel-reason.tpl");
360
-            $this->assign("user", $user);
361
-            $this->assign("status", "User");
362
-            $this->assign("showReason", false);
363
-        }
364
-    }
365
-
366
-    #endregion
367
-
368
-    #region Renaming / Editing
369
-
370
-    /**
371
-     * Entry point for the rename action
372
-     *
373
-     * @throws ApplicationLogicException
374
-     */
375
-    protected function rename()
376
-    {
377
-        $this->setHtmlTitle('User Management');
378
-
379
-        $database = $this->getDatabase();
380
-
381
-        $userId = WebRequest::getInt('user');
382
-        $user = User::getById($userId, $database);
383
-
384
-        if ($user === false) {
385
-            throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
386
-        }
387
-
388
-        // Dual-mode action
389
-        if (WebRequest::wasPosted()) {
390
-            $this->validateCSRFToken();
391
-            $newUsername = WebRequest::postString('newname');
392
-
393
-            if ($newUsername === null || trim($newUsername) === "") {
394
-                throw new ApplicationLogicException('The new username cannot be empty');
395
-            }
396
-
397
-            if (User::getByUsername($newUsername, $database) != false) {
398
-                throw new ApplicationLogicException('The new username already exists');
399
-            }
400
-
401
-            $oldUsername = $user->getUsername();
402
-            $user->setUsername($newUsername);
403
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
404
-
405
-            $user->save();
406
-
407
-            $logEntryData = serialize(array(
408
-                'old' => $oldUsername,
409
-                'new' => $newUsername,
410
-            ));
411
-
412
-            Logger::renamedUser($database, $user, $logEntryData);
413
-
414
-            SessionAlert::quick("Changed User "
415
-                . htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
416
-                . " name to "
417
-                . htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
418
-
419
-            $this->getNotificationHelper()->userRenamed($user, $oldUsername);
420
-
421
-            // send an email to the user.
422
-            $this->assign('targetUsername', $user->getUsername());
423
-            $this->assign('toolAdmin', User::getCurrent($database)->getUsername());
424
-            $this->assign('oldUsername', $oldUsername);
425
-            $this->assign('mailingList', $this->adminMailingList);
426
-
427
-            $this->getEmailHelper()->sendMail(
428
-                $user->getEmail(),
429
-                'Your username on WP:ACC has been changed',
430
-                $this->fetchTemplate('usermanagement/emails/renamed.tpl'),
431
-                array('Reply-To' => $this->adminMailingList)
432
-            );
433
-
434
-            $this->redirect("userManagement");
435
-
436
-            return;
437
-        }
438
-        else {
439
-            $this->assignCSRFToken();
440
-            $this->setTemplate('usermanagement/renameuser.tpl');
441
-            $this->assign('user', $user);
442
-        }
443
-    }
444
-
445
-    /**
446
-     * Entry point for the edit action
447
-     *
448
-     * @throws ApplicationLogicException
449
-     */
450
-    protected function editUser()
451
-    {
452
-        $this->setHtmlTitle('User Management');
453
-
454
-        $database = $this->getDatabase();
455
-
456
-        $userId = WebRequest::getInt('user');
457
-        $user = User::getById($userId, $database);
458
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
459
-
460
-        if ($user === false) {
461
-            throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
462
-        }
463
-
464
-        // Dual-mode action
465
-        if (WebRequest::wasPosted()) {
466
-            $this->validateCSRFToken();
467
-            $newEmail = WebRequest::postEmail('user_email');
468
-            $newOnWikiName = WebRequest::postString('user_onwikiname');
469
-
470
-            if ($newEmail === null) {
471
-                throw new ApplicationLogicException('Invalid email address');
472
-            }
473
-
474
-            if (!$oauth->isFullyLinked()) {
475
-                if (trim($newOnWikiName) == "") {
476
-                    throw new ApplicationLogicException('New on-wiki username cannot be blank');
477
-                }
478
-
479
-                $user->setOnWikiName($newOnWikiName);
480
-            }
481
-
482
-            $user->setEmail($newEmail);
483
-
484
-            $user->setUpdateVersion(WebRequest::postInt('updateversion'));
485
-
486
-            $user->save();
487
-
488
-            Logger::userPreferencesChange($database, $user);
489
-            $this->getNotificationHelper()->userPrefChange($user);
490
-            SessionAlert::quick('Changes to user\'s preferences have been saved');
491
-
492
-            $this->redirect("userManagement");
493
-
494
-            return;
495
-        }
496
-        else {
497
-            $this->assignCSRFToken();
498
-            $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
499
-                $this->getSiteConfiguration());
500
-            $this->setTemplate('usermanagement/edituser.tpl');
501
-            $this->assign('user', $user);
502
-            $this->assign('oauth', $oauth);
503
-        }
504
-    }
505
-
506
-    #endregion
507
-
508
-    /**
509
-     * Sends a status change email to the user.
510
-     *
511
-     * @param string      $subject           The subject of the email
512
-     * @param string      $template          The smarty template to use
513
-     * @param string|null $reason            The reason for performing the status change
514
-     * @param User        $user              The user affected
515
-     * @param string      $toolAdminUsername The tool admin's username who is making the edit
516
-     */
517
-    private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
518
-    {
519
-        $this->assign('targetUsername', $user->getUsername());
520
-        $this->assign('toolAdmin', $toolAdminUsername);
521
-        $this->assign('actionReason', $reason);
522
-        $this->assign('mailingList', $this->adminMailingList);
523
-
524
-        $this->getEmailHelper()->sendMail(
525
-            $user->getEmail(),
526
-            $subject,
527
-            $this->fetchTemplate($template),
528
-            array('Reply-To' => $this->adminMailingList)
529
-        );
530
-    }
531
-
532
-    /**
533
-     * @param UserRole[] $activeRoles
534
-     *
535
-     * @return array
536
-     */
537
-    private function getRoleData($activeRoles)
538
-    {
539
-        $availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles();
540
-
541
-        $currentUser = User::getCurrent($this->getDatabase());
542
-        $this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
543
-
544
-        $initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
545
-
546
-        $roleData = array();
547
-        foreach ($availableRoles as $role => $data) {
548
-            $intersection = array_intersect($data['editableBy'], $userRoles);
549
-
550
-            $roleData[$role] = $initialValue;
551
-            $roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
552
-            $roleData[$role]['description'] = $data['description'];
553
-        }
554
-
555
-        foreach ($activeRoles as $role) {
556
-            if (!isset($roleData[$role->getRole()])) {
557
-                // This value is no longer available in the configuration, allow changing (aka removing) it.
558
-                $roleData[$role->getRole()] = $initialValue;
559
-                $roleData[$role->getRole()]['allowEdit'] = 1;
560
-            }
561
-
562
-            $roleData[$role->getRole()]['object'] = $role;
563
-            $roleData[$role->getRole()]['active'] = 1;
564
-        }
565
-
566
-        return $roleData;
567
-    }
27
+	/** @var string */
28
+	private $adminMailingList = '[email protected]';
29
+
30
+	/**
31
+	 * Main function for this page, when no specific actions are called.
32
+	 */
33
+	protected function main()
34
+	{
35
+		$this->setHtmlTitle('User Management');
36
+
37
+		$database = $this->getDatabase();
38
+		$currentUser = User::getCurrent($database);
39
+
40
+		// A bit hacky, but it's better than my last solution of creating an object for each user and passing that to
41
+		// the template. I still don't have a particularly good way of handling this.
42
+		OAuthUserHelper::prepareTokenCountStatement($database);
43
+
44
+		if (WebRequest::getBoolean("showAll")) {
45
+			$this->assign("showAll", true);
46
+
47
+			$suspendedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_SUSPENDED)->fetch();
48
+			$this->assign("suspendedUsers", $suspendedUsers);
49
+
50
+			$declinedUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_DECLINED)->fetch();
51
+			$this->assign("declinedUsers", $declinedUsers);
52
+
53
+			UserSearchHelper::get($database)->getRoleMap($roleMap);
54
+		}
55
+		else {
56
+			$this->assign("showAll", false);
57
+			$this->assign("suspendedUsers", array());
58
+			$this->assign("declinedUsers", array());
59
+
60
+			UserSearchHelper::get($database)->statusIn(array('New', 'Active'))->getRoleMap($roleMap);
61
+		}
62
+
63
+		$newUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_NEW)->fetch();
64
+		$normalUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('user')->fetch();
65
+		$adminUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('admin')->fetch();
66
+		$checkUsers = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('checkuser')->fetch();
67
+		$toolRoots = UserSearchHelper::get($database)->byStatus(User::STATUS_ACTIVE)->byRole('toolRoot')->fetch();
68
+		$this->assign('newUsers', $newUsers);
69
+		$this->assign('normalUsers', $normalUsers);
70
+		$this->assign('adminUsers', $adminUsers);
71
+		$this->assign('checkUsers', $checkUsers);
72
+		$this->assign('toolRoots', $toolRoots);
73
+
74
+		$this->assign('roles', $roleMap);
75
+
76
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
77
+			return UserSearchHelper::get($database)->fetchColumn('username');
78
+		});
79
+
80
+		$this->assign('canApprove', $this->barrierTest('approve', $currentUser));
81
+		$this->assign('canDecline', $this->barrierTest('decline', $currentUser));
82
+		$this->assign('canRename', $this->barrierTest('rename', $currentUser));
83
+		$this->assign('canEditUser', $this->barrierTest('editUser', $currentUser));
84
+		$this->assign('canSuspend', $this->barrierTest('suspend', $currentUser));
85
+		$this->assign('canEditRoles', $this->barrierTest('editRoles', $currentUser));
86
+
87
+		$this->setTemplate("usermanagement/main.tpl");
88
+	}
89
+
90
+	#region Access control
91
+
92
+	/**
93
+	 * Action target for editing the roles assigned to a user
94
+	 */
95
+	protected function editRoles()
96
+	{
97
+		$this->setHtmlTitle('User Management');
98
+		$database = $this->getDatabase();
99
+		$userId = WebRequest::getInt('user');
100
+
101
+		/** @var User $user */
102
+		$user = User::getById($userId, $database);
103
+
104
+		if ($user === false) {
105
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
106
+		}
107
+
108
+		$roleData = $this->getRoleData(UserRole::getForUser($user->getId(), $database));
109
+
110
+		// Dual-mode action
111
+		if (WebRequest::wasPosted()) {
112
+			$this->validateCSRFToken();
113
+
114
+			$reason = WebRequest::postString('reason');
115
+			if ($reason === false || trim($reason) === '') {
116
+				throw new ApplicationLogicException('No reason specified for roles change');
117
+			}
118
+
119
+			/** @var UserRole[] $delete */
120
+			$delete = array();
121
+			/** @var string[] $delete */
122
+			$add = array();
123
+
124
+			foreach ($roleData as $name => $r) {
125
+				if ($r['allowEdit'] !== 1) {
126
+					// not allowed, to touch this, so ignore it
127
+					continue;
128
+				}
129
+
130
+				$newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
131
+				if ($newValue !== $r['active']) {
132
+					if ($newValue === 0) {
133
+						$delete[] = $r['object'];
134
+					}
135
+
136
+					if ($newValue === 1) {
137
+						$add[] = $name;
138
+					}
139
+				}
140
+			}
141
+
142
+			// Check there's something to do
143
+			if ((count($add) + count($delete)) === 0) {
144
+				$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
145
+				SessionAlert::warning('No changes made to roles.');
146
+
147
+				return;
148
+			}
149
+
150
+			$removed = array();
151
+
152
+			/** @var UserRole $d */
153
+			foreach ($delete as $d) {
154
+				$removed[] = $d->getRole();
155
+				$d->delete();
156
+			}
157
+
158
+			foreach ($add as $x) {
159
+				$a = new UserRole();
160
+				$a->setUser($user->getId());
161
+				$a->setRole($x);
162
+				$a->setDatabase($database);
163
+				$a->save();
164
+			}
165
+
166
+			Logger::userRolesEdited($database, $user, $reason, $add, $removed);
167
+
168
+			// dummy save for optimistic locking. If this fails, the entire txn will roll back.
169
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
170
+			$user->save();
171
+
172
+			$this->getNotificationHelper()->userRolesEdited($user, $reason);
173
+			SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
174
+
175
+			$this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
176
+
177
+			return;
178
+		}
179
+		else {
180
+			$this->assignCSRFToken();
181
+			$this->setTemplate('usermanagement/roleedit.tpl');
182
+			$this->assign('user', $user);
183
+			$this->assign('roleData', $roleData);
184
+		}
185
+	}
186
+
187
+	/**
188
+	 * Action target for suspending users
189
+	 *
190
+	 * @throws ApplicationLogicException
191
+	 */
192
+	protected function suspend()
193
+	{
194
+		$this->setHtmlTitle('User Management');
195
+
196
+		$database = $this->getDatabase();
197
+
198
+		$userId = WebRequest::getInt('user');
199
+
200
+		/** @var User $user */
201
+		$user = User::getById($userId, $database);
202
+
203
+		if ($user === false) {
204
+			throw new ApplicationLogicException('Sorry, the user you are trying to suspend could not be found.');
205
+		}
206
+
207
+		if ($user->isSuspended()) {
208
+			throw new ApplicationLogicException('Sorry, the user you are trying to suspend is already suspended.');
209
+		}
210
+
211
+		// Dual-mode action
212
+		if (WebRequest::wasPosted()) {
213
+			$this->validateCSRFToken();
214
+			$reason = WebRequest::postString('reason');
215
+
216
+			if ($reason === null || trim($reason) === "") {
217
+				throw new ApplicationLogicException('No reason provided');
218
+			}
219
+
220
+			$user->setStatus(User::STATUS_SUSPENDED);
221
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
222
+			$user->save();
223
+			Logger::suspendedUser($database, $user, $reason);
224
+
225
+			$this->getNotificationHelper()->userSuspended($user, $reason);
226
+			SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
227
+
228
+			// send email
229
+			$this->sendStatusChangeEmail(
230
+				'Your WP:ACC account has been suspended',
231
+				'usermanagement/emails/suspended.tpl',
232
+				$reason,
233
+				$user,
234
+				User::getCurrent($database)->getUsername()
235
+			);
236
+
237
+			$this->redirect('userManagement');
238
+
239
+			return;
240
+		}
241
+		else {
242
+			$this->assignCSRFToken();
243
+			$this->setTemplate('usermanagement/changelevel-reason.tpl');
244
+			$this->assign('user', $user);
245
+			$this->assign('status', 'Suspended');
246
+			$this->assign("showReason", true);
247
+		}
248
+	}
249
+
250
+	/**
251
+	 * Entry point for the decline action
252
+	 *
253
+	 * @throws ApplicationLogicException
254
+	 */
255
+	protected function decline()
256
+	{
257
+		$this->setHtmlTitle('User Management');
258
+
259
+		$database = $this->getDatabase();
260
+
261
+		$userId = WebRequest::getInt('user');
262
+		$user = User::getById($userId, $database);
263
+
264
+		if ($user === false) {
265
+			throw new ApplicationLogicException('Sorry, the user you are trying to decline could not be found.');
266
+		}
267
+
268
+		if (!$user->isNewUser()) {
269
+			throw new ApplicationLogicException('Sorry, the user you are trying to decline is not new.');
270
+		}
271
+
272
+		// Dual-mode action
273
+		if (WebRequest::wasPosted()) {
274
+			$this->validateCSRFToken();
275
+			$reason = WebRequest::postString('reason');
276
+
277
+			if ($reason === null || trim($reason) === "") {
278
+				throw new ApplicationLogicException('No reason provided');
279
+			}
280
+
281
+			$user->setStatus(User::STATUS_DECLINED);
282
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
283
+			$user->save();
284
+			Logger::declinedUser($database, $user, $reason);
285
+
286
+			$this->getNotificationHelper()->userDeclined($user, $reason);
287
+			SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
288
+
289
+			// send email
290
+			$this->sendStatusChangeEmail(
291
+				'Your WP:ACC account has been declined',
292
+				'usermanagement/emails/declined.tpl',
293
+				$reason,
294
+				$user,
295
+				User::getCurrent($database)->getUsername()
296
+			);
297
+
298
+			$this->redirect('userManagement');
299
+
300
+			return;
301
+		}
302
+		else {
303
+			$this->assignCSRFToken();
304
+			$this->setTemplate('usermanagement/changelevel-reason.tpl');
305
+			$this->assign('user', $user);
306
+			$this->assign('status', 'Declined');
307
+			$this->assign("showReason", true);
308
+		}
309
+	}
310
+
311
+	/**
312
+	 * Entry point for the approve action
313
+	 *
314
+	 * @throws ApplicationLogicException
315
+	 */
316
+	protected function approve()
317
+	{
318
+		$this->setHtmlTitle('User Management');
319
+
320
+		$database = $this->getDatabase();
321
+
322
+		$userId = WebRequest::getInt('user');
323
+		$user = User::getById($userId, $database);
324
+
325
+		if ($user === false) {
326
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve could not be found.');
327
+		}
328
+
329
+		if ($user->isActive()) {
330
+			throw new ApplicationLogicException('Sorry, the user you are trying to approve is already an active user.');
331
+		}
332
+
333
+		// Dual-mode action
334
+		if (WebRequest::wasPosted()) {
335
+			$this->validateCSRFToken();
336
+			$user->setStatus(User::STATUS_ACTIVE);
337
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
338
+			$user->save();
339
+			Logger::approvedUser($database, $user);
340
+
341
+			$this->getNotificationHelper()->userApproved($user);
342
+			SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
343
+
344
+			// send email
345
+			$this->sendStatusChangeEmail(
346
+				'Your WP:ACC account has been approved',
347
+				'usermanagement/emails/approved.tpl',
348
+				null,
349
+				$user,
350
+				User::getCurrent($database)->getUsername()
351
+			);
352
+
353
+			$this->redirect("userManagement");
354
+
355
+			return;
356
+		}
357
+		else {
358
+			$this->assignCSRFToken();
359
+			$this->setTemplate("usermanagement/changelevel-reason.tpl");
360
+			$this->assign("user", $user);
361
+			$this->assign("status", "User");
362
+			$this->assign("showReason", false);
363
+		}
364
+	}
365
+
366
+	#endregion
367
+
368
+	#region Renaming / Editing
369
+
370
+	/**
371
+	 * Entry point for the rename action
372
+	 *
373
+	 * @throws ApplicationLogicException
374
+	 */
375
+	protected function rename()
376
+	{
377
+		$this->setHtmlTitle('User Management');
378
+
379
+		$database = $this->getDatabase();
380
+
381
+		$userId = WebRequest::getInt('user');
382
+		$user = User::getById($userId, $database);
383
+
384
+		if ($user === false) {
385
+			throw new ApplicationLogicException('Sorry, the user you are trying to rename could not be found.');
386
+		}
387
+
388
+		// Dual-mode action
389
+		if (WebRequest::wasPosted()) {
390
+			$this->validateCSRFToken();
391
+			$newUsername = WebRequest::postString('newname');
392
+
393
+			if ($newUsername === null || trim($newUsername) === "") {
394
+				throw new ApplicationLogicException('The new username cannot be empty');
395
+			}
396
+
397
+			if (User::getByUsername($newUsername, $database) != false) {
398
+				throw new ApplicationLogicException('The new username already exists');
399
+			}
400
+
401
+			$oldUsername = $user->getUsername();
402
+			$user->setUsername($newUsername);
403
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
404
+
405
+			$user->save();
406
+
407
+			$logEntryData = serialize(array(
408
+				'old' => $oldUsername,
409
+				'new' => $newUsername,
410
+			));
411
+
412
+			Logger::renamedUser($database, $user, $logEntryData);
413
+
414
+			SessionAlert::quick("Changed User "
415
+				. htmlentities($oldUsername, ENT_COMPAT, 'UTF-8')
416
+				. " name to "
417
+				. htmlentities($newUsername, ENT_COMPAT, 'UTF-8'));
418
+
419
+			$this->getNotificationHelper()->userRenamed($user, $oldUsername);
420
+
421
+			// send an email to the user.
422
+			$this->assign('targetUsername', $user->getUsername());
423
+			$this->assign('toolAdmin', User::getCurrent($database)->getUsername());
424
+			$this->assign('oldUsername', $oldUsername);
425
+			$this->assign('mailingList', $this->adminMailingList);
426
+
427
+			$this->getEmailHelper()->sendMail(
428
+				$user->getEmail(),
429
+				'Your username on WP:ACC has been changed',
430
+				$this->fetchTemplate('usermanagement/emails/renamed.tpl'),
431
+				array('Reply-To' => $this->adminMailingList)
432
+			);
433
+
434
+			$this->redirect("userManagement");
435
+
436
+			return;
437
+		}
438
+		else {
439
+			$this->assignCSRFToken();
440
+			$this->setTemplate('usermanagement/renameuser.tpl');
441
+			$this->assign('user', $user);
442
+		}
443
+	}
444
+
445
+	/**
446
+	 * Entry point for the edit action
447
+	 *
448
+	 * @throws ApplicationLogicException
449
+	 */
450
+	protected function editUser()
451
+	{
452
+		$this->setHtmlTitle('User Management');
453
+
454
+		$database = $this->getDatabase();
455
+
456
+		$userId = WebRequest::getInt('user');
457
+		$user = User::getById($userId, $database);
458
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
459
+
460
+		if ($user === false) {
461
+			throw new ApplicationLogicException('Sorry, the user you are trying to edit could not be found.');
462
+		}
463
+
464
+		// Dual-mode action
465
+		if (WebRequest::wasPosted()) {
466
+			$this->validateCSRFToken();
467
+			$newEmail = WebRequest::postEmail('user_email');
468
+			$newOnWikiName = WebRequest::postString('user_onwikiname');
469
+
470
+			if ($newEmail === null) {
471
+				throw new ApplicationLogicException('Invalid email address');
472
+			}
473
+
474
+			if (!$oauth->isFullyLinked()) {
475
+				if (trim($newOnWikiName) == "") {
476
+					throw new ApplicationLogicException('New on-wiki username cannot be blank');
477
+				}
478
+
479
+				$user->setOnWikiName($newOnWikiName);
480
+			}
481
+
482
+			$user->setEmail($newEmail);
483
+
484
+			$user->setUpdateVersion(WebRequest::postInt('updateversion'));
485
+
486
+			$user->save();
487
+
488
+			Logger::userPreferencesChange($database, $user);
489
+			$this->getNotificationHelper()->userPrefChange($user);
490
+			SessionAlert::quick('Changes to user\'s preferences have been saved');
491
+
492
+			$this->redirect("userManagement");
493
+
494
+			return;
495
+		}
496
+		else {
497
+			$this->assignCSRFToken();
498
+			$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
499
+				$this->getSiteConfiguration());
500
+			$this->setTemplate('usermanagement/edituser.tpl');
501
+			$this->assign('user', $user);
502
+			$this->assign('oauth', $oauth);
503
+		}
504
+	}
505
+
506
+	#endregion
507
+
508
+	/**
509
+	 * Sends a status change email to the user.
510
+	 *
511
+	 * @param string      $subject           The subject of the email
512
+	 * @param string      $template          The smarty template to use
513
+	 * @param string|null $reason            The reason for performing the status change
514
+	 * @param User        $user              The user affected
515
+	 * @param string      $toolAdminUsername The tool admin's username who is making the edit
516
+	 */
517
+	private function sendStatusChangeEmail($subject, $template, $reason, $user, $toolAdminUsername)
518
+	{
519
+		$this->assign('targetUsername', $user->getUsername());
520
+		$this->assign('toolAdmin', $toolAdminUsername);
521
+		$this->assign('actionReason', $reason);
522
+		$this->assign('mailingList', $this->adminMailingList);
523
+
524
+		$this->getEmailHelper()->sendMail(
525
+			$user->getEmail(),
526
+			$subject,
527
+			$this->fetchTemplate($template),
528
+			array('Reply-To' => $this->adminMailingList)
529
+		);
530
+	}
531
+
532
+	/**
533
+	 * @param UserRole[] $activeRoles
534
+	 *
535
+	 * @return array
536
+	 */
537
+	private function getRoleData($activeRoles)
538
+	{
539
+		$availableRoles = $this->getSecurityManager()->getRoleConfiguration()->getAvailableRoles();
540
+
541
+		$currentUser = User::getCurrent($this->getDatabase());
542
+		$this->getSecurityManager()->getActiveRoles($currentUser, $userRoles, $inactiveRoles);
543
+
544
+		$initialValue = array('active' => 0, 'allowEdit' => 0, 'description' => '???', 'object' => null);
545
+
546
+		$roleData = array();
547
+		foreach ($availableRoles as $role => $data) {
548
+			$intersection = array_intersect($data['editableBy'], $userRoles);
549
+
550
+			$roleData[$role] = $initialValue;
551
+			$roleData[$role]['allowEdit'] = count($intersection) > 0 ? 1 : 0;
552
+			$roleData[$role]['description'] = $data['description'];
553
+		}
554
+
555
+		foreach ($activeRoles as $role) {
556
+			if (!isset($roleData[$role->getRole()])) {
557
+				// This value is no longer available in the configuration, allow changing (aka removing) it.
558
+				$roleData[$role->getRole()] = $initialValue;
559
+				$roleData[$role->getRole()]['allowEdit'] = 1;
560
+			}
561
+
562
+			$roleData[$role->getRole()]['object'] = $role;
563
+			$roleData[$role->getRole()]['active'] = 1;
564
+		}
565
+
566
+		return $roleData;
567
+	}
568 568
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
                     continue;
128 128
                 }
129 129
 
130
-                $newValue = WebRequest::postBoolean('role-' . $name) ? 1 : 0;
130
+                $newValue = WebRequest::postBoolean('role-'.$name) ? 1 : 0;
131 131
                 if ($newValue !== $r['active']) {
132 132
                     if ($newValue === 0) {
133 133
                         $delete[] = $r['object'];
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
             $user->save();
171 171
 
172 172
             $this->getNotificationHelper()->userRolesEdited($user, $reason);
173
-            SessionAlert::quick('Roles changed for user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
173
+            SessionAlert::quick('Roles changed for user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
174 174
 
175 175
             $this->redirect('statistics/users', 'detail', array('user' => $user->getId()));
176 176
 
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
             Logger::suspendedUser($database, $user, $reason);
224 224
 
225 225
             $this->getNotificationHelper()->userSuspended($user, $reason);
226
-            SessionAlert::quick('Suspended user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
226
+            SessionAlert::quick('Suspended user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
227 227
 
228 228
             // send email
229 229
             $this->sendStatusChangeEmail(
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
             Logger::declinedUser($database, $user, $reason);
285 285
 
286 286
             $this->getNotificationHelper()->userDeclined($user, $reason);
287
-            SessionAlert::quick('Declined user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
287
+            SessionAlert::quick('Declined user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
288 288
 
289 289
             // send email
290 290
             $this->sendStatusChangeEmail(
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
             Logger::approvedUser($database, $user);
340 340
 
341 341
             $this->getNotificationHelper()->userApproved($user);
342
-            SessionAlert::quick('Approved user ' . htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
342
+            SessionAlert::quick('Approved user '.htmlentities($user->getUsername(), ENT_COMPAT, 'UTF-8'));
343 343
 
344 344
             // send email
345 345
             $this->sendStatusChangeEmail(
Please login to merge, or discard this patch.
includes/Pages/PageLog.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -18,54 +18,54 @@
 block discarded – undo
18 18
 
19 19
 class PageLog extends PagedInternalPageBase
20 20
 {
21
-    /**
22
-     * Main function for this page, when no specific actions are called.
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Logs');
21
+	/**
22
+	 * Main function for this page, when no specific actions are called.
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Logs');
27 27
 
28
-        $filterUser = WebRequest::getString('filterUser');
29
-        $filterAction = WebRequest::getString('filterAction');
30
-        $filterObjectType = WebRequest::getString('filterObjectType');
31
-        $filterObjectId = WebRequest::getInt('filterObjectId');
28
+		$filterUser = WebRequest::getString('filterUser');
29
+		$filterAction = WebRequest::getString('filterAction');
30
+		$filterObjectType = WebRequest::getString('filterObjectType');
31
+		$filterObjectId = WebRequest::getInt('filterObjectId');
32 32
 
33
-        $database = $this->getDatabase();
33
+		$database = $this->getDatabase();
34 34
 
35
-        if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
36
-            $filterObjectType = null;
37
-        }
35
+		if (!array_key_exists($filterObjectType, LogHelper::getObjectTypes())) {
36
+			$filterObjectType = null;
37
+		}
38 38
 
39
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
40
-            return UserSearchHelper::get($database)->fetchColumn('username');
41
-        });
39
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
40
+			return UserSearchHelper::get($database)->fetchColumn('username');
41
+		});
42 42
 
43
-        $logSearch = LogSearchHelper::get($database);
43
+		$logSearch = LogSearchHelper::get($database);
44 44
 
45
-        $this->setSearchHelper($logSearch);
46
-        $this->setupLimits();
45
+		$this->setSearchHelper($logSearch);
46
+		$this->setupLimits();
47 47
 
48 48
 
49
-        /** @var Log[] $logs */
50
-        $logs = $logSearch->getRecordCount($count)->fetch();
49
+		/** @var Log[] $logs */
50
+		$logs = $logSearch->getRecordCount($count)->fetch();
51 51
 
52
-        if ($count === 0) {
53
-            $this->assign('logs', array());
54
-            $this->setTemplate('logs/main.tpl');
52
+		if ($count === 0) {
53
+			$this->assign('logs', array());
54
+			$this->setTemplate('logs/main.tpl');
55 55
 
56
-            return;
57
-        }
56
+			return;
57
+		}
58 58
 
59
-        list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
59
+		list($users, $logData) = LogHelper::prepareLogsForTemplate($logs, $database, $this->getSiteConfiguration());
60 60
 
61
-        $this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
61
+		$this->setupPageData($count, array('filterUser' => $filterUser, 'filterAction' => $filterAction, 'filterObjectType' => $filterObjectType, 'filterObjectId' => $filterObjectId));
62 62
 
63
-        $this->assign("logs", $logData);
64
-        $this->assign("users", $users);
63
+		$this->assign("logs", $logData);
64
+		$this->assign("users", $users);
65 65
 
66
-        $this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
67
-        $this->assign('allObjectTypes', LogHelper::getObjectTypes());
66
+		$this->assign('allLogActions', LogHelper::getLogActions($this->getDatabase()));
67
+		$this->assign('allObjectTypes', LogHelper::getObjectTypes());
68 68
 
69
-        $this->setTemplate("logs/main.tpl");
70
-    }
69
+		$this->setTemplate("logs/main.tpl");
70
+	}
71 71
 }
Please login to merge, or discard this patch.
includes/Pages/PageViewRequest.php 3 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -25,72 +25,72 @@  discard block
 block discarded – undo
25 25
 
26 26
 class PageViewRequest extends InternalPageBase
27 27
 {
28
-    use RequestData;
29
-    const STATUS_SYMBOL_OPEN = '&#x2610';
30
-    const STATUS_SYMBOL_ACCEPTED = '&#x2611';
31
-    const STATUS_SYMBOL_REJECTED = '&#x2612';
32
-
33
-    /**
34
-     * Main function for this page, when no specific actions are called.
35
-     * @throws ApplicationLogicException
36
-     */
37
-    protected function main()
38
-    {
39
-        // set up csrf protection
40
-        $this->assignCSRFToken();
41
-
42
-        // get some useful objects
43
-        $database = $this->getDatabase();
44
-        $request = $this->getRequest($database, WebRequest::getInt('id'));
45
-        $config = $this->getSiteConfiguration();
46
-        $currentUser = User::getCurrent($database);
47
-
48
-        // Test we should be able to look at this request
49
-        if ($config->getEmailConfirmationEnabled()) {
50
-            if ($request->getEmailConfirm() !== 'Confirmed') {
51
-                // Not allowed to look at this yet.
52
-                throw new ApplicationLogicException('The email address has not yet been confirmed for this request.');
53
-            }
54
-        }
55
-
56
-        $this->setupBasicData($request, $config);
57
-
58
-        $this->setupUsernameData($request);
59
-
60
-        $this->setupTitle($request);
61
-
62
-        $this->setupReservationDetails($request->getReserved(), $database, $currentUser);
63
-        $this->setupGeneralData($database);
64
-
65
-        $this->assign('requestDataCleared', false);
66
-        if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
67
-            $this->assign('requestDataCleared', true);
68
-        }
69
-
70
-        $allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
71
-
72
-        $this->setupCreationTypes($currentUser);
73
-
74
-        $this->setupLogData($request, $database);
75
-
76
-        if ($allowedPrivateData) {
77
-            $this->setTemplate('view-request/main-with-data.tpl');
78
-            $this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
79
-
80
-            $this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class));
81
-            $this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData'));
82
-
83
-            if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) {
84
-                $this->setTemplate('view-request/main-with-checkuser-data.tpl');
85
-                $this->setupCheckUserData($request);
86
-            }
87
-        }
88
-        else {
89
-            $this->setTemplate('view-request/main.tpl');
90
-        }
91
-
92
-        /** @noinspection JSUnusedGlobalSymbols */
93
-        $this->setTailScript(<<<'JS'
28
+	use RequestData;
29
+	const STATUS_SYMBOL_OPEN = '&#x2610';
30
+	const STATUS_SYMBOL_ACCEPTED = '&#x2611';
31
+	const STATUS_SYMBOL_REJECTED = '&#x2612';
32
+
33
+	/**
34
+	 * Main function for this page, when no specific actions are called.
35
+	 * @throws ApplicationLogicException
36
+	 */
37
+	protected function main()
38
+	{
39
+		// set up csrf protection
40
+		$this->assignCSRFToken();
41
+
42
+		// get some useful objects
43
+		$database = $this->getDatabase();
44
+		$request = $this->getRequest($database, WebRequest::getInt('id'));
45
+		$config = $this->getSiteConfiguration();
46
+		$currentUser = User::getCurrent($database);
47
+
48
+		// Test we should be able to look at this request
49
+		if ($config->getEmailConfirmationEnabled()) {
50
+			if ($request->getEmailConfirm() !== 'Confirmed') {
51
+				// Not allowed to look at this yet.
52
+				throw new ApplicationLogicException('The email address has not yet been confirmed for this request.');
53
+			}
54
+		}
55
+
56
+		$this->setupBasicData($request, $config);
57
+
58
+		$this->setupUsernameData($request);
59
+
60
+		$this->setupTitle($request);
61
+
62
+		$this->setupReservationDetails($request->getReserved(), $database, $currentUser);
63
+		$this->setupGeneralData($database);
64
+
65
+		$this->assign('requestDataCleared', false);
66
+		if ($request->getEmail() === $this->getSiteConfiguration()->getDataClearEmail()) {
67
+			$this->assign('requestDataCleared', true);
68
+		}
69
+
70
+		$allowedPrivateData = $this->isAllowedPrivateData($request, $currentUser);
71
+
72
+		$this->setupCreationTypes($currentUser);
73
+
74
+		$this->setupLogData($request, $database);
75
+
76
+		if ($allowedPrivateData) {
77
+			$this->setTemplate('view-request/main-with-data.tpl');
78
+			$this->setupPrivateData($request, $currentUser, $this->getSiteConfiguration(), $database);
79
+
80
+			$this->assign('canSetBan', $this->barrierTest('set', $currentUser, PageBan::class));
81
+			$this->assign('canSeeCheckuserData', $this->barrierTest('seeUserAgentData', $currentUser, 'RequestData'));
82
+
83
+			if ($this->barrierTest('seeUserAgentData', $currentUser, 'RequestData')) {
84
+				$this->setTemplate('view-request/main-with-checkuser-data.tpl');
85
+				$this->setupCheckUserData($request);
86
+			}
87
+		}
88
+		else {
89
+			$this->setTemplate('view-request/main.tpl');
90
+		}
91
+
92
+		/** @noinspection JSUnusedGlobalSymbols */
93
+		$this->setTailScript(<<<'JS'
94 94
     var $requestLogs = $('#requestLog');
95 95
     $requestLogs.scrollTop($requestLogs[0].scrollHeight);
96 96
     
@@ -112,183 +112,183 @@  discard block
 block discarded – undo
112 112
         }
113 113
     }
114 114
 JS
115
-        );
116
-    }
117
-
118
-    /**
119
-     * @param Request $request
120
-     */
121
-    protected function setupTitle(Request $request)
122
-    {
123
-        $statusSymbol = self::STATUS_SYMBOL_OPEN;
124
-        if ($request->getStatus() === 'Closed') {
125
-            if ($request->getWasCreated()) {
126
-                $statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
127
-            }
128
-            else {
129
-                $statusSymbol = self::STATUS_SYMBOL_REJECTED;
130
-            }
131
-        }
132
-
133
-        $this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
134
-    }
135
-
136
-    /**
137
-     * Sets up data unrelated to the request, such as the email template information
138
-     *
139
-     * @param PdoDatabase $database
140
-     */
141
-    protected function setupGeneralData(PdoDatabase $database)
142
-    {
143
-        $config = $this->getSiteConfiguration();
144
-
145
-        $this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
146
-
147
-        $this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
148
-
149
-        $this->assign('requestStates', $config->getRequestStates());
150
-
151
-        /** @var EmailTemplate $createdTemplate */
152
-        $createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database);
153
-
154
-        $this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
155
-        $this->assign('createdJsQuestion', $createdTemplate->getJsquestion());
156
-        $this->assign('createdId', $createdTemplate->getId());
157
-        $this->assign('createdName', $createdTemplate->getName());
158
-
159
-        $createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database);
160
-        $this->assign("createReasons", $createReasons);
161
-        $declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database);
162
-        $this->assign("declineReasons", $declineReasons);
163
-
164
-        $allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database);
165
-        $this->assign("allCreateReasons", $allCreateReasons);
166
-        $allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database);
167
-        $this->assign("allDeclineReasons", $allDeclineReasons);
168
-        $allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database);
169
-        $this->assign("allOtherReasons", $allOtherReasons);
170
-
171
-        $this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
172
-            return UserSearchHelper::get($database)->byStatus('Active')->fetchColumn('username');
173
-        });
174
-    }
175
-
176
-    private function setupLogData(Request $request, PdoDatabase $database)
177
-    {
178
-        $currentUser = User::getCurrent($database);
179
-
180
-        $logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager());
181
-        $requestLogs = array();
182
-
183
-        if (trim($request->getComment()) !== "") {
184
-            $requestLogs[] = array(
185
-                'type'     => 'comment',
186
-                'security' => 'user',
187
-                'userid'   => null,
188
-                'user'     => $request->getName(),
189
-                'entry'    => null,
190
-                'time'     => $request->getDate(),
191
-                'canedit'  => false,
192
-                'id'       => $request->getId(),
193
-                'comment'  => $request->getComment(),
194
-            );
195
-        }
196
-
197
-        /** @var User[] $nameCache */
198
-        $nameCache = array();
199
-
200
-        $editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class);
201
-
202
-        /** @var Log|Comment $entry */
203
-        foreach ($logs as $entry) {
204
-            // both log and comment have a 'user' field
205
-            if (!array_key_exists($entry->getUser(), $nameCache)) {
206
-                $entryUser = User::getById($entry->getUser(), $database);
207
-                $nameCache[$entry->getUser()] = $entryUser;
208
-            }
209
-
210
-            if ($entry instanceof Comment) {
211
-                $requestLogs[] = array(
212
-                    'type'     => 'comment',
213
-                    'security' => $entry->getVisibility(),
214
-                    'user'     => $nameCache[$entry->getUser()]->getUsername(),
215
-                    'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
216
-                    'entry'    => null,
217
-                    'time'     => $entry->getTime(),
218
-                    'canedit'  => ($editableComments || $entry->getUser() == $currentUser->getId()),
219
-                    'id'       => $entry->getId(),
220
-                    'comment'  => $entry->getComment(),
221
-                );
222
-            }
223
-
224
-            if ($entry instanceof Log) {
225
-                $invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
226
-                $entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
227
-
228
-                $entryComment = $entry->getComment();
229
-
230
-                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
231
-                    $data = unserialize($entry->getComment());
232
-                    /** @var JobQueue $job */
233
-                    $job = JobQueue::getById($data['job'], $database);
234
-                    $requestLogs[] = array(
235
-                        'type'     => 'joblog',
236
-                        'security' => 'user',
237
-                        'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
238
-                        'user'     => $entryUser->getUsername(),
239
-                        'entry'    => LogHelper::getLogDescription($entry),
240
-                        'time'     => $entry->getTimestamp(),
241
-                        'canedit'  => false,
242
-                        'id'       => $entry->getId(),
243
-                        'jobId'    => $job->getId(),
244
-                        'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
245
-                    );
246
-                } else {
247
-                    $requestLogs[] = array(
248
-                        'type'     => 'log',
249
-                        'security' => 'user',
250
-                        'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
251
-                        'user'     => $entryUser->getUsername(),
252
-                        'entry'    => LogHelper::getLogDescription($entry),
253
-                        'time'     => $entry->getTimestamp(),
254
-                        'canedit'  => false,
255
-                        'id'       => $entry->getId(),
256
-                        'comment'  => $entryComment,
257
-                    );
258
-                }
259
-            }
260
-        }
261
-
262
-        $this->assign("requestLogs", $requestLogs);
263
-    }
264
-
265
-    /**
266
-     * @param Request $request
267
-     */
268
-    protected function setupUsernameData(Request $request)
269
-    {
270
-        $blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
271
-
272
-        $this->assign('requestIsBlacklisted', $blacklistData !== false);
273
-        $this->assign('requestBlacklist', $blacklistData);
274
-
275
-        try {
276
-            $spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
277
-        }
278
-        catch (Exception $ex) {
279
-            $spoofs = $ex->getMessage();
280
-        }
281
-
282
-        $this->assign("spoofs", $spoofs);
283
-    }
284
-
285
-    private function setupCreationTypes(User $user)
286
-    {
287
-        $this->assign('canManualCreate',
288
-            $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'));
289
-        $this->assign('canOauthCreate',
290
-            $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'));
291
-        $this->assign('canBotCreate',
292
-            $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'));
293
-    }
115
+		);
116
+	}
117
+
118
+	/**
119
+	 * @param Request $request
120
+	 */
121
+	protected function setupTitle(Request $request)
122
+	{
123
+		$statusSymbol = self::STATUS_SYMBOL_OPEN;
124
+		if ($request->getStatus() === 'Closed') {
125
+			if ($request->getWasCreated()) {
126
+				$statusSymbol = self::STATUS_SYMBOL_ACCEPTED;
127
+			}
128
+			else {
129
+				$statusSymbol = self::STATUS_SYMBOL_REJECTED;
130
+			}
131
+		}
132
+
133
+		$this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
134
+	}
135
+
136
+	/**
137
+	 * Sets up data unrelated to the request, such as the email template information
138
+	 *
139
+	 * @param PdoDatabase $database
140
+	 */
141
+	protected function setupGeneralData(PdoDatabase $database)
142
+	{
143
+		$config = $this->getSiteConfiguration();
144
+
145
+		$this->assign('createAccountReason', 'Requested account at [[WP:ACC]], request #');
146
+
147
+		$this->assign('defaultRequestState', $config->getDefaultRequestStateKey());
148
+
149
+		$this->assign('requestStates', $config->getRequestStates());
150
+
151
+		/** @var EmailTemplate $createdTemplate */
152
+		$createdTemplate = EmailTemplate::getById($config->getDefaultCreatedTemplateId(), $database);
153
+
154
+		$this->assign('createdHasJsQuestion', $createdTemplate->getJsquestion() != '');
155
+		$this->assign('createdJsQuestion', $createdTemplate->getJsquestion());
156
+		$this->assign('createdId', $createdTemplate->getId());
157
+		$this->assign('createdName', $createdTemplate->getName());
158
+
159
+		$createReasons = EmailTemplate::getActiveTemplates(EmailTemplate::CREATED, $database);
160
+		$this->assign("createReasons", $createReasons);
161
+		$declineReasons = EmailTemplate::getActiveTemplates(EmailTemplate::NOT_CREATED, $database);
162
+		$this->assign("declineReasons", $declineReasons);
163
+
164
+		$allCreateReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::CREATED, $database);
165
+		$this->assign("allCreateReasons", $allCreateReasons);
166
+		$allDeclineReasons = EmailTemplate::getAllActiveTemplates(EmailTemplate::NOT_CREATED, $database);
167
+		$this->assign("allDeclineReasons", $allDeclineReasons);
168
+		$allOtherReasons = EmailTemplate::getAllActiveTemplates(false, $database);
169
+		$this->assign("allOtherReasons", $allOtherReasons);
170
+
171
+		$this->getTypeAheadHelper()->defineTypeAheadSource('username-typeahead', function() use ($database) {
172
+			return UserSearchHelper::get($database)->byStatus('Active')->fetchColumn('username');
173
+		});
174
+	}
175
+
176
+	private function setupLogData(Request $request, PdoDatabase $database)
177
+	{
178
+		$currentUser = User::getCurrent($database);
179
+
180
+		$logs = LogHelper::getRequestLogsWithComments($request->getId(), $database, $this->getSecurityManager());
181
+		$requestLogs = array();
182
+
183
+		if (trim($request->getComment()) !== "") {
184
+			$requestLogs[] = array(
185
+				'type'     => 'comment',
186
+				'security' => 'user',
187
+				'userid'   => null,
188
+				'user'     => $request->getName(),
189
+				'entry'    => null,
190
+				'time'     => $request->getDate(),
191
+				'canedit'  => false,
192
+				'id'       => $request->getId(),
193
+				'comment'  => $request->getComment(),
194
+			);
195
+		}
196
+
197
+		/** @var User[] $nameCache */
198
+		$nameCache = array();
199
+
200
+		$editableComments = $this->barrierTest('editOthers', $currentUser, PageEditComment::class);
201
+
202
+		/** @var Log|Comment $entry */
203
+		foreach ($logs as $entry) {
204
+			// both log and comment have a 'user' field
205
+			if (!array_key_exists($entry->getUser(), $nameCache)) {
206
+				$entryUser = User::getById($entry->getUser(), $database);
207
+				$nameCache[$entry->getUser()] = $entryUser;
208
+			}
209
+
210
+			if ($entry instanceof Comment) {
211
+				$requestLogs[] = array(
212
+					'type'     => 'comment',
213
+					'security' => $entry->getVisibility(),
214
+					'user'     => $nameCache[$entry->getUser()]->getUsername(),
215
+					'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
216
+					'entry'    => null,
217
+					'time'     => $entry->getTime(),
218
+					'canedit'  => ($editableComments || $entry->getUser() == $currentUser->getId()),
219
+					'id'       => $entry->getId(),
220
+					'comment'  => $entry->getComment(),
221
+				);
222
+			}
223
+
224
+			if ($entry instanceof Log) {
225
+				$invalidUserId = $entry->getUser() === -1 || $entry->getUser() === 0;
226
+				$entryUser = $invalidUserId ? User::getCommunity() : $nameCache[$entry->getUser()];
227
+
228
+				$entryComment = $entry->getComment();
229
+
230
+				if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
231
+					$data = unserialize($entry->getComment());
232
+					/** @var JobQueue $job */
233
+					$job = JobQueue::getById($data['job'], $database);
234
+					$requestLogs[] = array(
235
+						'type'     => 'joblog',
236
+						'security' => 'user',
237
+						'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
238
+						'user'     => $entryUser->getUsername(),
239
+						'entry'    => LogHelper::getLogDescription($entry),
240
+						'time'     => $entry->getTimestamp(),
241
+						'canedit'  => false,
242
+						'id'       => $entry->getId(),
243
+						'jobId'    => $job->getId(),
244
+						'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
245
+					);
246
+				} else {
247
+					$requestLogs[] = array(
248
+						'type'     => 'log',
249
+						'security' => 'user',
250
+						'userid'   => $entry->getUser() == -1 ? null : $entry->getUser(),
251
+						'user'     => $entryUser->getUsername(),
252
+						'entry'    => LogHelper::getLogDescription($entry),
253
+						'time'     => $entry->getTimestamp(),
254
+						'canedit'  => false,
255
+						'id'       => $entry->getId(),
256
+						'comment'  => $entryComment,
257
+					);
258
+				}
259
+			}
260
+		}
261
+
262
+		$this->assign("requestLogs", $requestLogs);
263
+	}
264
+
265
+	/**
266
+	 * @param Request $request
267
+	 */
268
+	protected function setupUsernameData(Request $request)
269
+	{
270
+		$blacklistData = $this->getBlacklistHelper()->isBlacklisted($request->getName());
271
+
272
+		$this->assign('requestIsBlacklisted', $blacklistData !== false);
273
+		$this->assign('requestBlacklist', $blacklistData);
274
+
275
+		try {
276
+			$spoofs = $this->getAntiSpoofProvider()->getSpoofs($request->getName());
277
+		}
278
+		catch (Exception $ex) {
279
+			$spoofs = $ex->getMessage();
280
+		}
281
+
282
+		$this->assign("spoofs", $spoofs);
283
+	}
284
+
285
+	private function setupCreationTypes(User $user)
286
+	{
287
+		$this->assign('canManualCreate',
288
+			$this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'));
289
+		$this->assign('canOauthCreate',
290
+			$this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'));
291
+		$this->assign('canBotCreate',
292
+			$this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'));
293
+	}
294 294
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
             }
131 131
         }
132 132
 
133
-        $this->setHtmlTitle($statusSymbol . ' #' . $request->getId());
133
+        $this->setHtmlTitle($statusSymbol.' #'.$request->getId());
134 134
     }
135 135
 
136 136
     /**
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
                 $entryComment = $entry->getComment();
229 229
 
230
-                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
230
+                if ($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') {
231 231
                     $data = unserialize($entry->getComment());
232 232
                     /** @var JobQueue $job */
233 233
                     $job = JobQueue::getById($data['job'], $database);
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 
228 228
                 $entryComment = $entry->getComment();
229 229
 
230
-                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest'){
230
+                if($entry->getAction() === 'JobIssueRequest' || $entry->getAction() === 'JobCompletedRequest') {
231 231
                     $data = unserialize($entry->getComment());
232 232
                     /** @var JobQueue $job */
233 233
                     $job = JobQueue::getById($data['job'], $database);
@@ -243,7 +243,8 @@  discard block
 block discarded – undo
243 243
                         'jobId'    => $job->getId(),
244 244
                         'jobDesc'  => JobQueue::getTaskDescriptions()[$job->getTask()],
245 245
                     );
246
-                } else {
246
+                }
247
+                else {
247 248
                     $requestLogs[] = array(
248 249
                         'type'     => 'log',
249 250
                         'security' => 'user',
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PagePreferences.php 3 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -16,73 +16,73 @@
 block discarded – undo
16 16
 
17 17
 class PagePreferences extends InternalPageBase
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->setHtmlTitle('Preferences');
19
+	/**
20
+	 * Main function for this page, when no specific actions are called.
21
+	 * @return void
22
+	 */
23
+	protected function main()
24
+	{
25
+		$this->setHtmlTitle('Preferences');
26 26
 
27
-        $enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth();
28
-        $database = $this->getDatabase();
29
-        $user = User::getCurrent($database);
27
+		$enforceOAuth = $this->getSiteConfiguration()->getEnforceOAuth();
28
+		$database = $this->getDatabase();
29
+		$user = User::getCurrent($database);
30 30
 
31
-        // Dual mode
32
-        if (WebRequest::wasPosted()) {
33
-            $this->validateCSRFToken();
34
-            $user->setWelcomeSig(WebRequest::postString('sig'));
35
-            $user->setEmailSig(WebRequest::postString('emailsig'));
36
-            $user->setAbortPref(WebRequest::getBoolean('sig') ? 1 : 0);
37
-            $this->setCreationMode($user);
31
+		// Dual mode
32
+		if (WebRequest::wasPosted()) {
33
+			$this->validateCSRFToken();
34
+			$user->setWelcomeSig(WebRequest::postString('sig'));
35
+			$user->setEmailSig(WebRequest::postString('emailsig'));
36
+			$user->setAbortPref(WebRequest::getBoolean('sig') ? 1 : 0);
37
+			$this->setCreationMode($user);
38 38
 
39
-            $email = WebRequest::postEmail('email');
40
-            if ($email !== null) {
41
-                $user->setEmail($email);
42
-            }
39
+			$email = WebRequest::postEmail('email');
40
+			if ($email !== null) {
41
+				$user->setEmail($email);
42
+			}
43 43
 
44
-            $user->save();
45
-            SessionAlert::success("Preferences updated!");
44
+			$user->save();
45
+			SessionAlert::success("Preferences updated!");
46 46
 
47
-            $this->redirect('');
48
-        }
49
-        else {
50
-            $this->assignCSRFToken();
51
-            $this->setTemplate('preferences/prefs.tpl');
52
-            $this->assign("enforceOAuth", $enforceOAuth);
47
+			$this->redirect('');
48
+		}
49
+		else {
50
+			$this->assignCSRFToken();
51
+			$this->setTemplate('preferences/prefs.tpl');
52
+			$this->assign("enforceOAuth", $enforceOAuth);
53 53
 
54
-            $this->assign('canManualCreate',
55
-                $this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'));
56
-            $this->assign('canOauthCreate',
57
-                $this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'));
58
-            $this->assign('canBotCreate',
59
-                $this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'));
54
+			$this->assign('canManualCreate',
55
+				$this->barrierTest(User::CREATION_MANUAL, $user, 'RequestCreation'));
56
+			$this->assign('canOauthCreate',
57
+				$this->barrierTest(User::CREATION_OAUTH, $user, 'RequestCreation'));
58
+			$this->assign('canBotCreate',
59
+				$this->barrierTest(User::CREATION_BOT, $user, 'RequestCreation'));
60 60
 
61
-            $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
62
-                $this->getSiteConfiguration());
63
-            $this->assign('oauth', $oauth);
61
+			$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(),
62
+				$this->getSiteConfiguration());
63
+			$this->assign('oauth', $oauth);
64 64
 
65
-            $identity = null;
66
-            if ($oauth->isFullyLinked()) {
67
-                $identity = $oauth->getIdentity();
68
-            }
65
+			$identity = null;
66
+			if ($oauth->isFullyLinked()) {
67
+				$identity = $oauth->getIdentity();
68
+			}
69 69
 
70
-            $this->assign('identity', $identity);
71
-            $this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime());
72
-        }
73
-    }
70
+			$this->assign('identity', $identity);
71
+			$this->assign('graceTime', $this->getSiteConfiguration()->getOauthIdentityGraceTime());
72
+		}
73
+	}
74 74
 
75
-    /**
76
-     * @param User $user
77
-     */
78
-    protected function setCreationMode(User $user)
79
-    {
80
-        // if the user is selecting a creation mode that they are not allowed, do nothing.
81
-        // this has the side effect of allowing them to keep a selected mode that either has been changed for them,
82
-        // or that they have kept from when they previously had certain access.
83
-        $creationMode = WebRequest::postInt('creationmode');
84
-        if($this->barrierTest($creationMode, $user, 'RequestCreation')){
85
-            $user->setCreationMode($creationMode);
86
-        }
87
-    }
75
+	/**
76
+	 * @param User $user
77
+	 */
78
+	protected function setCreationMode(User $user)
79
+	{
80
+		// if the user is selecting a creation mode that they are not allowed, do nothing.
81
+		// this has the side effect of allowing them to keep a selected mode that either has been changed for them,
82
+		// or that they have kept from when they previously had certain access.
83
+		$creationMode = WebRequest::postInt('creationmode');
84
+		if($this->barrierTest($creationMode, $user, 'RequestCreation')){
85
+			$user->setCreationMode($creationMode);
86
+		}
87
+	}
88 88
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@
 block discarded – undo
81 81
         // this has the side effect of allowing them to keep a selected mode that either has been changed for them,
82 82
         // or that they have kept from when they previously had certain access.
83 83
         $creationMode = WebRequest::postInt('creationmode');
84
-        if($this->barrierTest($creationMode, $user, 'RequestCreation')){
84
+        if ($this->barrierTest($creationMode, $user, 'RequestCreation')) {
85 85
             $user->setCreationMode($creationMode);
86 86
         }
87 87
     }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -81,7 +81,7 @@
 block discarded – undo
81 81
         // this has the side effect of allowing them to keep a selected mode that either has been changed for them,
82 82
         // or that they have kept from when they previously had certain access.
83 83
         $creationMode = WebRequest::postInt('creationmode');
84
-        if($this->barrierTest($creationMode, $user, 'RequestCreation')){
84
+        if($this->barrierTest($creationMode, $user, 'RequestCreation')) {
85 85
             $user->setCreationMode($creationMode);
86 86
         }
87 87
     }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageOAuth.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -21,77 +21,77 @@
 block discarded – undo
21 21
 
22 22
 class PageOAuth extends InternalPageBase
23 23
 {
24
-    /**
25
-     * Attach entry point
26
-     *
27
-     * must be posted, or will redirect to preferences
28
-     */
29
-    protected function attach()
30
-    {
31
-        if (!WebRequest::wasPosted()) {
32
-            $this->redirect('preferences');
33
-
34
-            return;
35
-        }
36
-
37
-        $database = $this->getDatabase();
38
-
39
-        $this->validateCSRFToken();
40
-
41
-        $oauthProtocolHelper = $this->getOAuthProtocolHelper();
42
-        $user = User::getCurrent($database);
43
-        $oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
44
-
45
-        try {
46
-            $authoriseUrl = $oauth->getRequestToken();
47
-            $this->redirectUrl($authoriseUrl);
48
-        }
49
-        catch (CurlException $ex) {
50
-            throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
51
-        }
52
-    }
53
-
54
-    /**
55
-     * Detach account entry point
56
-     */
57
-    protected function detach()
58
-    {
59
-        if ($this->getSiteConfiguration()->getEnforceOAuth()) {
60
-            throw new AccessDeniedException($this->getSecurityManager());
61
-        }
62
-
63
-        $database = $this->getDatabase();
64
-        $user = User::getCurrent($database);
65
-        $oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
66
-
67
-        try {
68
-            $oauth->refreshIdentity();
69
-        }
70
-        catch (CurlException $ex) {
71
-            // do nothing. The user's already revoked this access anyway.
72
-        }
73
-        catch (OAuthException $ex) {
74
-            // do nothing. The user's already revoked this access anyway.
75
-        }
76
-
77
-        $oauth->detach();
78
-
79
-        // TODO: figure out why we need to force logout after a detach.
80
-        $user->setForcelogout(true);
81
-        $user->save();
82
-
83
-        // force the user to log out
84
-        Session::destroy();
85
-
86
-        $this->redirect('login');
87
-    }
88
-
89
-    /**
90
-     * Main function for this page, when no specific actions are called.
91
-     * @return void
92
-     */
93
-    protected function main()
94
-    {
95
-        $this->redirect('preferences');
96
-    }
24
+	/**
25
+	 * Attach entry point
26
+	 *
27
+	 * must be posted, or will redirect to preferences
28
+	 */
29
+	protected function attach()
30
+	{
31
+		if (!WebRequest::wasPosted()) {
32
+			$this->redirect('preferences');
33
+
34
+			return;
35
+		}
36
+
37
+		$database = $this->getDatabase();
38
+
39
+		$this->validateCSRFToken();
40
+
41
+		$oauthProtocolHelper = $this->getOAuthProtocolHelper();
42
+		$user = User::getCurrent($database);
43
+		$oauth = new OAuthUserHelper($user, $database, $oauthProtocolHelper, $this->getSiteConfiguration());
44
+
45
+		try {
46
+			$authoriseUrl = $oauth->getRequestToken();
47
+			$this->redirectUrl($authoriseUrl);
48
+		}
49
+		catch (CurlException $ex) {
50
+			throw new ApplicationLogicException($ex->getMessage(), 0, $ex);
51
+		}
52
+	}
53
+
54
+	/**
55
+	 * Detach account entry point
56
+	 */
57
+	protected function detach()
58
+	{
59
+		if ($this->getSiteConfiguration()->getEnforceOAuth()) {
60
+			throw new AccessDeniedException($this->getSecurityManager());
61
+		}
62
+
63
+		$database = $this->getDatabase();
64
+		$user = User::getCurrent($database);
65
+		$oauth = new OAuthUserHelper($user, $database, $this->getOAuthProtocolHelper(), $this->getSiteConfiguration());
66
+
67
+		try {
68
+			$oauth->refreshIdentity();
69
+		}
70
+		catch (CurlException $ex) {
71
+			// do nothing. The user's already revoked this access anyway.
72
+		}
73
+		catch (OAuthException $ex) {
74
+			// do nothing. The user's already revoked this access anyway.
75
+		}
76
+
77
+		$oauth->detach();
78
+
79
+		// TODO: figure out why we need to force logout after a detach.
80
+		$user->setForcelogout(true);
81
+		$user->save();
82
+
83
+		// force the user to log out
84
+		Session::destroy();
85
+
86
+		$this->redirect('login');
87
+	}
88
+
89
+	/**
90
+	 * Main function for this page, when no specific actions are called.
91
+	 * @return void
92
+	 */
93
+	protected function main()
94
+	{
95
+		$this->redirect('preferences');
96
+	}
97 97
 }
Please login to merge, or discard this patch.
includes/Pages/UserAuth/PageChangePassword.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,70 +17,70 @@
 block discarded – undo
17 17
 
18 18
 class PageChangePassword extends InternalPageBase
19 19
 {
20
-    /**
21
-     * Main function for this page, when no specific actions are called.
22
-     * @return void
23
-     */
24
-    protected function main()
25
-    {
26
-        $this->setHtmlTitle('Change Password');
20
+	/**
21
+	 * Main function for this page, when no specific actions are called.
22
+	 * @return void
23
+	 */
24
+	protected function main()
25
+	{
26
+		$this->setHtmlTitle('Change Password');
27 27
 
28
-        if (WebRequest::wasPosted()) {
29
-            $this->validateCSRFToken();
30
-            try {
31
-                $oldPassword = WebRequest::postString('oldpassword');
32
-                $newPassword = WebRequest::postString('newpassword');
33
-                $newPasswordConfirmation = WebRequest::postString('newpasswordconfirm');
28
+		if (WebRequest::wasPosted()) {
29
+			$this->validateCSRFToken();
30
+			try {
31
+				$oldPassword = WebRequest::postString('oldpassword');
32
+				$newPassword = WebRequest::postString('newpassword');
33
+				$newPasswordConfirmation = WebRequest::postString('newpasswordconfirm');
34 34
 
35
-                $user = User::getCurrent($this->getDatabase());
36
-                if (!$user instanceof User) {
37
-                    throw new ApplicationLogicException('User not found');
38
-                }
35
+				$user = User::getCurrent($this->getDatabase());
36
+				if (!$user instanceof User) {
37
+					throw new ApplicationLogicException('User not found');
38
+				}
39 39
 
40
-                $this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user);
41
-            }
42
-            catch (ApplicationLogicException $ex) {
43
-                SessionAlert::error($ex->getMessage());
44
-                $this->redirect('changePassword');
40
+				$this->validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, $user);
41
+			}
42
+			catch (ApplicationLogicException $ex) {
43
+				SessionAlert::error($ex->getMessage());
44
+				$this->redirect('changePassword');
45 45
 
46
-                return;
47
-            }
46
+				return;
47
+			}
48 48
 
49
-            $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
50
-            $passwordProvider->setCredential($user, 1, $newPassword);
49
+			$passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
50
+			$passwordProvider->setCredential($user, 1, $newPassword);
51 51
 
52
-            SessionAlert::success('Password changed successfully!');
52
+			SessionAlert::success('Password changed successfully!');
53 53
 
54
-            $this->redirect('preferences');
55
-        }
56
-        else {
57
-            $this->assignCSRFToken();
58
-            $this->setTemplate('preferences/changePassword.tpl');
59
-        }
60
-    }
54
+			$this->redirect('preferences');
55
+		}
56
+		else {
57
+			$this->assignCSRFToken();
58
+			$this->setTemplate('preferences/changePassword.tpl');
59
+		}
60
+	}
61 61
 
62
-    /**
63
-     * @param string $oldPassword
64
-     * @param string $newPassword
65
-     * @param string $newPasswordConfirmation
66
-     * @param User   $user
67
-     *
68
-     * @throws ApplicationLogicException
69
-     */
70
-    protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user)
71
-    {
72
-        if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) {
73
-            throw new ApplicationLogicException('All three fields must be completed to change your password');
74
-        }
62
+	/**
63
+	 * @param string $oldPassword
64
+	 * @param string $newPassword
65
+	 * @param string $newPasswordConfirmation
66
+	 * @param User   $user
67
+	 *
68
+	 * @throws ApplicationLogicException
69
+	 */
70
+	protected function validateNewPassword($oldPassword, $newPassword, $newPasswordConfirmation, User $user)
71
+	{
72
+		if ($oldPassword === null || $newPassword === null || $newPasswordConfirmation === null) {
73
+			throw new ApplicationLogicException('All three fields must be completed to change your password');
74
+		}
75 75
 
76
-        if ($newPassword !== $newPasswordConfirmation) {
77
-            throw new ApplicationLogicException('Your new passwords did not match!');
78
-        }
76
+		if ($newPassword !== $newPasswordConfirmation) {
77
+			throw new ApplicationLogicException('Your new passwords did not match!');
78
+		}
79 79
 
80
-        // TODO: adapt for MFA support
81
-        $passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
82
-        if (!$passwordProvider->authenticate($user, $oldPassword)) {
83
-            throw new ApplicationLogicException('The password you entered was incorrect.');
84
-        }
85
-    }
80
+		// TODO: adapt for MFA support
81
+		$passwordProvider = new PasswordCredentialProvider($this->getDatabase(), $this->getSiteConfiguration());
82
+		if (!$passwordProvider->authenticate($user, $oldPassword)) {
83
+			throw new ApplicationLogicException('The password you entered was incorrect.');
84
+		}
85
+	}
86 86
 }
87 87
\ No newline at end of file
Please login to merge, or discard this patch.