Passed
Push — master ( 64ec5e...ddd39f )
by Roeland
28:49 queued 15:55
created

DocumentAccess   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 303
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 303
rs 10
c 0
b 0
f 0
wmc 20

20 Methods

Rating   Name   Duplication   Size   Complexity  
A setOwnerId() 0 4 1
A addCircle() 0 4 1
A getGroups() 0 2 1
A addUser() 0 4 1
A addGroup() 0 4 1
A getCircles() 0 2 1
A addCircles() 0 4 1
A addUsers() 0 4 1
A setViewerId() 0 4 1
A setLinks() 0 4 1
A setGroups() 0 4 1
A jsonSerialize() 0 8 1
A setUsers() 0 4 1
A getLinks() 0 2 1
A getOwnerId() 0 2 1
A getViewerId() 0 2 1
A setCircles() 0 4 1
A addGroups() 0 4 1
A __construct() 0 2 1
A getUsers() 0 2 1
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * FullTextSearch - Full text search framework for Nextcloud
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCP\FullTextSearch\Model;
32
33
34
use JsonSerializable;
35
36
37
/**
38
 * Class DocumentAccess
39
 *
40
 * This object is used as a data transfer object when
41
 *
42
 * - indexing a document,
43
 * - generating a search request.
44
 *
45
 * During the index, it is used to define which users, groups, circles, ...
46
 * have access to the IndexDocument
47
 *
48
 * During the search, it is internally use to define to which group, circles, ...
49
 * a user that perform the search belongs to.
50
 *
51
 * @see IndexDocument::setAccess
52
 *
53
 * @since 15.0.0
54
 *
55
 * @package OCP\FullTextSearch\Model
56
 */
