BoardController::updateAcl()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[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\Deck\Controller;
25
26
use OCA\Deck\Db\Acl;
27
use OCA\Deck\Service\BoardService;
28
use OCA\Deck\Service\PermissionService;
29
use OCP\IRequest;
30
use OCP\AppFramework\Controller;
31
use OCP\IUserManager;
32
use OCP\IGroupManager;
33
34
class BoardController extends Controller {
35
	private $userId;
36
	private $boardService;
37
	private $userManager;
38
	private $groupManager;
39
	private $permissionService;
40
	private $userInfo;
41
42
	public function __construct($appName, IRequest $request, IUserManager $userManager, IGroupManager $groupManager, BoardService $boardService, PermissionService $permissionService, $userId) {
43
		parent::__construct($appName, $request);
44
		$this->userId = $userId;
45
		$this->userManager = $userManager;
46
		$this->groupManager = $groupManager;
47
		$this->boardService = $boardService;
48
		$this->permissionService = $permissionService;
49
		$this->userInfo = $this->getBoardPrerequisites();
50
	}
51
52
	/**
53
	 * TODO: move to boardservice
54
	 * @return array
55
	 */
56
	private function getBoardPrerequisites() {
57
		$groups = $this->groupManager->getUserGroupIds(
58
			$this->userManager->get($this->userId)
59
		);
60
		return [
61
			'user' => $this->userId,
62
			'groups' => $groups
63
		];
64
	}
65
66
	/**
67
	 * @NoAdminRequired
68
	 */
69
	public function index() {
70
		return $this->boardService->findAll($this->userInfo);
71
	}
72
73
	/**
74
	 * @NoAdminRequired
75
	 * @param $boardId
76
	 * @return \OCP\AppFramework\Db\Entity
77
	 */
78
	public function read($boardId) {
79
		return $this->boardService->find($boardId);
80
	}
81
82
	/**
83
	 * @NoAdminRequired
84
	 * @param $title
85
	 * @param $color
86
	 * @return \OCP\AppFramework\Db\Entity
87
	 */
88
	public function create($title, $color) {
89
		return $this->boardService->create($title, $this->userId, $color);
90
	}
91
92
	/**
93
	 * @NoAdminRequired
94
	 * @param $id
95
	 * @param $title
96
	 * @param $color
97
	 * @return \OCP\AppFramework\Db\Entity
98
	 */
99
	public function update($id, $title, $color) {
100
		return $this->boardService->update($id, $title, $color);
101
	}
102
103
	/**
104
	 * @NoAdminRequired
105
	 * @param $boardId
106
	 * @return \OCP\AppFramework\Db\Entity
107
	 */
108
	public function delete($boardId) {
109
		return $this->boardService->delete($boardId);
110
	}
111
112
	/**
113
	 * @NoAdminRequired
114
	 * @param $boardId
115
	 * @return array|bool
116
	 * @internal param $userId
117
	 */
118
	public function getUserPermissions($boardId) {
119
		$permissions = $this->permissionService->getPermissions($boardId);
120
		return [
121
			'PERMISSION_READ' => $permissions[Acl::PERMISSION_READ],
122
			'PERMISSION_EDIT' => $permissions[Acl::PERMISSION_EDIT],
123
			'PERMISSION_MANAGE' => $permissions[Acl::PERMISSION_MANAGE],
124
			'PERMISSION_SHARE' => $permissions[Acl::PERMISSION_SHARE]
125
		];
126
	}
127
128
	/**
129
	 * @NoAdminRequired
130
	 * @param $boardId
131
	 * @param $type
132
	 * @param $participant
133
	 * @param $edit
134
	 * @param $share
135
	 * @param $manage
136
	 * @return \OCP\AppFramework\Db\Entity
137
	 */
138
	public function addAcl($boardId, $type, $participant, $edit, $share, $manage) {
139
		return $this->boardService->addAcl($boardId, $type, $participant, $edit, $share, $manage);
140
	}
141
142
	/**
143
	 * @NoAdminRequired
144
	 * @param $id
145
	 * @param $permissionEdit
146
	 * @param $permissionShare
147
	 * @param $permissionManage
148
	 * @return \OCP\AppFramework\Db\Entity
149
	 */
150
	public function updateAcl($id, $permissionEdit, $permissionShare, $permissionManage) {
151
		return $this->boardService->updateAcl($id, $permissionEdit, $permissionShare, $permissionManage);
152
	}
153
154
	/**
155
	 * @NoAdminRequired
156
	 * @param $aclId
157
	 * @return \OCP\AppFramework\Db\Entity
158
	 */
159
	public function deleteAcl($aclId) {
160
		return $this->boardService->deleteAcl($aclId);
161
	}
162
163
}
164