PermissionManager   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 38
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A splitGroups() 0 3 1
A isEnabledForUser() 0 16 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 2017 Lukas Reschke <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace OCA\Richdocuments;
23
24
use OCA\Richdocuments\AppInfo\Application;
25
use OCP\IConfig;
26
use OCP\IGroupManager;
27
use OCP\IUser;
28
29
class PermissionManager {
30
31
	/** @var IConfig */
32
	private $config;
33
	/** @var IGroupManager */
34
	private $groupManager;
35
36 3
	public function __construct(IConfig $config,
37
								IGroupManager $groupManager) {
38 3
		$this->config = $config;
39 3
		$this->groupManager = $groupManager;
40 3
	}
41
42
	/**
43
	 * @param string $groupString
44
	 * @return array
45
	 */
46 2
	private function splitGroups($groupString) {
47 2
		return explode('|', $groupString);
48
	}
49
50 3
	public function isEnabledForUser(IUser $user) {
51 3
		$enabledForGroups = $this->config->getAppValue(Application::APPNAME, 'use_groups', '');
52 3
		if($enabledForGroups === '') {
53 1
			return true;
54
		}
55
56 2
		$groups = $this->splitGroups($enabledForGroups);
57 2
		$uid = $user->getUID();
58 2
		foreach($groups as $group) {
59 2
			if($this->groupManager->isInGroup($uid, $group)) {
60 1
				return true;
61
			}
62
		}
63
64 1
		return false;
65
	}
66
}
67