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
|
2 |
|
public function __invoke() |
19
|
|
|
{ |
20
|
2 |
|
Gate::authorize('admin-link', Auth::user()); |
21
|
|
|
|
22
|
|
|
// Build each of the Administration menus depending on customer's access |
23
|
1 |
|
$userBuild = $this->buildUserList(); |
24
|
1 |
|
$equipmentBuild = $this->buildEquipmentList(); |
25
|
1 |
|
$custBuild = $this->buildCustomerList(); |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
|
29
|
|
|
|
30
|
1 |
|
return Inertia::render('Admin/index', [ |
31
|
1 |
|
'links' => array_merge($userBuild, $equipmentBuild, $custBuild), |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
// Build the user administration links if the user has access |
36
|
1 |
|
protected function buildUserList() |
37
|
|
|
{ |
38
|
1 |
|
$userBuild = []; |
39
|
1 |
|
if($this->getPermissionValue('Manage Users')) |
40
|
|
|
{ |
41
|
|
|
$userBuild = [ |
42
|
|
|
[ |
43
|
1 |
|
'name' => 'Create New User', |
44
|
1 |
|
'icon' => 'fas fa-user-plus', |
45
|
1 |
|
'link' => route('admin.user.create'), |
46
|
|
|
], |
47
|
|
|
[ |
48
|
1 |
|
'name' => 'Modify User', |
49
|
1 |
|
'icon' => 'fas fa-user-edit', |
50
|
1 |
|
'link' => route('admin.user.list'), |
51
|
|
|
], |
52
|
|
|
[ |
53
|
1 |
|
'name' => 'Show Deactivated Users', |
54
|
1 |
|
'icon' => 'fas fa-store-alt-slash', |
55
|
1 |
|
'link' => route('admin.disabled.index'), |
56
|
|
|
], |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
1 |
|
$roleBuild = []; |
61
|
1 |
|
if($this->getPermissionValue('Manage Permissions')) |
62
|
|
|
{ |
63
|
|
|
$roleBuild = [[ |
64
|
1 |
|
'name' => 'User Roles and Permissions', |
65
|
1 |
|
'icon' => 'fas fa-users-cog', |
66
|
1 |
|
'link' => route('admin.user-roles.index'), |
67
|
|
|
]]; |
68
|
|
|
} |
69
|
|
|
|
70
|
1 |
|
return ['users' => array_merge($userBuild, $roleBuild)]; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
// Build the equipment administration links if the user has access |
74
|
1 |
|
protected function buildEquipmentList() |
75
|
|
|
{ |
76
|
1 |
|
$nav = []; |
77
|
1 |
|
if($this->getPermissionValue('Manage Equipment')) |
78
|
|
|
{ |
79
|
|
|
$nav = [ |
80
|
|
|
'equipment types and categories' => [ |
81
|
|
|
[ |
82
|
1 |
|
'name' => 'Create New Category', |
83
|
1 |
|
'icon' => 'fas fa-plus-square', |
84
|
1 |
|
'link' => route('admin.equipment.categories.create'), |
85
|
|
|
], |
86
|
|
|
[ |
87
|
1 |
|
'name' => 'Modify Existing Category', |
88
|
1 |
|
'icon' => 'fas fa-edit', |
89
|
1 |
|
'link' => route('admin.equipment.categories.index'), |
90
|
|
|
], |
91
|
|
|
[ |
92
|
1 |
|
'name' => 'Create New Equipment', |
93
|
1 |
|
'icon' => 'fas fa-plus-square', |
94
|
1 |
|
'link' => route('admin.equipment.create'), |
95
|
|
|
], |
96
|
|
|
[ |
97
|
1 |
|
'name' => 'Modify Existing Equipment', |
98
|
1 |
|
'icon' => 'fas fa-edit', |
99
|
1 |
|
'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
|
1 |
|
return $nav; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
// Build Customer Management list |
115
|
1 |
|
protected function buildCustomerList() |
116
|
|
|
{ |
117
|
1 |
|
$nav = []; |
118
|
|
|
|
119
|
1 |
|
if($this->getPermissionValue('Manage Customers')) |
120
|
|
|
{ |
121
|
|
|
$nav = [ |
122
|
|
|
'Manage Customers' => [ |
123
|
|
|
[ |
124
|
1 |
|
'name' => 'Change Customer ID Number', |
125
|
1 |
|
'icon' => 'fas fa-fingerprint', |
126
|
1 |
|
'link' => route('customers.change-id.index'), |
127
|
|
|
], |
128
|
|
|
[ |
129
|
1 |
|
'name' => 'View Deactivated Customers', |
130
|
1 |
|
'icon' => 'fas fa-ban', |
131
|
1 |
|
'link' => route('customers.show-deactivated'), |
132
|
|
|
], |
133
|
|
|
[ |
134
|
|
|
'name' => 'View Deleted Customer Information', |
135
|
|
|
'icon' => 'fas fa-trash-alt', |
136
|
|
|
'link' => '#', |
137
|
|
|
], |
138
|
|
|
], |
139
|
|
|
]; |
140
|
|
|
} |
141
|
|
|
|
142
|
1 |
|
return $nav; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
|
146
|
|
|
|
147
|
|
|
|
148
|
|
|
|
149
|
|
|
|
150
|
|
|
|
151
|
|
|
|
152
|
|
|
// Determine if the user has permissions for a specific area |
153
|
1 |
|
protected function getPermissionValue($description) |
154
|
|
|
{ |
155
|
1 |
|
$allowed = UserRolePermissions::where('role_id', Auth::user()->role_id)->whereHas('UserRolePermissionTypes', function($q) use ($description) |
|
|
|
|
156
|
|
|
{ |
157
|
1 |
|
$q->where('description', $description); |
158
|
1 |
|
})->first(); |
159
|
|
|
|
160
|
1 |
|
return $allowed->allow; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|