User::scopeWithRoleInDomain()   B
last analyzed

Complexity

Conditions 7
Paths 4

Size

Total Lines 40
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 22
c 0
b 0
f 0
dl 0
loc 40
rs 8.6346
cc 7
nc 4
nop 3
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
        $builder->where('domain_id', $domain->id)
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 necessary display all users with role defined in an ancestor domain
119
                $domainParentIds = $domain->findAncestors()->pluck('id');
120
                if (config('uccello.users.display_all_users_with_role')) {
121
                    $query->whereIn('domain_id', $domainParentIds);
122
                } else {
123
                    $query->where('domain_id', $domain->id);
124
                }
125
126
                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

126
                if (Auth::user() && Auth::user()->/** @scrutinizer ignore-call */ canSeeDescendantsRecords($domain) && $withDescendants) {
Loading history...
127
                    $query->orWhereIn('domain_id', function ($query) use ($domain) {
128
                        $query->select('id')
129
                            ->from((new Domain)->getTable())
130
                            ->where('path', 'like', $domain->id.'/%')
131
                            ->orWhere('path', 'like', '%/'.$domain->id.'/%')
132
                            ->get();
133
                    });
134
                }
135
            });
136
137
        // If necessary display also all admin users
138
        if (config('uccello.users.display_all_admin_users')) {
139
            $builder->orWhere('is_admin', true);
140
        }
141
142
        return $builder;
143
    }
144
145
    public function domain()
146
    {
147
        return $this->belongsTo(Domain::class);
148
    }
149
150
    public function lastDomain()
151
    {
152
        return $this->belongsTo(Domain::class);
153
    }
154
155
    public function privileges()
156
    {
157
        return $this->hasMany(Privilege::class);
158
    }
159
160
    public function menus()
161
    {
162
        return $this->hasMany(Menu::class);
163
    }
164
165
    public function groups()
166
    {
167
        return $this->belongsToMany(Group::class, 'uccello_rl_groups_users');
168
    }
169
170
    public function userSettings()
171
    {
172
        return $this->hasOne(UserSettings::class, 'user_id');
173
    }
174
175
    /**
176
     * Returns record label
177
     *
178
     * @return string
179
     */
180
    public function getRecordLabelAttribute(): string
181
    {
182
        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...
183
    }
184
185
    /**
186
     * Get avatar type
187
     *
188
     * @return string
189
     */
190
    public function getAvatarTypeAttribute(): string
191
    {
192
        return $this->avatar->type ?? 'initials';
0 ignored issues
show
Bug introduced by
The property type does not exist on string.
Loading history...
193
    }
194
195
    /**
196
     * Returns initals generated from the user name
197
     *
198
     * @return string
199
     */
200
    public function getInitialsAttribute(): string
201
    {
202
        $initials = "";
203
204
        $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...
205
206
        $i = 0;
207
        foreach ($words as $w) {
208
            $initials .= $w[0];
209
            $i++;
210
211
            if ($i === 3) { // Maximum: 3 letters
212
                break;
213
            }
214
        }
215
216
        return $initials;
217
    }
218
219
    /**
220
     * Returns the image to use as the user avatar
221
     *
222
     * @return string
223
     */
224
    public function getImageAttribute(): string
225
    {
226
        $image = 'vendor/uccello/uccello/images/user-no-image.png';
227
228
        if ($this->avatarType === 'gravatar') {
229
            $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...
230
        } 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...
231
            $image = $this->avatar->path;
232
        }
233
234
        return $image;
235
    }
236
237
    /**
238
     * Returns user settings
239
     *
240
     * @return \stdClass;
241
     */
242
    public function getSettingsAttribute()
243
    {
244
        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...
245
    }
246
247
    /**
248
     * Searches a settings by key and returns the current value
249
     *
250
     * @param string $key
251
     * @param mixed $defaultValue
252
     * @return \stdClass|null;
253
     */
254
    public function getSettings($key, $defaultValue = null)
