Completed
Push — master ( 418b5a...9bf62d )
by Andras
02:31
created

PermissionManager   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

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 OCP\IConfig;
25
use OCP\IGroupManager;
26
use OCP\IUser;
27
28
class PermissionManager {
29
	const APP_ID = 'richdocuments';
30
	/** @var IConfig */
31
	private $config;
32
	/** @var IGroupManager */
33
	private $groupManager;
34
35
	public function __construct(IConfig $config,
36
								IGroupManager $groupManager) {
37
		$this->config = $config;
38
		$this->groupManager = $groupManager;
39
	}
40
41
	/**
42
	 * @param string $groupString
43
	 * @return array
44
	 */
45
	private function splitGroups($groupString) {
46
		return explode('|', $groupString);
47
	}
48
49
	public function isEnabledForUser(IUser $user) {
50
		$enabledForGroups = $this->config->getAppValue(self::APP_ID, 'use_groups', '');
51
		if($enabledForGroups === '') {
52
			return true;
53
		}
54
55
		$groups = $this->splitGroups($enabledForGroups);
56
		$uid = $user->getUID();
57
		foreach($groups as $group) {
58
			if($this->groupManager->isInGroup($uid, $group)) {
59
				return true;
60
			}
61
		}
62
63
		return false;
64
	}
65
}
66