Passed
Pull Request — master (#1169)
by René
06:00
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\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 combined list of NC users, groups and contacts
56
	 * @NoAdminRequired
57
	 * @param string $query
58
	 * @param bool $getGroups - search in groups
59
	 * @param bool $getUsers - search in site users
60
	 * @param bool $getContacts - search in contacs
61
	 * @param bool $getContactGroups - search in contacs
62
	 * @param array $skipGroups - group names to skip in return array
63
	 * @param array $skipUsers - user names to skip in return array
64
	 * @return DataResponse
65
	 */
66
	public function getSiteUsersAndGroups(
67
		$query = '',
68
		$getGroups = true,
69
		$getUsers = true,
70
		$getContacts = true,
71
		$getContactGroups = true,
72
		$getMail = false,
73
		$skipGroups = [],
74
		$skipUsers = []
75
	) {
76
		return new DataResponse(['siteusers' => $this->systemService->getSiteUsersAndGroups(
77
			$query, $getGroups, $getUsers, $getContacts, $getContactGroups, $getMail, $skipGroups, $skipUsers)], Http::STATUS_OK);
78
	}
79
80
	/**
81
	 * Validate it the user name is reservrd
82
	 * return false, if this username already exists as a user or as
83
	 * a participant of the poll
84
	 * @NoAdminRequired
85
	 * @PublicPage
86
	 * @return DataResponse
87
	 */
88
	public function validatePublicUsername($pollId, $userName, $token) {
89
		try {
90
			return new DataResponse(['result' => $this->systemService->validatePublicUsername($pollId, $userName, $token), 'name' => $userName], Http::STATUS_OK);
91
		} catch (\Exception $e) {
92
			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\ShareAlreadyExists or OCA\Polls\Exceptions\ContactGroupNotFound or OCA\Polls\Exceptions\BadRequestException or OCA\Polls\Exceptions\InvalidPollTypeException or OCA\Polls\Exceptions\InvalidShowResultsException or OCA\Polls\Exceptions\MultipleContactsFound or OCA\Polls\Exceptions\InvalidEmailAddress or OCA\Polls\Exceptions\ContactsNotEnabled or OCA\Polls\Exceptions\InvalidAccessException or OCA\Polls\Exceptions\TooShortException or OCA\Polls\Exceptions\CirclesNotEnabled 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

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