255
    {
256
        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...
257
    }
258
259
    /**
260
     * Returns user's roles on a domain
261
     *
262
     * @param \Uccello\Core\Models\Domain $domain
263
     * @param bool $withAncestors
264
     * @return \Illuminate\Support\Collection
265
     */
266
    public function rolesOnDomain($domain, $withAncestors = true): Collection
267
    {
268
        // return Cache::remember('user_'.$this->id.'_domain_'.$domain->slug.'_roles', 600, function () use($domain) {
269
        $roles = collect();
270
271
        // Display all user's roles on ancestor domains
272
        if ($withAncestors && config('uccello.roles.display_ancestors_roles')) {
273
            $treeDomainsIds = $domain->findAncestors()->pluck('id');
274
        } else {
275
            $treeDomainsIds = collect([$domain->id]);
276
        }
277
278
        foreach ($treeDomainsIds as $treeDomainId) {
279
            $_domain = Domain::find($treeDomainId);
280
            foreach ($this->privileges->where('domain_id', $_domain->id) as $privilege) {
281
                if (!$roles->contains($privilege->role)) {
282
                    $roles[] = $privilege->role;
283
                }
284
            }
285
        }
286
287
        return $roles;
288
        // });
289
    }
290
291
    /**
292
     * Returns user's privileges on a domain
293
     *
294
     * @param \Uccello\Core\Models\Domain $domain
295
     * @param bool $withAncestors
296
     * @return \Illuminate\Support\Collection
297
     */
298
    public function privilegesOnDomain($domain, $withAncestors = true): Collection
299
    {
300
        $privileges = collect();
301
302
        // Display all user's roles on ancestor domains
303
        if ($withAncestors) {
304
            $treeDomainsIds = $domain->findAncestors()->pluck('id');
305
        } else {
306
            $treeDomainsIds = collect([$domain->id]);
307
        }
308
309
        foreach ($treeDomainsIds as $treeDomainId) {
310
            $_domain = Domain::find($treeDomainId);
311
312
            $_privileges = $this->privileges()
313
                ->where('domain_id', $_domain->id)
314
                ->with('role')
315
                ->with('domain')
316
                ->get();
317
318
            foreach ($_privileges as $privilege) {
319
                if (!$privileges->contains($privilege)) {
320
                    $privileges[] = $privilege;
321
                }
322
            }
323
        }
324
325
        return $privileges;
326
    }
327
328
    /**
329
     * Returns ids of user's roles on a domain
330
     *
331
     * @param \Uccello\Core\Models\Domain $domain
332
     * @return \Illuminate\Support\Collection
333
     */
334
    public function subordonateRolesIdsOnDomain($domain): Collection
335
    {
336
        $roles = $this->rolesOnDomain($domain);
337
338
        $subordonateRoles = collect();
339
        foreach ($roles as $role) {
340
            $subordonateRoles = $subordonateRoles->merge($role->findDescendants()->pluck('id'));
341
        }
342
343
        return $subordonateRoles;
344
    }
345
346
    /**
347
     * Check if the user has at least a role on a domain
348
     *
349
     * @param \Uccello\Core\Models\Domain $domain
350
     * @return boolean
351
     */
352
    public function hasRoleOnDomain($domain): bool
353
    {
354
        if ($this->is_admin) {
355
            return true;
356
        }
357
358
        return $this->rolesOnDomain($domain)->count() > 0;
359
    }
360
361
    /**
362
     * Check if the user has at least a role on a domain or its descendants
363
     *
364
     * @param \Uccello\Core\Models\Domain $domain
365
     * @return boolean
366
     */
367
    public function hasRoleOnDescendantDomain(Domain $domain): bool
368
    {
369
        if ($this->is_admin) {
370
            return true;
371
        }
372
373
        $hasRole = false;
374
375
        $descendants = Cache::remember('domain_' . $domain->slug . '_descendants', 600, function () use ($domain) {
376
            return $domain->findDescendants()->get();
377
        });
378
379
        foreach ($descendants as $descendant) {
380
            if ($this->hasRoleOnDomain($descendant)) {
381
                $hasRole = true;
382
                break;
383
            }
384
        }
385
386
        return $hasRole;
387
    }
