1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Uccello\Core\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Notifications\Notifiable; |
|
|
|
|
6
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable; |
|
|
|
|
7
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
|
|
|
8
|
|
|
use Illuminate\Support\Collection; |
|
|
|
|
9
|
|
|
use Illuminate\Support\Facades\Cache; |
|
|
|
|
10
|
|
|
use Spatie\Searchable\Searchable; |
|
|
|
|
11
|
|
|
use Spatie\Searchable\SearchResult; |
|
|
|
|
12
|
|
|
use Uccello\Core\Support\Traits\UccelloModule; |
13
|
|
|
use Uccello\Core\Models\Group; |
14
|
|
|
|
15
|
|
|
class User extends Authenticatable implements Searchable |
16
|
|
|
{ |
17
|
|
|
use SoftDeletes; |
18
|
|
|
use Notifiable; |
19
|
|
|
use UccelloModule; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* The table associated with the model. |
23
|
|
|
* |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
protected $table = 'users'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The attributes that should be mutated to dates. |
30
|
|
|
* |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
protected $dates = [ 'deleted_at' ]; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* The attributes that should be casted to native types. |
37
|
|
|
* |
38
|
|
|
* @var array |
39
|
|
|
*/ |
40
|
|
|
protected $casts = [ |
41
|
|
|
'avatar' => 'object', |
42
|
|
|
]; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* The attributes that are mass assignable. |
46
|
|
|
* |
47
|
|
|
* @var array |
48
|
|
|
*/ |
49
|
|
|
protected $fillable = [ |
50
|
|
|
'username', |
51
|
|
|
'name', |
52
|
|
|
'email', |
53
|
|
|
'password', |
54
|
|
|
'is_admin', |
55
|
|
|
'domain_id' |
56
|
|
|
]; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* The attributes that should be hidden for arrays. |
60
|
|
|
* |
61
|
|
|
* @var array |
62
|
|
|
*/ |
63
|
|
|
protected $hidden = [ |
64
|
|
|
'password', 'remember_token', |
65
|
|
|
]; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* The accessors to append to the model's array form. |
69
|
|
|
* |
70
|
|
|
* @var array |
71
|
|
|
*/ |
72
|
|
|
protected $appends = [ |
73
|
|
|
'recordLabel', |
74
|
|
|
'uuid', |
75
|
|
|
]; |
76
|
|
|
|
77
|
|
|
public $searchableType = 'user'; |
78
|
|
|
|
79
|
|
|
public $searchableColumns = [ |
80
|
|
|
'name' |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
public function getSearchResult(): SearchResult |
84
|
|
|
{ |
85
|
|
|
return new SearchResult( |
86
|
|
|
$this, |
87
|
|
|
$this->recordLabel |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function domain() |
92
|
|
|
{ |
93
|
|
|
return $this->belongsTo(Domain::class); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function lastDomain() |
97
|
|
|
{ |
98
|
|
|
return $this->belongsTo(Domain::class); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function privileges() |
102
|
|
|
{ |
103
|
|
|
return $this->hasMany(Privilege::class); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function menus() |
107
|
|
|
{ |
108
|
|
|
return $this->hasMany(Menu::class); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function groups() |
112
|
|
|
{ |
113
|
|
|
return $this->belongsToMany(Group::class, 'uccello_rl_groups_users'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function userSettings() |
117
|
|
|
{ |
118
|
|
|
return $this->hasOne(UserSettings::class, 'user_id'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Returns record label |
123
|
|
|
* |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
|
|
public function getRecordLabelAttribute() : string |
127
|
|
|
{ |
128
|
|
|
return trim($this->name) ?? $this->username; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Get avatar type |
133
|
|
|
* |
134
|
|
|
* @return string |
135
|
|
|
*/ |
136
|
|
|
public function getAvatarTypeAttribute() : string |
137
|
|
|
{ |
138
|
|
|
return $this->avatar->type ?? 'initials'; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Returns initals generated from the user name |
143
|
|
|
* |
144
|
|
|
* @return string |
145
|
|
|
*/ |
146
|
|
|
public function getInitialsAttribute() : string |
147
|
|
|
{ |
148
|
|
|
$initials = ""; |
149
|
|
|
|
150
|
|
|
$words = explode(" ", strtoupper($this->name)); |
151
|
|
|
|
152
|
|
|
$i = 0; |
153
|
|
|
foreach ($words as $w) { |
154
|
|
|
$initials .= $w[0]; |
155
|
|
|
$i++; |
156
|
|
|
|
157
|
|
|
if ($i === 3) { // Maximum: 3 letters |
158
|
|
|
break; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $initials; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Returns the image to use as the user avatar |
167
|
|
|
* |
168
|
|
|
* @return string |
169
|
|
|
*/ |
170
|
|
|
public function getImageAttribute() : string |
171
|
|
|
{ |
172
|
|
|
$image = 'vendor/uccello/uccello/images/user-no-image.png'; |
173
|
|
|
|
174
|
|
|
if ($this->avatarType === 'gravatar') { |
175
|
|
|
$image = 'https://www.gravatar.com/avatar/' . md5($this->email) . '?d=mm'; |
176
|
|
|
|
177
|
|
|
} elseif ($this->avatarType === 'image' && !empty($this->avatar->path)) { |
178
|
|
|
$image = $this->avatar->path; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
return $image; |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* Returns user settings |
186
|
|
|
* |
187
|
|
|
* @return \stdClass; |
188
|
|
|
*/ |
189
|
|
|
public function getSettingsAttribute() |
190
|
|
|
{ |
191
|
|
|
return $this->userSettings->data ?? new \stdClass; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* Searches a settings by key and returns the current value |
196
|
|
|
* |
197
|
|
|
* @param string $key |
198
|
|
|
* @param mixed $defaultValue |
199
|
|
|
* @return \stdClass|null; |
200
|
|
|
*/ |
201
|
|
|
public function getSettings($key, $defaultValue=null) { |
202
|
|
|
return $this->userSettings->data->{$key} ?? $defaultValue; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
/** |
206
|
|
|
* Returns user's roles on a domain |
207
|
|
|
* |
208
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
209
|
|
|
* @return \Illuminate\Support\Collection |
210
|
|
|
*/ |
211
|
|
|
public function rolesOnDomain($domain) : Collection |
212
|
|
|
{ |
213
|
|
|
// return Cache::remember('user_'.$this->id.'_domain_'.$domain->slug.'_roles', 600, function () use($domain) { |
214
|
|
|
$roles = collect(); |
|
|
|
|
215
|
|
|
|
216
|
|
|
if (config('uccello.roles.display_ancestors_roles')) { |
|
|
|
|
217
|
|
|
$treeDomainsIds = $domain->findAncestors()->pluck('id'); |
218
|
|
|
} else { |
219
|
|
|
$treeDomainsIds = collect([ $domain->id ]); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
foreach ($treeDomainsIds as $treeDomainId) { |
223
|
|
|
$_domain = Domain::find($treeDomainId); |
224
|
|
|
foreach ($this->privileges->where('domain_id', $_domain->id) as $privilege) { |
225
|
|
|
$roles[ ] = $privilege->role; |
226
|
|
|
} |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
return $roles; |
230
|
|
|
// }); |
231
|
|
|
|
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* Returns ids of user's roles on a domain |
236
|
|
|
* |
237
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
238
|
|
|
* @return \Illuminate\Support\Collection |
239
|
|
|
*/ |
240
|
|
|
public function subordonateRolesIdsOnDomain($domain) : Collection |
241
|
|
|
{ |
242
|
|
|
$roles = $this->rolesOnDomain($domain); |
243
|
|
|
|
244
|
|
|
$subordonateRoles = collect(); |
|
|
|
|
245
|
|
|
foreach ($roles as $role) { |
246
|
|
|
$subordonateRoles = $subordonateRoles->merge($role->findDescendants()->pluck('id')); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
return $subordonateRoles; |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* Check if the user has at least a role on a domain |
254
|
|
|
* |
255
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
256
|
|
|
* @return boolean |
257
|
|
|
*/ |
258
|
|
|
public function hasRoleOnDomain($domain) : bool { |
259
|
|
|
if ($this->is_admin) { |
260
|
|
|
return true; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
return $this->rolesOnDomain($domain)->count() > 0; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
/** |
267
|
|
|
* Check if the user has at least a role on a domain or its descendants |
268
|
|
|
* |
269
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
270
|
|
|
* @return boolean |
271
|
|
|
*/ |
272
|
|
|
public function hasRoleOnDescendantDomain(Domain $domain) : bool { |
273
|
|
|
if ($this->is_admin) { |
274
|
|
|
return true; |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
$hasRole = false; |
278
|
|
|
|
279
|
|
|
$descendants = Cache::remember('domain_'.$domain->slug.'_descendants', 600, function () use($domain) { |
280
|
|
|
return $domain->findDescendants()->get(); |
281
|
|
|
}); |
282
|
|
|
|
283
|
|
|
foreach ($descendants as $descendant) { |
284
|
|
|
if ($this->hasRoleOnDomain($descendant)) { |
285
|
|
|
$hasRole = true; |
286
|
|
|
break; |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
return $hasRole; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
/** |
294
|
|
|
* Returns all user capabilities on a module in a domain. |
295
|
|
|
* If the user has a capability in one of the parents of a domain, he also has it in that domain. |
296
|
|
|
* |
297
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
298
|
|
|
* @param \Uccello\Core\Models\Module $module |
299
|
|
|
* @return \Illuminate\Support\Collection |
300
|
|
|
*/ |
301
|
|
|
public function capabilitiesOnModule(Domain $domain, Module $module) : Collection |
302
|
|
|
{ |
303
|
|
|
$keyName = 'user_'.$this->id.'_'.$domain->slug.'_'.$module->name.'_capabilities'; |
304
|
|
|
|
305
|
|
|
return Cache::remember($keyName, 600, function () use($domain, $module) { |
306
|
|
|
$capabilities = collect(); |
|
|
|
|
307
|
|
|
|
308
|
|
|
// Get the domain and all its parents |
309
|
|
|
$domainParents = $domain->findAncestors()->get(); |
310
|
|
|
|
311
|
|
|
// Get user privileges on each domain |
312
|
|
|
foreach ($domainParents as $_domain) { |
313
|
|
|
$privileges = $this->privileges->where('domain_id', $_domain->id); |
314
|
|
|
|
315
|
|
|
foreach ($privileges as $privilege) { |
316
|
|
|
|
317
|
|
|
foreach ($privilege->role->profiles as $profile) { |
318
|
|
|
$capabilities = $capabilities->merge($profile->capabilitiesOnModule($module)); |
319
|
|
|
} |
320
|
|
|
} |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
return $capabilities; |
324
|
|
|
}); |
325
|
|
|
} |
326
|
|
|
|
327
|
|
|
/** |
328
|
|
|
* Checks if the user has a capability on a module in a domain. |
329
|
|
|
* |
330
|
|
|
* @param string $capabilityName |
331
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
332
|
|
|
* @param \Uccello\Core\Models\Module $module |
333
|
|
|
* @return boolean |
334
|
|
|
*/ |
335
|
|
|
public function hasCapabilityOnModule(string $capabilityName, Domain $domain, Module $module) : bool |
336
|
|
|
{ |
337
|
|
|
$capability = capability($capabilityName); |
338
|
|
|
|
339
|
|
|
$userCapabilities = $this->capabilitiesOnModule($domain, $module); |
340
|
|
|
|
341
|
|
|
return $this->is_admin || $userCapabilities->contains($capability); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
/** |
345
|
|
|
* Checks if the user can access to settings panel. |
346
|
|
|
* Checks if the user has at least one admin capability on admin modules in a domain. |
347
|
|
|
* |
348
|
|
|
* @param \Uccello\Core\Models\Domain|null $domain |
349
|
|
|
* @return boolean |
350
|
|
|
*/ |
351
|
|
|
public function canAccessToSettingsPanel(?Domain $domain) : bool |
352
|
|
|
{ |
353
|
|
|
if (empty($domain)) { |
354
|
|
|
$domain = Domain::first(); |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
$keyName = 'user_'.$this->id.'_'.$domain->slug.'_can_access_to_settings_panel'; |
358
|
|
|
|
359
|
|
|
return Cache::remember($keyName, 600, function () use($domain) { |
360
|
|
|
|
361
|
|
|
$hasCapability = false; |
362
|
|
|
|
363
|
|
|
foreach (Module::all() as $module) { |
364
|
|
|
if ($module->isAdminModule() === true && $this->canAdmin($domain, $module)) { |
365
|
|
|
$hasCapability = true; |
366
|
|
|
break; |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
return $hasCapability; |
371
|
|
|
}); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Checks if the user can admin a module in a domain. |
376
|
|
|
* |
377
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
378
|
|
|
* @param \Uccello\Core\Models\Module $module |
379
|
|
|
* @return boolean |
380
|
|
|
*/ |
381
|
|
|
public function canAdmin(Domain $domain, Module $module) : bool |
382
|
|
|
{ |
383
|
|
|
return $this->hasCapabilityOnModule('admin', $domain, $module); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* Checks if the user can create a module in a domain. |
388
|
|
|
* |
389
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
390
|
|
|
* @param \Uccello\Core\Models\Module $module |
391
|
|
|
* @return boolean |
392
|
|
|
*/ |
393
|
|
|
public function canCreate(Domain $domain, Module $module) : bool |
394
|
|
|
{ |
395
|
|
|
return $this->hasCapabilityOnModule('create', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* Checks if the user can retrieve a module in a domain. |
400
|
|
|
* |
401
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
402
|
|
|
* @param \Uccello\Core\Models\Module $module |
403
|
|
|
* @return boolean |
404
|
|
|
*/ |
405
|
|
|
public function canRetrieve(Domain $domain, Module $module) : bool |
406
|
|
|
{ |
407
|
|
|
return $this->hasCapabilityOnModule('retrieve', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
/** |
411
|
|
|
* Checks if the user can update a module in a domain. |
412
|
|
|
* |
413
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
414
|
|
|
* @param \Uccello\Core\Models\Module $module |
415
|
|
|
* @return boolean |
416
|
|
|
*/ |
417
|
|
|
public function canUpdate(Domain $domain, Module $module) : bool |
418
|
|
|
{ |
419
|
|
|
return $this->hasCapabilityOnModule('update', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Checks if the user can delete a module in a domain. |
424
|
|
|
* |
425
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
426
|
|
|
* @param \Uccello\Core\Models\Module $module |
427
|
|
|
* @return boolean |
428
|
|
|
*/ |
429
|
|
|
public function canDelete(Domain $domain, Module $module) : bool |
430
|
|
|
{ |
431
|
|
|
return $this->hasCapabilityOnModule('delete', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
432
|
|
|
} |
433
|
|
|
|
434
|
|
|
/** |
435
|
|
|
* Checks if the user can create by API a module in a domain. |
436
|
|
|
* |
437
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
438
|
|
|
* @param \Uccello\Core\Models\Module $module |
439
|
|
|
* @return boolean |
440
|
|
|
*/ |
441
|
|
|
public function canCreateByApi(Domain $domain, Module $module) : bool |
442
|
|
|
{ |
443
|
|
|
return $this->hasCapabilityOnModule('api-create', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Checks if the user can retrieve by API a module in a domain. |
448
|
|
|
* |
449
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
450
|
|
|
* @param \Uccello\Core\Models\Module $module |
451
|
|
|
* @return boolean |
452
|
|
|
*/ |
453
|
|
|
public function canRetrieveByApi(Domain $domain, Module $module) : bool |
454
|
|
|
{ |
455
|
|
|
return $this->hasCapabilityOnModule('api-retrieve', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Checks if the user can update by API a module in a domain. |
460
|
|
|
* |
461
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
462
|
|
|
* @param \Uccello\Core\Models\Module $module |
463
|
|
|
* @return boolean |
464
|
|
|
*/ |
465
|
|
|
public function canUpdateByApi(Domain $domain, Module $module) : bool |
466
|
|
|
{ |
467
|
|
|
return $this->hasCapabilityOnModule('api-update', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
468
|
|
|
} |
469
|
|
|
|
470
|
|
|
/** |
471
|
|
|
* Checks if the user can delete by API a module in a domain. |
472
|
|
|
* |
473
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
474
|
|
|
* @param \Uccello\Core\Models\Module $module |
475
|
|
|
* @return boolean |
476
|
|
|
*/ |
477
|
|
|
public function canDeleteByApi(Domain $domain, Module $module) : bool |
478
|
|
|
{ |
479
|
|
|
return $this->hasCapabilityOnModule('api-delete', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module)); |
480
|
|
|
} |
481
|
|
|
|
482
|
|
|
/** |
483
|
|
|
* Checks if the user has almost a role allowing to view data transversally |
484
|
|
|
* |
485
|
|
|
* @param \Uccello\Core\Models\Domain $domain |
486
|
|
|
* @return boolean |
487
|
|
|
*/ |
488
|
|
|
public function canSeeDescendantsRecords(Domain $domain) : bool |
489
|
|
|
{ |
490
|
|
|
$allowed = false; |
491
|
|
|
|
492
|
|
|
if ($this->is_admin) { |
493
|
|
|
$allowed = true; |
494
|
|
|
} else { |
495
|
|
|
$roles = $this->rolesOnDomain($domain); |
496
|
|
|
foreach ($roles as $role) { |
497
|
|
|
if ($role->see_descendants_records) { |
498
|
|
|
$allowed = true; |
499
|
|
|
break; |
500
|
|
|
} |
501
|
|
|
} |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
return $allowed; |
505
|
|
|
} |
506
|
|
|
|
507
|
|
|
public function getAllowedGroupUuids() |
508
|
|
|
{ |
509
|
|
|
// Use cache |
510
|
|
|
$allowedGroups = Cache::rememberForever( |
511
|
|
|
'allowed_groups_for_' . ($this->is_admin ? 'admin' : $this->getKey()), |
512
|
|
|
function () { |
513
|
|
|
return $this->getAllowedGroupUuidsProcess(); |
514
|
|
|
} |
515
|
|
|
); |
516
|
|
|
|
517
|
|
|
return $allowedGroups; |
518
|
|
|
} |
519
|
|
|
|
520
|
|
|
public function getAllowedGroupsAndUsers($addUsers = true) |
521
|
|
|
{ |
522
|
|
|
// Use cache |
523
|
|
|
$allowedGroupsAndUsers = Cache::rememberForever( |
524
|
|
|
'allowed_group_users_for_' . ($addUsers ? 'u_' : '') . ($this->is_admin ? 'admin' : $this->getKey()), |
525
|
|
|
function () use ($addUsers) { |
526
|
|
|
return $this->getAllowedGroupsAndUsersProcess($addUsers); |
527
|
|
|
} |
528
|
|
|
); |
529
|
|
|
|
530
|
|
|
return $allowedGroupsAndUsers; |
531
|
|
|
} |
532
|
|
|
|
533
|
|
|
protected function getAllowedGroupUuidsProcess() |
534
|
|
|
{ |
535
|
|
|
$allowedUserUuids = collect([$this->uuid]); |
|
|
|
|
536
|
|
|
|
537
|
|
|
if ($this->is_admin) { |
538
|
|
|
$groups = Group::all(); |
539
|
|
|
} else { |
540
|
|
|
$groups = []; |
541
|
|
|
$users = []; |
542
|
|
|
|
543
|
|
|
foreach ($this->groups as $group) { |
544
|
|
|
$groups[$group->uuid] = $group; |
545
|
|
|
}; |
546
|
|
|
|
547
|
|
|
$this->addRecursiveChildrenGroups($groups, $users, $groups, false); |
548
|
|
|
|
549
|
|
|
$groups = collect($groups); |
550
|
|
|
} |
551
|
|
|
|
552
|
|
|
foreach ($groups as $uuid => $group) { |
553
|
|
|
$allowedUserUuids[] = $uuid; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
return $allowedUserUuids; |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
protected function addRecursiveChildrenGroups(&$groups, &$users, $searchGroups, $addUsers = false) |
560
|
|
|
{ |
561
|
|
|
foreach ($searchGroups as $uuid => $searchGroup) { |
562
|
|
|
$searchChildrenGroups = []; |
563
|
|
|
|
564
|
|
|
foreach ($searchGroup->childrenGroups as $childrenGroup) { |
565
|
|
|
if (empty($groups[$childrenGroup->uuid])) { |
566
|
|
|
$groups[$childrenGroup->uuid] = $childrenGroup; |
567
|
|
|
$searchChildrenGroups[$childrenGroup->uuid] = $childrenGroup; |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
if($addUsers) |
571
|
|
|
{ |
572
|
|
|
foreach ($childrenGroup->users as $user) { |
573
|
|
|
if (empty($users[$user->uuid])) { |
574
|
|
|
$users[$user->uuid] = $user; |
575
|
|
|
} |
576
|
|
|
} |
577
|
|
|
} |
578
|
|
|
} |
579
|
|
|
|
580
|
|
|
$this->addRecursiveChildrenGroups($groups, $users, $searchChildrenGroups, $addUsers); |
581
|
|
|
} |
582
|
|
|
} |
583
|
|
|
|
584
|
|
|
protected function getAllowedGroupsAndUsersProcess($addUsers = true) |
585
|
|
|
{ |
586
|
|
|
$allowedUserUuids = collect([[ |
|
|
|
|
587
|
|
|
'uuid' => $this->uuid, |
588
|
|
|
'recordLabel' => uctrans('me', $this->module) |
589
|
|
|
]]); |
590
|
|
|
|
591
|
|
|
// if ($this->is_admin) { |
592
|
|
|
$groups = Group::orderBy('name')->get(); |
593
|
|
|
$users = \App\User::orderBy('name')->get(); |
|
|
|
|
594
|
|
|
// } else { |
595
|
|
|
// $groups = []; |
596
|
|
|
// $users = []; |
597
|
|
|
|
598
|
|
|
// foreach ($this->groups as $group) { |
599
|
|
|
// $groups[$group->uuid] = $group; |
600
|
|
|
|
601
|
|
|
// if($addUsers) |
602
|
|
|
// { |
603
|
|
|
// foreach ($group->users as $user) { |
604
|
|
|
// if (empty($users[$user->uuid])) { |
605
|
|
|
// $users[$user->uuid] = $user; |
606
|
|
|
// } |
607
|
|
|
// } |
608
|
|
|
// } |
609
|
|
|
// }; |
610
|
|
|
|
611
|
|
|
// $this->addRecursiveChildrenGroups($groups, $users, $groups, $addUsers); |
612
|
|
|
|
613
|
|
|
// $groups = collect($groups)->sortBy('name'); |
614
|
|
|
// $users = collect($users)->sortBy('name'); |
615
|
|
|
// } |
616
|
|
|
|
617
|
|
|
foreach ($groups as $uuid => $group) { |
618
|
|
|
$allowedUserUuids[] = [ |
619
|
|
|
'uuid' => $group->uuid, |
620
|
|
|
'recordLabel' => $group->recordLabel |
621
|
|
|
]; |
622
|
|
|
} |
623
|
|
|
|
624
|
|
|
foreach ($users as $uuid => $user) { |
625
|
|
|
if($user->getKey() != $this->getKey()) { |
626
|
|
|
$allowedUserUuids[] = [ |
627
|
|
|
'uuid' => $user->uuid, |
628
|
|
|
'recordLabel' => $user->recordLabel |
629
|
|
|
]; |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
|
633
|
|
|
return $allowedUserUuids; |
634
|
|
|
} |
635
|
|
|
} |
636
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths