|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Containers\Authorization\Data\Seeders; |
|
4
|
|
|
|
|
5
|
|
|
use App\Containers\Authorization\Actions\CreatePermissionAction; |
|
6
|
|
|
use App\Containers\Authorization\Actions\CreateRoleAction; |
|
7
|
|
|
use App\Port\Seeder\Abstracts\Seeder; |
|
8
|
|
|
|
|
9
|
|
|
class RolesAndPermissionsSeeder extends Seeder |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var \App\Containers\Authorization\Actions\CreateRoleAction |
|
14
|
|
|
*/ |
|
15
|
|
|
private $createRoleAction; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @var \App\Containers\Authorization\Actions\CreatePermissionAction |
|
19
|
|
|
*/ |
|
20
|
|
|
private $createPermissionAction; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* RolesAndPermissionsSeeder constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* @param \App\Containers\Authorization\Actions\CreateRoleAction $createRoleAction |
|
26
|
|
|
* @param \App\Containers\Authorization\Actions\CreatePermissionAction $createPermissionAction |
|
27
|
|
|
*/ |
|
28
|
|
|
public function __construct( |
|
29
|
|
|
CreateRoleAction $createRoleAction, |
|
30
|
|
|
CreatePermissionAction $createPermissionAction |
|
31
|
|
|
) { |
|
32
|
|
|
$this->createRoleAction = $createRoleAction; |
|
33
|
|
|
$this->createPermissionAction = $createPermissionAction; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Run the database seeds. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
|
|
public function run() |
|
42
|
|
|
{ |
|
43
|
|
|
// Default Roles ---------------------------------------------------------------- |
|
44
|
|
|
// ------------------------------------------------------------------------------ |
|
45
|
|
|
$roleAdmin = $this->createRoleAction->run('admin', 'Super Administrator'); |
|
46
|
|
|
$roleClient = $this->createRoleAction->run('client', 'Normal Client'); |
|
47
|
|
|
$roleDeveloper = $this->createRoleAction->run('developer', 'A developer account, has access to the API'); |
|
48
|
|
|
|
|
49
|
|
|
// Default Permissions ---------------------------------------------------------- |
|
50
|
|
|
// ------------------------------------------------------------------------------ |
|
51
|
|
|
|
|
52
|
|
|
$p = $this->createPermissionAction->run('list-all-users', 'List all users in the system'); |
|
53
|
|
|
$roleAdmin->givePermissionTo($p); |
|
54
|
|
|
|
|
55
|
|
|
// --------------------------------------- |
|
56
|
|
|
|
|
57
|
|
|
$p = $this->createPermissionAction->run('manage-roles-permissions', 'Manage Roles and Permissions for Users'); |
|
58
|
|
|
$roleAdmin->givePermissionTo($p); |
|
59
|
|
|
|
|
60
|
|
|
// --------------------------------------- |
|
61
|
|
|
$p = $this->createPermissionAction->run('delete-user'); |
|
62
|
|
|
$roleAdmin->givePermissionTo($p); |
|
63
|
|
|
|
|
64
|
|
|
// --------------------------------------- |
|
65
|
|
|
|
|
66
|
|
|
$p = $this->createPermissionAction->run('update-user'); |
|
67
|
|
|
$roleClient->givePermissionTo($p); |
|
68
|
|
|
$roleAdmin->givePermissionTo($p); |
|
69
|
|
|
|
|
70
|
|
|
// --------------------------------------- |
|
71
|
|
|
|
|
72
|
|
|
$p = $this->createPermissionAction->run('create-applications', |
|
73
|
|
|
'Create Application to gain third party access using special token'); |
|
74
|
|
|
$roleDeveloper->givePermissionTo($p); |
|
75
|
|
|
|
|
76
|
|
|
// --------------------------------------- |
|
77
|
|
|
|
|
78
|
|
|
// ... |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|