388
389
    /**
390
     * Returns all user capabilities on a module in a domain.
391
     * If the user has a capability in one of the parents of a domain, he also has it in that domain.
392
     *
393
     * @param \Uccello\Core\Models\Domain $domain
394
     * @param \Uccello\Core\Models\Module $module
395
     * @return \Illuminate\Support\Collection
396
     */
397
    public function capabilitiesOnModule(Domain $domain, Module $module): Collection
398
    {
399
        $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...
400
401
        return Cache::remember($keyName, 600, function () use ($domain, $module) {
402
            $capabilities = collect();
403
404
            // Get the domain and all its parents
405
            $domainParents = $domain->findAncestors()->get();
406
407
            // Get user privileges on each domain
408
            foreach ($domainParents as $_domain) {
409
                $privileges = $this->privileges->where('domain_id', $_domain->id);
410
411
                foreach ($privileges as $privilege) {
412
                    foreach ($privilege->role->profiles as $profile) {
413
                        $capabilities = $capabilities->merge($profile->capabilitiesOnModule($module));
414
                    }
415
                }
416
            }
417
418
            return $capabilities;
419
        });
420
    }
421
422
    /**
423
     * Checks if the user has a capability on a module in a domain.
424
     *
425
     * @param string $capabilityName
426
     * @param \Uccello\Core\Models\Domain $domain
427
     * @param \Uccello\Core\Models\Module $module
428
     * @return boolean
429
     */
430
    public function hasCapabilityOnModule(string $capabilityName, Domain $domain, Module $module): bool
431
    {
432
        $capability = capability($capabilityName);
433
434
        $userCapabilities = $this->capabilitiesOnModule($domain, $module);
435
436
        return $this->is_admin || $userCapabilities->contains($capability);
437
    }
438
439
    /**
440
     * Checks if the user can access to settings panel.
441
     * Checks if the user has at least one admin capability on admin modules in a domain.
442
     *
443
     * @param \Uccello\Core\Models\Domain|null $domain
444
     * @return boolean
445
     */
446
    public function canAccessToSettingsPanel(?Domain $domain): bool
447
    {
448
        if (empty($domain)) {
449
            $domain = Domain::first();
450
        }
451
452
        $keyName = 'user_' . $this->id . '_' . $domain->slug . '_can_access_to_settings_panel';
453
454
        return Cache::remember($keyName, 600, function () use ($domain) {
455
456
            $hasCapability = false;
457
458
            foreach (Module::all() as $module) {
459
                if ($module->isAdminModule() === true && $this->canAdmin($domain, $module)) {
460
                    $hasCapability = true;
461
                    break;
462
                }
463
            }
464
465
            return $hasCapability;
466
        });
467
    }
468
469
    /**
470
     * Checks if the user can admin a module in a domain.
471
     *
472
     * @param \Uccello\Core\Models\Domain $domain
473
     * @param \Uccello\Core\Models\Module $module
474
     * @return boolean
475
     */
476
    public function canAdmin(Domain $domain, Module $module): bool
477
    {
478
        return $this->hasCapabilityOnModule('admin', $domain, $module);
479
    }
480
481
    /**
482
     * Checks if the user can create a module in a domain.
483
     *
484
     * @param \Uccello\Core\Models\Domain $domain
485
     * @param \Uccello\Core\Models\Module $module
486
     * @return boolean
487
     */
488
    public function canCreate(Domain $domain, Module $module): bool
