Passed
Push — master ( dce31b...604a65 )
by Jonathan
14:27
created

User::privilegesOnDomain()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 28
rs 9.1111
cc 6
nc 8
nop 2
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\Auth;
10
use Illuminate\Support\Facades\Cache;
11
use Spatie\Searchable\Searchable;
0 ignored issues
show
Bug introduced by
The type Spatie\Searchable\Searchable was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Spatie\Searchable\SearchResult;
0 ignored issues
show
Bug introduced by
The type Spatie\Searchable\SearchResult was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Uccello\Core\Support\Traits\UccelloModule;
14
use Uccello\Core\Models\Group;
15
16
class User extends Authenticatable implements Searchable
17
{
18
    use SoftDeletes;
19
    use Notifiable;
20
    use UccelloModule;
21
22
    /**
23
     * The table associated with the model.
24
     *
25
     * @var string
26
     */
27
    protected $table = 'users';
28
29
    /**
30
     * The attributes that should be mutated to dates.
31
     *
32
     * @var array
33
     */
34
    protected $dates = [ 'deleted_at' ];
35
36
    /**
37
     * The attributes that should be casted to native types.
38
     *
39
     * @var array
40
     */
41
    protected $casts = [
42
        'avatar' => 'object',
43
    ];
44
45
    /**
46
     * The attributes that are mass assignable.
47
     *
48
     * @var array
49
     */
50
    protected $fillable = [
51
        'username',
52
        'name',
53
        'email',
54
        'password',
55
        'is_admin',
56
        'domain_id'
57
    ];
58
59
    /**
60
     * The attributes that should be hidden for arrays.
61
     *
62
     * @var array
63
     */
64
    protected $hidden = [
65
        'password', 'remember_token',
66
    ];
67
68
    /**
69
     * The accessors to append to the model's array form.
70
     *
71
     * @var array
72
     */
73
    protected $appends = [
74
        'recordLabel',
75
        'uuid',
76
    ];
77
78
    public $searchableType = 'user';
79
80
    public $searchableColumns = [
81
        'username',
82
        'name',
83
        'email'
84
    ];
85
86
    public function getSearchResult(): SearchResult
87
    {
88
        return new SearchResult(
89
            $this,
90
            $this->recordLabel
91
        );
92
    }
93
94
    /**
95
     * Scope a query to only include users with role in domain.
96
     *
97
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
98
     * @param  \Uccello\Core\Models\Domain|null $domain
99
     *
100
     *
101
     * @return \Illuminate\Database\Eloquent\Builder
102
     */
103
    public function scopeWithRoleInDomain($builder, ?Domain $domain, $withDescendants = false)
104
    {
105
        if (!$domain) {
106
            $domain = Domain::first();
107
        }
108
109
        // Check if user is admin or if he has at least a role on the domain
110
        // or on descendants domains if withDescendants option is on
111
        return $builder->where('is_admin',true)
0 ignored issues
show
Bug Best Practice introduced by
The expression return $builder->where('...ion(...) { /* ... */ }) also could return the type Illuminate\Database\Query\Builder which is incompatible with the documented return type Illuminate\Database\Eloquent\Builder.
Loading history...
112
            ->orWhereIn($this->getKeyName(), function ($query) use ($domain, $withDescendants) {
113
                $privilegesTable = env('UCCELLO_TABLE_PREFIX', 'uccello_').'privileges';
114
115
                $query->select('user_id')
116
                    ->from($privilegesTable);
117
118
                if (Auth::user() && Auth::user()->canSeeDescendantsRecords($domain) && $withDescendants) {
0 ignored issues
show
Bug introduced by
The method canSeeDescendantsRecords() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

118
                if (Auth::user() && Auth::user()->/** @scrutinizer ignore-call */ canSeeDescendantsRecords($domain) && $withDescendants) {
Loading history...
119
                    $domainsIds = $domain->findDescendants()->pluck('id');
120
                    $query->whereIn('domain_id', $domainsIds);
121
                } else {
122
                    $query->where('domain_id', $domain->id);
123
                }
124
            });
125
        }
126
127
    public function domain()
128
    {
129
        return $this->belongsTo(Domain::class);
130
    }
131
132
    public function lastDomain()
133
    {
134
        return $this->belongsTo(Domain::class);
135
    }
136
137
    public function privileges()
138
    {
139
        return $this->hasMany(Privilege::class);
140
    }
141
142
    public function menus()
143
    {
144
        return $this->hasMany(Menu::class);
145
    }
146
147
    public function groups()
148
    {
149
        return $this->belongsToMany(Group::class, 'uccello_rl_groups_users');
150
    }
151
152
    public function userSettings()
153
    {
154
        return $this->hasOne(UserSettings::class, 'user_id');
155
    }
156
157
    /**
158
     * Returns record label
159
     *
160
     * @return string
161
     */
162
    public function getRecordLabelAttribute() : string
163
    {
164
        return trim($this->name) ?? $this->username;
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Uccello\Core\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
165
    }
166
167
    /**
168
     * Get avatar type
169
     *
170
     * @return string
171
     */
172
    public function getAvatarTypeAttribute() : string
173
    {
174
        return $this->avatar->type ?? 'initials';
0 ignored issues
show
Bug introduced by
The property type does not exist on string.
Loading history...
175
    }
176
177
    /**
178
     * Returns initals generated from the user name
179
     *
180
     * @return string
181
     */
182
    public function getInitialsAttribute() : string
183
    {
184
        $initials = "";
185
186
        $words = explode(" ", strtoupper($this->name));
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Uccello\Core\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
187
188
        $i = 0;
189
        foreach ($words as $w) {
190
            $initials .= $w[0];
191
            $i++;
192
193
            if ($i === 3) { // Maximum: 3 letters
194
                break;
195
            }
196
        }
197
198
        return $initials;
199
    }
200
201
    /**
202
     * Returns the image to use as the user avatar
203
     *
204
     * @return string
205
     */
206
    public function getImageAttribute() : string
207
    {
208
        $image = 'vendor/uccello/uccello/images/user-no-image.png';
209
210
        if ($this->avatarType === 'gravatar') {
211
            $image = 'https://www.gravatar.com/avatar/' . md5($this->email) . '?d=mm';
0 ignored issues
show
Bug introduced by
The property email does not seem to exist on Uccello\Core\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
212
213
        } elseif ($this->avatarType === 'image' && !empty($this->avatar->path)) {
0 ignored issues
show
Bug introduced by
The property path does not exist on string.
Loading history...
214
            $image = $this->avatar->path;
215
        }
216
217
        return $image;
218
    }
219
220
    /**
221
     * Returns user settings
222
     *
223
     * @return \stdClass;
224
     */
225
    public function getSettingsAttribute()
226
    {
227
        return $this->userSettings->data ?? new \stdClass;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Uccello\Core\Models\UserSettings. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
228
    }
229
230
    /**
231
     * Searches a settings by key and returns the current value
232
     *
233
     * @param string $key
234
     * @param mixed $defaultValue
235
     * @return \stdClass|null;
236
     */
237
    public function getSettings($key, $defaultValue=null) {
238
        return $this->userSettings->data->{$key} ?? $defaultValue;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Uccello\Core\Models\UserSettings. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
239
    }
240
241
    /**
242
     * Returns user's roles on a domain
243
     *
244
     * @param \Uccello\Core\Models\Domain $domain
245
     * @param bool $withAncestors
246
     * @return \Illuminate\Support\Collection
247
     */
248
    public function rolesOnDomain($domain, $withAncestors = true) : Collection
249
    {
250
        // return Cache::remember('user_'.$this->id.'_domain_'.$domain->slug.'_roles', 600, function () use($domain) {
251
            $roles = collect();
252
253
            // Display all user's roles on ancestor domains
254
            if ($withAncestors && config('uccello.roles.display_ancestors_roles')) {
255
                $treeDomainsIds = $domain->findAncestors()->pluck('id');
256
            } else {
257
                $treeDomainsIds = collect([ $domain->id ]);
258
            }
259
260
            foreach ($treeDomainsIds as $treeDomainId) {
261
                $_domain = Domain::find($treeDomainId);
262
                foreach ($this->privileges->where('domain_id', $_domain->id) as $privilege) {
263
                    if (!$roles->contains($privilege->role)) {
264
                        $roles[ ] = $privilege->role;
265
                    }
266
                }
267
            }
268
269
            return $roles;
270
        // });
271
272
    }
273
274
    /**
275
     * Returns user's privileges on a domain
276
     *
277
     * @param \Uccello\Core\Models\Domain $domain
278
     * @param bool $withAncestors
279
     * @return \Illuminate\Support\Collection
280
     */
281
    public function privilegesOnDomain($domain, $withAncestors = true) : Collection
282
    {
283
        $privileges = collect();
284
285
        // Display all user's roles on ancestor domains
286
        if ($withAncestors && config('uccello.roles.display_ancestors_roles')) {
287
            $treeDomainsIds = $domain->findAncestors()->pluck('id');
288
        } else {
289
            $treeDomainsIds = collect([ $domain->id ]);
290
        }
291
292
        foreach ($treeDomainsIds as $treeDomainId) {
293
            $_domain = Domain::find($treeDomainId);
294
295
            $_privileges = $this->privileges()
296
                ->where('domain_id', $_domain->id)
297
                ->with('role')
298
                ->with('domain')
299
                ->get();
300
301
            foreach ($_privileges as $privilege) {
302
                if (!$privileges->contains($privilege)) {
303
                    $privileges[ ] = $privilege;
304
                }
305
            }
306
        }
307
308
        return $privileges;
309
    }
310
311
    /**
312
     * Returns ids of user's roles on a domain
313
     *
314
     * @param \Uccello\Core\Models\Domain $domain
315
     * @return \Illuminate\Support\Collection
316
     */
317
    public function subordonateRolesIdsOnDomain($domain) : Collection
318
    {
319
        $roles = $this->rolesOnDomain($domain);
320
321
        $subordonateRoles = collect();
322
        foreach ($roles as $role) {
323
            $subordonateRoles = $subordonateRoles->merge($role->findDescendants()->pluck('id'));
324
        }
325
326
        return $subordonateRoles;
327
    }
328
329
    /**
330
     * Check if the user has at least a role on a domain
331
     *
332
     * @param \Uccello\Core\Models\Domain $domain
333
     * @return boolean
334
     */
335
    public function hasRoleOnDomain($domain) : bool {
336
        if ($this->is_admin) {
337
            return true;
338
        }
339
340
        return $this->rolesOnDomain($domain)->count() > 0;
341
    }
342
343
    /**
344
     * Check if the user has at least a role on a domain or its descendants
345
     *
346
     * @param \Uccello\Core\Models\Domain $domain
347
     * @return boolean
348
     */
349
    public function hasRoleOnDescendantDomain(Domain $domain) : bool {
350
        if ($this->is_admin) {
351
            return true;
352
        }
353
354
        $hasRole = false;
355
356
        $descendants = Cache::remember('domain_'.$domain->slug.'_descendants', 600, function () use($domain) {
357
            return $domain->findDescendants()->get();
358
        });
359
360
        foreach ($descendants as $descendant) {
361
            if ($this->hasRoleOnDomain($descendant)) {
362
                $hasRole = true;
363
                break;
364
            }
365
        }
366
367
        return $hasRole;
368
    }
369
370
    /**
371
     * Returns all user capabilities on a module in a domain.
372
     * If the user has a capability in one of the parents of a domain, he also has it in that domain.
373
     *
374
     * @param \Uccello\Core\Models\Domain $domain
375
     * @param \Uccello\Core\Models\Module $module
376
     * @return \Illuminate\Support\Collection
377
     */
378
    public function capabilitiesOnModule(Domain $domain, Module $module) : Collection
379
    {
380
        $keyName = 'user_'.$this->id.'_'.$domain->slug.'_'.$module->name.'_capabilities';
0 ignored issues
show
Bug introduced by
The property name does not seem to exist on Uccello\Core\Models\Module. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
381
382
        return Cache::remember($keyName, 600, function () use($domain, $module) {
383
            $capabilities = collect();
384
385
            // Get the domain and all its parents
386
            $domainParents = $domain->findAncestors()->get();
387
388
            // Get user privileges on each domain
389
            foreach ($domainParents as $_domain) {
390
                $privileges = $this->privileges->where('domain_id', $_domain->id);
391
392
                foreach ($privileges as $privilege) {
393
394
                    foreach ($privilege->role->profiles as $profile) {
395
                        $capabilities = $capabilities->merge($profile->capabilitiesOnModule($module));
396
                    }
397
                }
398
            }
399
400
            return $capabilities;
401
        });
402
    }
403
404
    /**
405
     * Checks if the user has a capability on a module in a domain.
406
     *
407
     * @param string $capabilityName
408
     * @param \Uccello\Core\Models\Domain $domain
409
     * @param \Uccello\Core\Models\Module $module
410
     * @return boolean
411
     */
412
    public function hasCapabilityOnModule(string $capabilityName, Domain $domain, Module $module) : bool
413
    {
414
        $capability = capability($capabilityName);
415
416
        $userCapabilities = $this->capabilitiesOnModule($domain, $module);
417
418
        return $this->is_admin || $userCapabilities->contains($capability);
419
    }
420
421
    /**
422
     * Checks if the user can access to settings panel.
423
     * Checks if the user has at least one admin capability on admin modules in a domain.
424
     *
425
     * @param \Uccello\Core\Models\Domain|null $domain
426
     * @return boolean
427
     */
428
    public function canAccessToSettingsPanel(?Domain $domain) : bool
429
    {
430
        if (empty($domain)) {
431
            $domain = Domain::first();
432
        }
433
434
        $keyName = 'user_'.$this->id.'_'.$domain->slug.'_can_access_to_settings_panel';
435
436
        return Cache::remember($keyName, 600, function () use($domain) {
437
438
            $hasCapability = false;
439
440
            foreach (Module::all() as $module) {
441
                if ($module->isAdminModule() === true && $this->canAdmin($domain, $module)) {
442
                    $hasCapability = true;
443
                    break;
444
                }
445
            }
446
447
            return $hasCapability;
448
        });
449
    }
450
451
    /**
452
     * Checks if the user can admin a module in a domain.
453
     *
454
     * @param \Uccello\Core\Models\Domain $domain
455
     * @param \Uccello\Core\Models\Module $module
456
     * @return boolean
457
     */
458
    public function canAdmin(Domain $domain, Module $module) : bool
459
    {
460
        return $this->hasCapabilityOnModule('admin', $domain, $module);
461
    }
462
463
    /**
464
     * Checks if the user can create a module in a domain.
465
     *
466
     * @param \Uccello\Core\Models\Domain $domain
467
     * @param \Uccello\Core\Models\Module $module
468
     * @return boolean
469
     */
470
    public function canCreate(Domain $domain, Module $module) : bool
471
    {
472
        return $this->hasCapabilityOnModule('create', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
473
    }
474
475
    /**
476
     * Checks if the user can retrieve a module in a domain.
477
     *
478
     * @param \Uccello\Core\Models\Domain $domain
479
     * @param \Uccello\Core\Models\Module $module
480
     * @return boolean
481
     */
482
    public function canRetrieve(Domain $domain, Module $module) : bool
483
    {
484
        return $this->hasCapabilityOnModule('retrieve', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
485
    }
486
487
    /**
488
     * Checks if the user can update a module in a domain.
489
     *
490
     * @param \Uccello\Core\Models\Domain $domain
491
     * @param \Uccello\Core\Models\Module $module
492
     * @return boolean
493
     */
494
    public function canUpdate(Domain $domain, Module $module) : bool
495
    {
496
        return $this->hasCapabilityOnModule('update', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
497
    }
498
499
    /**
500
     * Checks if the user can delete a module in a domain.
501
     *
502
     * @param \Uccello\Core\Models\Domain $domain
503
     * @param \Uccello\Core\Models\Module $module
504
     * @return boolean
505
     */
506
    public function canDelete(Domain $domain, Module $module) : bool
507
    {
508
        return $this->hasCapabilityOnModule('delete', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
509
    }
510
511
    /**
512
     * Checks if the user can create by API a module in a domain.
513
     *
514
     * @param \Uccello\Core\Models\Domain $domain
515
     * @param \Uccello\Core\Models\Module $module
516
     * @return boolean
517
     */
518
    public function canCreateByApi(Domain $domain, Module $module) : bool
519
    {
520
        return $this->hasCapabilityOnModule('api-create', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
521
    }
522
523
    /**
524
     * Checks if the user can retrieve by API a module in a domain.
525
     *
526
     * @param \Uccello\Core\Models\Domain $domain
527
     * @param \Uccello\Core\Models\Module $module
528
     * @return boolean
529
     */
530
    public function canRetrieveByApi(Domain $domain, Module $module) : bool
531
    {
532
        return $this->hasCapabilityOnModule('api-retrieve', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
533
    }
534
535
    /**
536
     * Checks if the user can update by API a module in a domain.
537
     *
538
     * @param \Uccello\Core\Models\Domain $domain
539
     * @param \Uccello\Core\Models\Module $module
540
     * @return boolean
541
     */
542
    public function canUpdateByApi(Domain $domain, Module $module) : bool
543
    {
544
        return $this->hasCapabilityOnModule('api-update', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
545
    }
546
547
    /**
548
     * Checks if the user can delete by API a module in a domain.
549
     *
550
     * @param \Uccello\Core\Models\Domain $domain
551
     * @param \Uccello\Core\Models\Module $module
552
     * @return boolean
553
     */
554
    public function canDeleteByApi(Domain $domain, Module $module) : bool
555
    {
556
        return $this->hasCapabilityOnModule('api-delete', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
557
    }
558
559
    /**
560
     * Checks if the user has almost a role allowing to view data transversally
561
     *
562
     * @param \Uccello\Core\Models\Domain $domain
563
     * @return boolean
564
     */
565
    public function canSeeDescendantsRecords(Domain $domain) : bool
566
    {
567
        $allowed = false;
568
569
        if ($this->is_admin) {
570
            $allowed = true;
571
        } else {
572
            $roles = $this->rolesOnDomain($domain);
573
            foreach ($roles as $role) {
574
                if ($role->see_descendants_records) {
575
                    $allowed = true;
576
                    break;
577
                }
578
            }
579
        }
580
581
        return $allowed;
582
    }
583
584
    public function getAllowedGroupUuids()
585
    {
586
        // Use cache
587
        $allowedGroups = Cache::rememberForever(
588
            'allowed_groups_for_' . ($this->is_admin ? 'admin' : $this->getKey()),
589
            function () {
590
                return $this->getAllowedGroupUuidsProcess();
591
            }
592
        );
593
594
        return $allowedGroups;
595
    }
596
597
    public function getAllowedGroupsAndUsers($addUsers = true)
598
    {
599
        // Use cache
600
        $allowedGroupsAndUsers = Cache::rememberForever(
601
            'allowed_group_users_for_' . ($addUsers ? 'u_' : '') . ($this->is_admin ? 'admin' : $this->getKey()),
602
            function () use ($addUsers) {
603
                return $this->getAllowedGroupsAndUsersProcess($addUsers);
604
            }
605
        );
606
607
        return $allowedGroupsAndUsers;
608
    }
609
610
    protected function getAllowedGroupUuidsProcess()
611
    {
612
        $allowedUserUuids = collect([$this->uuid]);
613
614
        if ($this->is_admin) {
615
            $groups = Group::all();
616
        } else {
617
            $groups = [];
618
            $users = [];
619
620
            foreach ($this->groups as $group) {
621
                $groups[$group->uuid] = $group;
622
            };
623
624
            $this->addRecursiveChildrenGroups($groups, $users, $groups, false);
625
626
            $groups = collect($groups);
627
        }
628
629
        foreach ($groups as $uuid => $group) {
630
            $allowedUserUuids[] = $uuid;
631
        }
632
633
        return $allowedUserUuids;
634
    }
635
636
    protected function addRecursiveChildrenGroups(&$groups, &$users, $searchGroups, $addUsers = false)
637
    {
638
        foreach ($searchGroups as $uuid => $searchGroup) {
639
            $searchChildrenGroups = [];
640
641
            foreach ($searchGroup->childrenGroups as $childrenGroup) {
642
                if (empty($groups[$childrenGroup->uuid])) {
643
                    $groups[$childrenGroup->uuid] = $childrenGroup;
644
                    $searchChildrenGroups[$childrenGroup->uuid] = $childrenGroup;
645
                }
646
647
                if($addUsers)
648
                {
649
                    foreach ($childrenGroup->users as $user) {
650
                        if (empty($users[$user->uuid])) {
651
                            $users[$user->uuid] = $user;
652
                        }
653
                    }
654
                }
655
            }
656
657
            $this->addRecursiveChildrenGroups($groups, $users, $searchChildrenGroups, $addUsers);
658
        }
659
    }
660
661
    protected function getAllowedGroupsAndUsersProcess($addUsers = true)
662
    {
663
        $allowedUserUuids = collect([[
664
            'uuid' => $this->uuid,
665
            'recordLabel' => uctrans('me', $this->module)
666
        ]]);
667
668
        // if ($this->is_admin) {
669
            $groups = Group::orderBy('name')->get();
670
            $users  = \App\User::orderBy('name')->get();
0 ignored issues
show
Bug introduced by
The type App\User was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
671
        // } else {
672
        //     $groups = [];
673
        //     $users = [];
674
675
        //     foreach ($this->groups as $group) {
676
        //         $groups[$group->uuid] = $group;
677
678
        //         if($addUsers)
679
        //         {
680
        //             foreach ($group->users as $user) {
681
        //                 if (empty($users[$user->uuid])) {
682
        //                     $users[$user->uuid] = $user;
683
        //                 }
684
        //             }
685
        //         }
686
        //     };
687
688
        //     $this->addRecursiveChildrenGroups($groups, $users, $groups, $addUsers);
689
690
        //     $groups = collect($groups)->sortBy('name');
691
        //     $users  = collect($users)->sortBy('name');
692
        // }
693
694
        foreach ($groups as $uuid => $group) {
695
            $allowedUserUuids[] = [
696
                'uuid' => $group->uuid,
697
                'recordLabel' => $group->recordLabel
698
            ];
699
        }
700
701
        foreach ($users as $uuid => $user) {
702
            if($user->getKey() != $this->getKey()) {
703
                $allowedUserUuids[] = [
704
                    'uuid' => $user->uuid,
705
                    'recordLabel' => $user->recordLabel
706
                ];
707
            }
708
        }
709
710
        return $allowedUserUuids;
711
    }
712
}
713