1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Epesi\Core\System\User\Access; |
4
|
|
|
|
5
|
|
|
use Spatie\Permission\Models\Permission; |
6
|
|
|
use Spatie\Permission\Models\Role; |
7
|
|
|
use Epesi\Core\System\Modules\ModuleCore; |
8
|
|
|
use Epesi\Core\System\User\Access\Integration\UserAccessSystemSettings; |
9
|
|
|
use Illuminate\Support\Facades\Gate; |
10
|
|
|
|
11
|
|
|
class AccessCore extends ModuleCore |
12
|
|
|
{ |
13
|
|
|
protected static $alias = 'user.access'; |
14
|
|
|
|
15
|
|
|
protected static $view = AccessSettings::class; |
16
|
|
|
|
17
|
|
|
protected static $joints = [ |
18
|
|
|
UserAccessSystemSettings::class |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
public function defaultRoles() |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
'Super Admin', |
25
|
|
|
'Admin', |
26
|
|
|
'Employee', |
27
|
|
|
'Guest' |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function install() |
32
|
|
|
{ |
33
|
|
|
foreach ($this->defaultRoles() as $roleName) { |
34
|
|
|
Role::create(['name' => $roleName]); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
Permission::create(['name' => 'modify system']); |
38
|
|
|
|
39
|
|
|
$modifySystemSettings = Permission::create(['name' => 'modify system settings']); |
40
|
|
|
|
41
|
|
|
Role::findByName('Admin')->givePermissionTo($modifySystemSettings); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function uninstall() |
45
|
|
|
{ |
46
|
|
|
Role::whereIn('name', $this->defaultRoles())->delete(); |
47
|
|
|
|
48
|
|
|
Permission::findByName('modify system')->delete(); |
49
|
|
|
Permission::findByName('modify system settings')->delete(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public static function boot() |
53
|
|
|
{ |
54
|
|
|
// allow Super Admin full access |
55
|
|
|
Gate::after(function ($user, $ability) { |
|
|
|
|
56
|
|
|
return $user->hasRole('Super Admin'); |
57
|
|
|
}); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.