Passed
Pull Request — master (#1128)
by René
04:35
created

SystemController::getSiteUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 2
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 2
crap 2
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\ContactsService;
30
use OCA\Polls\Service\SystemService;
31
32
use OCP\IRequest;
33
34
class SystemController extends Controller {
35
36
	/** @var ContactsService */
37
	private $contactsService;
38
39
	/** @var SystemService */
40
	private $systemService;
41
42
	/**
43
	 * SystemController constructor.
44
	 * @param string $appName
45
	 * @param IRequest $request
46
	 * @param SystemService $systemService
47
	 * @param ContactsService $contactsService
48
	 */
49
50
	public function __construct(
51
		string $appName,
52
		IRequest $request,
53
		ContactsService $contactsService,
54
		SystemService $systemService
55
	) {
56
		parent::__construct($appName, $request);
57
		$this->contactsService = $contactsService;
58
		$this->systemService = $systemService;
59
	}
60
61
	/**
62
	 * Get a combined list of NC users, groups and contacts
63
	 * @NoAdminRequired
64
	 * @param string $query
65
	 * @param bool $getGroups - search in groups
66
	 * @param bool $getUsers - search in site users
67
	 * @param bool $getContacts - search in contacs
68
	 * @param bool $getContactGroups - search in contacs
69
	 * @param array $skipGroups - group names to skip in return array
70
	 * @param array $skipUsers - user names to skip in return array
71
	 * @return DataResponse
72
	 */
73
	public function getSiteUsersAndGroups(
74
		$query = '',
75
		$getGroups = true,
76
		$getUsers = true,
77
		$getContacts = true,
78
		$getContactGroups = true,
79
		$getMail = false,
80
		$skipGroups = [],
81
		$skipUsers = []
82
	) {
83
		return new DataResponse(['siteusers' => $this->systemService->getSiteUsersAndGroups(
84
			$query, $getGroups, $getUsers, $getContacts, $getContactGroups, $getMail, $skipGroups, $skipUsers)], Http::STATUS_OK);
85
	}
86
87
	/**
88
	 * Validate it the user name is reservrd
89
	 * return false, if this username already exists as a user or as
90
	 * a participant of the poll
91
	 * @NoAdminRequired
92
	 * @PublicPage
93
	 * @return DataResponse
94
	 */
95
	public function validatePublicUsername($pollId, $userName, $token) {
96
		try {
97
			return new DataResponse(['result' => $this->systemService->validatePublicUsername($pollId, $userName, $token), 'name' => $userName], Http::STATUS_OK);
98
		} catch (\Exception $e) {
99
			return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
0 ignored issues
show
Bug introduced by
The method getStatus() does not exist on Exception. It seems like you code against a sub-type of Exception such as OCA\Polls\Exceptions\InvalidShareType or OCA\Polls\Exceptions\EmptyTitleException or OCA\Polls\Exceptions\InvalidUsernameException or OCA\Polls\Exceptions\BadRequestException or OCA\Polls\Exceptions\InvalidPollTypeException or OCA\Polls\Exceptions\InvalidShowResultsException or OCA\Polls\Exceptions\InvalidEmailAddress or OCA\Polls\Exceptions\InvalidAccessException or OCA\Polls\Exceptions\TooShortException or OCA\Polls\Exceptions\NotAuthorizedException or OCA\Polls\Exceptions\DuplicateEntryException. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
			return new DataResponse(['error' => $e->getMessage()], $e->/** @scrutinizer ignore-call */ getStatus());
Loading history...
100
		}
101
	}
102
103
	/**
104
	 * Validate email address (simple validation)
105
	 * @NoAdminRequired
106
	 * @PublicPage
107
	 * @return DataResponse
108
	 */
109
	public function validateEmailAddress($emailAddress) {
110
		try {
111
			return new DataResponse(['result' => $this->systemService->validateEmailAddress($emailAddress), 'emailAddress' => $emailAddress], Http::STATUS_OK);
112
		} catch (\Exception $e) {
113
			return new DataResponse(['error' => $e->getMessage()], $e->getStatus());
114
		}
115
	}
116
}
117