489
    {
490
        return $this->hasCapabilityOnModule('create', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
491
    }
492
493
    /**
494
     * Checks if the user can retrieve a module in a domain.
495
     *
496
     * @param \Uccello\Core\Models\Domain $domain
497
     * @param \Uccello\Core\Models\Module $module
498
     * @return boolean
499
     */
500
    public function canRetrieve(Domain $domain, Module $module): bool
501
    {
502
        return $this->hasCapabilityOnModule('retrieve', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
503
    }
504
505
    /**
506
     * Checks if the user can update a module in a domain.
507
     *
508
     * @param \Uccello\Core\Models\Domain $domain
509
     * @param \Uccello\Core\Models\Module $module
510
     * @return boolean
511
     */
512
    public function canUpdate(Domain $domain, Module $module): bool
513
    {
514
        return $this->hasCapabilityOnModule('update', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
515
    }
516
517
    /**
518
     * Checks if the user can delete a module in a domain.
519
     *
520
     * @param \Uccello\Core\Models\Domain $domain
521
     * @param \Uccello\Core\Models\Module $module
522
     * @return boolean
523
     */
524
    public function canDelete(Domain $domain, Module $module): bool
525
    {
526
        return $this->hasCapabilityOnModule('delete', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
527
    }
528
529
    /**
530
     * Checks if the user can create by API a module in a domain.
531
     *
532
     * @param \Uccello\Core\Models\Domain $domain
533
     * @param \Uccello\Core\Models\Module $module
534
     * @return boolean
535
     */
536
    public function canCreateByApi(Domain $domain, Module $module): bool
537
    {
538
        return $this->hasCapabilityOnModule('api-create', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
539
    }
540
541
    /**
542
     * Checks if the user can retrieve by API a module in a domain.
543
     *
544
     * @param \Uccello\Core\Models\Domain $domain
545
     * @param \Uccello\Core\Models\Module $module
546
     * @return boolean
547
     */
548
    public function canRetrieveByApi(Domain $domain, Module $module): bool
549
    {
550
        return $this->hasCapabilityOnModule('api-retrieve', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
551
    }
552
553
    /**
554
     * Checks if the user can update by API a module in a domain.
555
     *
556
     * @param \Uccello\Core\Models\Domain $domain
557
     * @param \Uccello\Core\Models\Module $module
558
     * @return boolean
559
     */
560
    public function canUpdateByApi(Domain $domain, Module $module): bool
561
    {
562
        return $this->hasCapabilityOnModule('api-update', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
563
    }
564
565
    /**
566
     * Checks if the user can delete by API a module in a domain.
567
     *
568
     * @param \Uccello\Core\Models\Domain $domain
569
     * @param \Uccello\Core\Models\Module $module
570
     * @return boolean
571
     */
572
    public function canDeleteByApi(Domain $domain, Module $module): bool
573
    {
574
        return $this->hasCapabilityOnModule('api-delete', $domain, $module) || ($module->isAdminModule() && $this->canAdmin($domain, $module));
575
    }
576
577
    /**
578
     * Checks if the user has almost a role allowing to view data transversally
579
     *
580
     * @param \Uccello\Core\Models\Domain $domain
581
     * @return boolean
582
     */
583
    public function canSeeDescendantsRecords(Domain $domain): bool
584
    {
585
        $allowed = false;
586
587
        if ($this->is_admin) {
588
            $allowed = true;
589
        } else {
590
            $roles = $this->rolesOnDomain($domain);
591
            foreach ($roles as $role) {
592
                if ($role->see_descendants_records) {
593
                    $allowed = true;
594
                    break;
595
                }
596
            }
597
        }
598
599
        return $allowed;
600
    }
601
602
    public function getAllowedGroupUuids()
603
    {
604
        // Use cache
605
        $allowedGroups = Cache::rememberForever(
606
            'allowed_groups_for_' . ($this->is_admin ? 'admin' : $this->getKey()),
607
            function () {
608
                return $this->getAllowedGroupUuidsProcess();
609
            }
610
        );
611
612
        return $allowedGroups;
613
    }
614
615
    public function getAllowedGroupsAndUsers(Domain $domain, $addUsers = true)
616
    {
617
        // Use cache
618
        $allowedGroupsAndUsers = Cache::rememberForever(
619
            'allowed_group_users_for_' .
620
                'd_' . $domain->getKey() . '_' .
621
                ($addUsers ? 'u_' : '') .
622
                ($this->is_admin ? 'admin' : $this->getKey()),
623
            function () use ($domain, $addUsers) {
624
                return $this->getAllowedGroupsAndUsersProcess($domain, $addUsers);
625
            }
626
        );
627
628
        return $allowedGroupsAndUsers;
629
    }
630
631
    protected function getAllowedGroupUuidsProcess()
632
    {
633
        $allowedUserUuids = collect([$this->uuid]);
634
635
        if ($this->is_admin) {
636
            $groups = Group::all();
637
        } else {
638
            $groups = [];
639
            $users = [];
640
641
            foreach ($this->groups as $group) {
642
                $groups[$group->uuid] = $group;
643
            };
644
645
            $this->addRecursiveChildrenGroups($groups, $users, $groups, false);
646
647
            $groups = collect($groups);
648
        }
649
650
        foreach ($groups as $uuid => $group) {
651
            $allowedUserUuids[] = $uuid;
652
        }
653
654
        return $allowedUserUuids;
655
    }
656
657
    protected function addRecursiveChildrenGroups(&$groups, &$users, $searchGroups, $addUsers = false)
658
    {
659
        foreach ($searchGroups as $uuid => $searchGroup) {
660
            $searchChildrenGroups = [];
661
662
            foreach ($searchGroup->childrenGroups as $childrenGroup) {
663
                if (empty($groups[$childrenGroup->uuid])) {
664
                    $groups[$childrenGroup->uuid] = $childrenGroup;
665
                    $searchChildrenGroups[$childrenGroup->uuid] = $childrenGroup;
666
                }
667
668
                if ($addUsers) {
669
                    foreach ($childrenGroup->users as $user) {
670
                        if (empty($users[$user->uuid])) {
671
                            $users[$user->uuid] = $user;
672
                        }
673
                    }
674
                }
675
            }
676
677
            $this->addRecursiveChildrenGroups($groups, $users, $searchChildrenGroups, $addUsers);
678
        }
679
    }
680
681
    protected function getAllowedGroupsAndUsersProcess(Domain $domain, $addUsers = true)
682
    {
683
        $allowedUserUuids = collect([[
684
            'uuid' => $this->uuid,
685
            'recordLabel' => uctrans('me', $this->module)
686
        ]]);
687
688
        // if ($this->is_admin) {
689
        $groups = Group::inDomain($domain)->orderBy('name')->get();
690
        $users  = \App\User::inDomain($domain)->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...
691
        // } else {
692
        //     $groups = [];
693
        //     $users = [];
694
695
        //     foreach ($this->groups as $group) {
696
        //         $groups[$group->uuid] = $group;
697
698
        //         if($addUsers)
699
        //         {
700
        //             foreach ($group->users as $user) {
701
        //                 if (empty($users[$user->uuid])) {
702
        //                     $users[$user->uuid] = $user;
703
        //                 }
704
        //             }
705
        //         }
706
        //     };
707
708
        //     $this->addRecursiveChildrenGroups($groups, $users, $groups, $addUsers);
709
710
        //     $groups = collect($groups)->sortBy('name');
711
        //     $users  = collect($users)->sortBy('name');
712
        // }
713
714
        foreach ($groups as $uuid => $group) {
715
            $allowedUserUuids[] = [
716
                'uuid' => $group->uuid,
717
                'recordLabel' => $group->recordLabel
718
            ];
719
        }
720
721
        foreach ($users as $uuid => $user) {
722
            if ($user->getKey() != $this->getKey()) {
723
                $allowedUserUuids[] = [
724
                    'uuid' => $user->uuid,
725
                    'recordLabel' => $user->recordLabel
726
                ];
727
            }
728
        }
729
730
        return $allowedUserUuids;
731
    }
732
}
733