Test Setup Failed
Push — dev6 ( 81193f...01d104 )
by Ron
22:34
created

AdminHomeController::buildEquipmentList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 38
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 38
rs 9.7
cc 2
nc 2
nop 0
1
<?php
2
3
namespace App\Http\Controllers\Admin;
4
5
use Inertia\Inertia;
6
7
use App\Models\UserRolePermissions;
8
use App\Http\Controllers\Controller;
9
10
use Illuminate\Support\Facades\Auth;
11
use Illuminate\Support\Facades\Gate;
12
13
class AdminHomeController extends Controller
14
{
15
    /**
16
     *  Administration Home Page
17
     */
18
    public function __invoke()
19
    {
20
        Gate::authorize('admin-link', Auth::user());
21
22
        //  Build each of the Administration menus depending on customer's access
23
        $userBuild      = $this->buildUserList();
24
        $equipmentBuild = $this->buildEquipmentList();
25
26
27
28
29
30
        return Inertia::render('Admin/index', [
31
            'links' => array_merge($userBuild, $equipmentBuild),
32
        ]);
33
    }
34
35
    //  Build the user administration links if the user has access
36
    protected function buildUserList()
37
    {
38
        $userBuild = [];
39
        if($this->getPermissionValue('Manage Users'))
40
        {
41
            $userBuild = [
42
                [
43
                    'name' => 'Create New User',
44
                    'icon' => 'fas fa-user-plus',
45
                    'link' => route('admin.user.create'),
46
                ],
47
                [
48
                    'name' => 'Modify User',
49
                    'icon' => 'fas fa-user-edit',
50
                    'link' => route('admin.user.list'),
51
                ],
52
                [
53
                    'name' => 'Show Deactivated Users',
54
                    'icon' => 'fas fa-store-alt-slash',
55
                    'link' => route('admin.disabled.index'),
56
                ],
57
            ];
58
        }
59
60
        $roleBuild = [];
61
        if($this->getPermissionValue('Manage Permissions'))
62
        {
63
            $roleBuild = [[
64
                'name' => 'User Roles and Permissions',
65
                'icon' => 'fas fa-users-cog',
66
                'link' => route('admin.user-roles.index'),
67
            ]];
68
        }
69
70
        return ['users' => array_merge($userBuild, $roleBuild)];
71
    }
72
73
    //  Build the equipment administration links if the user has access
74
    protected function buildEquipmentList()
75
    {
76
        $nav = [];
77
        if($this->getPermissionValue('Manage Equipment'))
78
        {
79
            $nav = [
80
                'equipment types and categories' => [
81
                    [
82
                        'name' => 'Create New Category',
83
                        'icon' => 'far fa-plus-square',
84
                        'link' => route('admin.equipment.categories.create'),
85
                    ],
86
                    [
87
                        'name' => 'Modify Existing Category',
88
                        'icon' => 'far fa-edit',
89
                        'link' => route('admin.equipment.categories.index'),
90
                    ],
91
                    [
92
                        'name' => 'Create New Equipment',
93
                        'icon' => 'far fa-plus-square',
94
                        'link' => route('admin.equipment.create'),
95
                    ],
96
                    [
97
                        'name' => 'Modify Existing Equipment',
98
                        'icon' => 'far fa-edit',
99
                        'link' => route('admin.equipment.index'),
100
                    ],
101
                    //  TODO - Finish Me
102
                    // [
103
                    //     'name' => 'Modify Information Gathered for Customer Equipment',
104
                    //     'icon' => '',
105
                    //     'link' => '#',
106
                    // ],
107
                ]
108
                ];
109
        }
110
111
        return $nav;
112
    }
113
114
115
    //  Determine if the user has permissions for a specific area
116
    protected function getPermissionValue($description)
117
    {
118
        $allowed = UserRolePermissions::where('role_id', Auth::user()->role_id)->whereHas('UserRolePermissionTypes', function($q) use ($description)
1 ignored issue
show
Bug introduced by
Accessing role_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
119
        {
120
            $q->where('description', $description);
121
        })->first();
122
123
        return $allowed->allow;
124
    }
125
}
126