Passed
Pull Request — master (#1480)
by Julius
03:11
created

BoardController::clone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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