57
final class DocumentAccess implements JsonSerializable {
58
59
	/** @var string */
60
	private $ownerId;
61
62
	/** @var string */
63
	private $viewerId = '';
64
65
	/** @var array */
66
	private $users = [];
67
68
	/** @var array */
69
	private $groups = [];
70
71
	/** @var array */
72
	private $circles = [];
73
74
	/** @var array */
75
	private $links = [];
76
77
78
	/**
79
	 * Owner of the document can be set at the init of the object.
80
	 *
81
	 * @since 15.0.0
82
	 *
83
	 * DocumentAccess constructor.
84
	 *
85
	 * @param string $ownerId
86
	 */
87
	public function __construct(string $ownerId = '') {
88
		$this->setOwnerId($ownerId);
89
	}
90
91
92
	/**
93
	 * Set the Owner of the document.
94
	 *
95
	 * @since 15.0.0
96
	 *
97
	 * @param string $ownerId
98
	 *
99
	 * @return DocumentAccess
100
	 */
101
	public function setOwnerId(string $ownerId) {
102
		$this->ownerId = $ownerId;
103
104
		return $this;
105
	}
106
107
	/**
108
	 * Get the Owner of the document.
109
	 *
110
	 * @since 15.0.0
111
	 *
112
	 * @return string
113
	 */
114
	public function getOwnerId(): string {
115
		return $this->ownerId;
116
	}
117
118
119
	/**
120
	 * Set the viewer of the document.
121
	 *
122
	 * @since 15.0.0
123
	 *
124
	 * @param string $viewerId
125
	 *
126
	 * @return DocumentAccess
127
	 */
128
	public function setViewerId(string $viewerId): DocumentAccess {
129
		$this->viewerId = $viewerId;
130
131
		return $this;
132
	}
133
134
	/**
135
	 * Get the viewer of the document.
136
	 *
137
	 * @since 15.0.0
138
	 *
139
	 * @return string
140
	 */
141
	public function getViewerId(): string {
142
		return $this->viewerId;
143
	}
144
145
146
	/**
147
	 * Set the list of users that have read access to the document.
148
	 *
149
	 * @since 15.0.0
150
	 *
151
	 * @param array $users
152
	 *
153
	 * @return DocumentAccess
154
	 */
155
	public function setUsers(array $users): DocumentAccess {
156
		$this->users = $users;
157
158
		return $this;
159
	}
160
161
	/**
162
	 * Add an entry to the list of users that have read access to the document.
163
	 *
164
	 * @since 15.0.0
165
	 *
166
	 * @param string $user
167
	 *
168
	 * @return DocumentAccess
169
	 */
170
	public function addUser(string $user): DocumentAccess {
171
		$this->users[] = $user;
172
173
		return $this;
174
	}
175
176
	/**
177
	 * Add multiple entries to the list of users that have read access to the
178
	 * document.
179
	 *
180
	 * @since 15.0.0
181
	 *
182
	 * @param array $users
183
	 *
184
	 * @return DocumentAccess
185
	 */
186
	public function addUsers($users): DocumentAccess {
187
		$this->users = array_merge($this->users, $users);
188
189
		return $this;
190
	}
191
192
	/**
193
	 * Get the complete list of users that have read access to the document.
194
	 *
195
	 * @since 15.0.0
196
	 *
197
	 * @return array
198
	 */
199
	public function getUsers(): array {
200
		return $this->users;
201
	}
202
203
204
	/**
205
	 * Set the list of groups that have read access to the document.
206
	 *
207
	 * @since 15.0.0
208
	 *
209
	 * @param array $groups
210
	 *
211
	 * @return DocumentAccess
212
	 */
213
	public function setGroups(array $groups): DocumentAccess {
214
		$this->groups = $groups;
215
216
		return $this;
217
	}
218
219
	/**
220
	 * Add an entry to the list of groups that have read access to the document.
221
	 *
222
	 * @since 15.0.0
223
	 *
224
	 * @param string $group
225
	 *
226
	 * @return DocumentAccess
227
	 */
228
	public function addGroup(string $group): DocumentAccess {
229
		$this->groups[] = $group;
230
231
		return $this;
232
	}
233
234
	/**
235
	 * Add multiple entries to the list of groups that have read access to the
236
	 * document.
237
	 *
238
	 * @since 15.0.0
239
	 *
240
	 * @param array $groups
241
	 *
242
	 * @return DocumentAccess
243
	 */
244
	public function addGroups(array $groups) {
245
		$this->groups = array_merge($this->groups, $groups);
246
247
		return $this;
248
	}
249
250
	/**
251
	 * Get the complete list of groups that have read access to the document.
252
	 *
253
	 * @since 15.0.0
254
	 *
255
	 * @return array
256
	 */
257
	public function getGroups(): array {
258
		return $this->groups;
259
	}
260
261
262
	/**
263
	 * Set the list of circles that have read access to the document.
264
	 *
265
	 * @since 15.0.0
266
	 *
267
	 * @param array $circles
268
	 *
269
	 * @return DocumentAccess
270
	 */
271
	public function setCircles(array $circles): DocumentAccess {
272
		$this->circles = $circles;
273
274
		return $this;
275
	}
276
277
	/**
278
	 * Add an entry to the list of circles that have read access to the document.
279
	 *
280
	 * @since 15.0.0
281
	 *
282
	 * @param string $circle
283
	 *
284
	 * @return DocumentAccess
285
	 */
286
	public function addCircle(string $circle): DocumentAccess {
287
		$this->circles[] = $circle;
288
289
		return $this;
290
	}
291
292
	/**
293
	 * Add multiple entries to the list of groups that have read access to the
294
	 * document.
295
	 *
296
	 * @since 15.0.0
297
	 *
298
	 * @param array $circles
299
	 *
300
	 * @return DocumentAccess
301
	 */
302
	public function addCircles(array $circles): DocumentAccess {
303
		$this->circles = array_merge($this->circles, $circles);
304
305
		return $this;
306
	}
307
308
	/**
309
	 * Get the complete list of circles that have read access to the document.
310
	 *
311
	 * @since 15.0.0
312
	 *
313
	 * @return array
314
	 */
315
	public function getCircles(): array {
316
		return $this->circles;
317
	}
318
319
320
	/**
321
	 * Set the list of links that have read access to the document.
322
	 *
323
	 * @since 15.0.0
324
	 *
325
	 * @param array $links
326
	 *
327
	 * @return DocumentAccess
328
	 */
329
	public function setLinks(array $links): DocumentAccess {
330
		$this->links = $links;
331
332
		return $this;
333
	}
334
335
	/**
336
	 * Get the list of links that have read access to the document.
337
	 *
338
	 * @since 15.0.0
339
	 *
340
	 * @return array
341
	 */
342
	public function getLinks(): array {
343
		return $this->links;
344
	}
345
346
347
	/**
348
	 * @since 15.0.0
349
	 *
350
	 * @return array
351
	 */
352
	public function jsonSerialize(): array {
353
		return [
354
			'ownerId' => $this->getOwnerId(),
355
			'viewerId' => $this->getViewerId(),
356
			'users' => $this->getUsers(),
357
			'groups' => $this->getGroups(),
358
			'circles' => $this->getCircles(),
359
			'links' => $this->getLinks()
360
		];
361
	}
362
}
363
364