Completed
Pull Request — master (#1038)
by René
06:20
created

SystemController::getSiteUsersAndGroups()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 12
ccs 0
cts 12
cp 0
rs 10
cc 1
nc 1
nop 8
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Vinzenz Rosenkranz <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Controller;
25
26
use OCP\AppFramework\Controller;
27
use OCP\AppFramework\Http;
28
use OCP\AppFramework\Http\DataResponse;
29
use OCA\Polls\Service\SystemService;
30
31
use OCP\IRequest;
32
33
class SystemController extends Controller {
34
35
	/** @var SystemService */
36
	private $systemService;
37
38
	/**
39
	 * SystemController constructor.
40
	 * @param string $appName
41
	 * @param IRequest $request
42
	 * @param SystemService $systemService
43
	 */
44
45
	public function __construct(
46
		string $appName,
47
		IRequest $request,
48
		SystemService $systemService
49
	) {
50
		parent::__construct($appName, $request);
51
		$this->systemService = $systemService;
52
	}
53
54
	/**
55
	 * Get a list of users
56
	 * @NoAdminRequired
57
	 * @param string $query
58
	 * @param array $skipUsers - usernames to skip in return array
59
	 * @return DataResponse
60
	 */
61
	public function getSiteUsers($query = '', $skipUsers = []) {
62
		return new DataResponse(['users' => $this->systemService->getSiteUsers($query, $skipUsers)], Http::STATUS_OK);
63
	}
64
65
	/**
66
	 * Get a list of user groups
67
	 * @NoAdminRequired
68
	 * @param string $query
69
	 * @param array $skipGroups - group names to skip in return array
70
	 * @return DataResponse
71
	 */
72
	public function getSiteGroups($query = '', $skipGroups = []) {
73
		return new DataResponse(['groups' => $this->systemService->getSiteGroups($query, $skipGroups)], Http::STATUS_OK);
74
	}
75
76
	/**
77
	 * Get a list of contacts
78
	 * @NoAdminRequired
79
	 * @param string $query
80
	 * @return DataResponse
81
	 */
82
	public function getContacts($query = '') {
83
		return new DataResponse(['contacts' => $this->systemService->getContacts($query)], Http::STATUS_OK);
84
	}
85
86
	/**
87
	 * Get a list of contact groups
88
	 * @NoAdminRequired
89
	 * @param string $query
90
	 * @return DataResponse
91
	 */
92
	public function getContactsGroups($query = '') {
93
		return new DataResponse(['contactGroups' => $this->systemService->getContactsGroups($query)], Http::STATUS_OK);
94
	}
95
96
97
	/**
98
	 * Get a combined list of NC users, groups and contacts
99
	 * @NoAdminRequired
100
	 * @param string $query
101
	 * @param bool $getGroups - search in groups
102
	 * @param bool $getUsers - search in site users
103
	 * @param bool $getContacts - search in contacs
104
	 * @param bool $getContactGroups - search in contacs
105
	 * @param array $skipGroups - group names to skip in return array
106
	 * @param array $skipUsers - user names to skip in return array
107
	 * @return DataResponse
108
	 */
109
	public function getSiteUsersAndGroups(
110
		$query = '',
111
		$getGroups = true,
112
		$getUsers = true,
113
		$getContacts = true,
114
		$getContactGroups = true,
115
		$getMail = false,
116
		$skipGroups = [],
117
		$skipUsers = []
118
	) {
119
		return new DataResponse(['siteusers' => $this->systemService->getSiteUsersAndGroups(
120
			$query, $getGroups, $getUsers, $getContacts, $getContactGroups, $getMail, $skipGroups, $skipUsers)], Http::STATUS_OK);
121
	}
122
123
	/**
124
	 * Validate it the user name is reservrd
125
	 * return false, if this username already exists as a user or as
126
	 * a participant of the poll
127
	 * @NoAdminRequired
128
	 * @PublicPage
129
	 * @return DataResponse
130
	 */
131
	public function validatePublicUsername($pollId, $userName, $token) {
132
		return new DataResponse(['result' => $this->systemService->validatePublicUsername($pollId, $userName, $token), 'name' => $userName], Http::STATUS_OK);
133
	}
134
}
135