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 OC\FullTextSearch\Model; |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
use JsonSerializable; |
35
|
|
|
use OCP\FullTextSearch\Model\IDocumentAccess; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Class IDocumentAccess |
40
|
|
|
* |
41
|
|
|
* This object is used as a data transfer object when |
42
|
|
|
* |
43
|
|
|
* - indexing a document, |
44
|
|
|
* - generating a search request. |
45
|
|
|
* |
46
|
|
|
* During the index, it is used to define which users, groups, circles, ... |
47
|
|
|
* have access to the IndexDocument |
48
|
|
|
* |
49
|
|
|
* During the search, it is internally use to define to which group, circles, ... |
50
|
|
|
* a user that perform the search belongs to. |
51
|
|
|
* |
52
|
|
|
* @see IIndexDocument::setAccess |
53
|
|
|
* |
54
|
|
|
* @since 16.0.0 |
55
|
|
|
* |
56
|
|
|
* @package OC\FullTextSearch\Model |
57
|
|
|
*/ |
58
|
|
|
final class DocumentAccess implements IDocumentAccess, JsonSerializable { |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** @var string */ |
62
|
|
|
private $ownerId; |
63
|
|
|
|
64
|
|
|
/** @var string */ |
65
|
|
|
private $viewerId = ''; |
66
|
|
|
|
67
|
|
|
/** @var array */ |
68
|
|
|
private $users = []; |
69
|
|
|
|
70
|
|
|
/** @var array */ |
71
|
|
|
private $groups = []; |
72
|
|
|
|
73
|
|
|
/** @var array */ |
74
|
|
|
private $circles = []; |
75
|
|
|
|
76
|
|
|
/** @var array */ |
77
|
|
|
private $links = []; |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Owner of the document can be set at the init of the object. |
82
|
|
|
* |
83
|
|
|
* @since 16.0.0 |
84
|
|
|
* |
85
|
|
|
* IDocumentAccess constructor. |
86
|
|
|
* |
87
|
|
|
* @param string $ownerId |
88
|
|
|
*/ |
89
|
|
|
public function __construct(string $ownerId = '') { |
90
|
|
|
$this->setOwnerId($ownerId); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Set the Owner of the document. |
96
|
|
|
* |
97
|
|
|
* @since 16.0.0 |
98
|
|
|
* |
99
|
|
|
* @param string $ownerId |
100
|
|
|
* |
101
|
|
|
* @return IDocumentAccess |
102
|
|
|
*/ |
103
|
|
|
public function setOwnerId(string $ownerId): IDocumentAccess { |
104
|
|
|
$this->ownerId = $ownerId; |
105
|
|
|
|
106
|
|
|
return $this; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Get the Owner of the document. |
111
|
|
|
* |
112
|
|
|
* @since 16.0.0 |
113
|
|
|
* |
114
|
|
|
* @return string |
115
|
|
|
*/ |
116
|
|
|
public function getOwnerId(): string { |
117
|
|
|
return $this->ownerId; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Set the viewer of the document. |
123
|
|
|
* |
124
|
|
|
* @since 16.0.0 |
125
|
|
|
* |
126
|
|
|
* @param string $viewerId |
127
|
|
|
* |
128
|
|
|
* @return IDocumentAccess |
129
|
|
|
*/ |
130
|
|
|
public function setViewerId(string $viewerId): IDocumentAccess { |
131
|
|
|
$this->viewerId = $viewerId; |
132
|
|
|
|
133
|
|
|
return $this; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Get the viewer of the document. |
138
|
|
|
* |
139
|
|
|
* @since 16.0.0 |
140
|
|
|
* |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getViewerId(): string { |
144
|
|
|
return $this->viewerId; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Set the list of users that have read access to the document. |
150
|
|
|
* |
151
|
|
|
* @since 16.0.0 |
152
|
|
|
* |
153
|
|
|
* @param array $users |
154
|
|
|
* |
155
|
|
|
* @return IDocumentAccess |
156
|
|
|
*/ |
157
|
|
|
public function setUsers(array $users): IDocumentAccess { |
158
|
|
|
$this->users = $users; |
159
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Add an entry to the list of users that have read access to the document. |
165
|
|
|
* |
166
|
|
|
* @since 16.0.0 |
167
|
|
|
* |
168
|
|
|
* @param string $user |
169
|
|
|
* |
170
|
|
|
* @return IDocumentAccess |
171
|
|
|
*/ |
172
|
|
|
public function addUser(string $user): IDocumentAccess { |
173
|
|
|
$this->users[] = $user; |
174
|
|
|
|
175
|
|
|
return $this; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Add multiple entries to the list of users that have read access to the |
180
|
|
|
* document. |
181
|
|
|
* |
182
|
|
|
* @since 16.0.0 |
183
|
|
|
* |
184
|
|
|
* @param array $users |
185
|
|
|
* |
186
|
|
|
* @return IDocumentAccess |
187
|
|
|
*/ |
188
|
|
|
public function addUsers($users): IDocumentAccess { |
189
|
|
|
$this->users = array_merge($this->users, $users); |
190
|
|
|
|
191
|
|
|
return $this; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Get the complete list of users that have read access to the document. |
196
|
|
|
* |
197
|
|
|
* @since 16.0.0 |
198
|
|
|
* |
199
|
|
|
* @return array |
200
|
|
|
*/ |
201
|
|
|
public function getUsers(): array { |
202
|
|
|
return $this->users; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Set the list of groups that have read access to the document. |
208
|
|
|
* |
209
|
|
|
* @since 16.0.0 |
210
|
|
|
* |
211
|
|
|
* @param array $groups |
212
|
|
|
* |
213
|
|
|
* @return IDocumentAccess |
214
|
|
|
*/ |
215
|
|
|
public function setGroups(array $groups): IDocumentAccess { |
216
|
|
|
$this->groups = $groups; |
217
|
|
|
|
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Add an entry to the list of groups that have read access to the document. |
223
|
|
|
* |
224
|
|
|
* @since 16.0.0 |
225
|
|
|
* |
226
|
|
|
* @param string $group |
227
|
|
|
* |
228
|
|
|
* @return IDocumentAccess |
229
|
|
|
*/ |
230
|
|
|
public function addGroup(string $group): IDocumentAccess { |
231
|
|
|
$this->groups[] = $group; |
232
|
|
|
|
233
|
|
|
return $this; |
234
|
|
|
} |
235
|
|
|
|
236
|
|
|
/** |
237
|
|
|
* Add multiple entries to the list of groups that have read access to the |
238
|
|
|
* document. |
239
|
|
|
* |
240
|
|
|
* @since 16.0.0 |
241
|
|
|
* |
242
|
|
|
* @param array $groups |
243
|
|
|
* |
244
|
|
|
* @return IDocumentAccess |
245
|
|
|
*/ |
246
|
|
|
public function addGroups(array $groups) { |
247
|
|
|
$this->groups = array_merge($this->groups, $groups); |
248
|
|
|
|
249
|
|
|
return $this; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Get the complete list of groups that have read access to the document. |
254
|
|
|
* |
255
|
|
|
* @since 16.0.0 |
256
|
|
|
* |
257
|
|
|
* @return array |
258
|
|
|
*/ |
259
|
|
|
public function getGroups(): array { |
260
|
|
|
return $this->groups; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* Set the list of circles that have read access to the document. |
266
|
|
|
* |
267
|
|
|
* @since 16.0.0 |
268
|
|
|
* |
269
|
|
|
* @param array $circles |
270
|
|
|
* |
271
|
|
|
* @return IDocumentAccess |
272
|
|
|
*/ |
273
|
|
|
public function setCircles(array $circles): IDocumentAccess { |
274
|
|
|
$this->circles = $circles; |
275
|
|
|
|
276
|
|
|
return $this; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* Add an entry to the list of circles that have read access to the document. |
281
|
|
|
* |
282
|
|
|
* @since 16.0.0 |
283
|
|
|
* |
284
|
|
|
* @param string $circle |
285
|
|
|
* |
286
|
|
|
* @return IDocumentAccess |
287
|
|
|
*/ |
288
|
|
|
public function addCircle(string $circle): IDocumentAccess { |
289
|
|
|
$this->circles[] = $circle; |
290
|
|
|
|
291
|
|
|
return $this; |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
/** |
295
|
|
|
* Add multiple entries to the list of groups that have read access to the |
296
|
|
|
* document. |
297
|
|
|
* |
298
|
|
|
* @since 16.0.0 |
299
|
|
|
* |
300
|
|
|
* @param array $circles |
301
|
|
|
* |
302
|
|
|
* @return IDocumentAccess |
303
|
|
|
*/ |
304
|
|
|
public function addCircles(array $circles): IDocumentAccess { |
305
|
|
|
$this->circles = array_merge($this->circles, $circles); |
306
|
|
|
|
307
|
|
|
return $this; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Get the complete list of circles that have read access to the document. |
312
|
|
|
* |
313
|
|
|
* @since 16.0.0 |
314
|
|
|
* |
315
|
|
|
* @return array |
316
|
|
|
*/ |
317
|
|
|
public function getCircles(): array { |
318
|
|
|
return $this->circles; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Set the list of links that have read access to the document. |
324
|
|
|
* |
325
|
|
|
* @since 16.0.0 |
326
|
|
|
* |
327
|
|
|
* @param array $links |
328
|
|
|
* |
329
|
|
|
* @return IDocumentAccess |
330
|
|
|
*/ |
331
|
|
|
public function setLinks(array $links): IDocumentAccess { |
332
|
|
|
$this->links = $links; |
333
|
|
|
|
334
|
|
|
return $this; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* Get the list of links that have read access to the document. |
339
|
|
|
* |
340
|
|
|
* @since 16.0.0 |
341
|
|
|
* |
342
|
|
|
* @return array |
343
|
|
|
*/ |
344
|
|
|
public function getLinks(): array { |
345
|
|
|
return $this->links; |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* @since 16.0.0 |
351
|
|
|
* |
352
|
|
|
* @return array |
353
|
|
|
*/ |
354
|
|
|
public function jsonSerialize(): array { |
355
|
|
|
return [ |
356
|
|
|
'ownerId' => $this->getOwnerId(), |
357
|
|
|
'viewerId' => $this->getViewerId(), |
358
|
|
|
'users' => $this->getUsers(), |
359
|
|
|
'groups' => $this->getGroups(), |
360
|
|
|
'circles' => $this->getCircles(), |
361
|
|
|
'links' => $this->getLinks() |
362
|
|
|
]; |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
|