1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Containers\Authorization\UI\API\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Containers\Authorization\Actions\AssignUserToRoleAction; |
6
|
|
|
use App\Containers\Authorization\Actions\AttachPermissionsToRoleAction; |
7
|
|
|
use App\Containers\Authorization\Actions\CreatePermissionAction; |
8
|
|
|
use App\Containers\Authorization\Actions\CreateRoleAction; |
9
|
|
|
use App\Containers\Authorization\Actions\DeleteRoleAction; |
10
|
|
|
use App\Containers\Authorization\Actions\DetachPermissionsFromRoleAction; |
11
|
|
|
use App\Containers\Authorization\Actions\GetPermissionAction; |
12
|
|
|
use App\Containers\Authorization\Actions\GetRoleAction; |
13
|
|
|
use App\Containers\Authorization\Actions\ListAllPermissionsAction; |
14
|
|
|
use App\Containers\Authorization\Actions\ListAllRolesAction; |
15
|
|
|
use App\Containers\Authorization\Actions\RevokeUserFromRoleAction; |
16
|
|
|
use App\Containers\Authorization\UI\API\Requests\AssignUserToRoleRequest; |
17
|
|
|
use App\Containers\Authorization\UI\API\Requests\AttachPermissionToRoleRequest; |
18
|
|
|
use App\Containers\Authorization\UI\API\Requests\CreatePermissionRequest; |
19
|
|
|
use App\Containers\Authorization\UI\API\Requests\CreateRoleRequest; |
20
|
|
|
use App\Containers\Authorization\UI\API\Requests\DeleteRoleRequest; |
21
|
|
|
use App\Containers\Authorization\UI\API\Requests\DetachPermissionToRoleRequest; |
22
|
|
|
use App\Containers\Authorization\UI\API\Requests\GetPermissionRequest; |
23
|
|
|
use App\Containers\Authorization\UI\API\Requests\GetRoleRequest; |
24
|
|
|
use App\Containers\Authorization\UI\API\Requests\ListAllPermissionsRequest; |
25
|
|
|
use App\Containers\Authorization\UI\API\Requests\ListAllRolesRequest; |
26
|
|
|
use App\Containers\Authorization\UI\API\Requests\RevokeUserFromRoleRequest; |
27
|
|
|
use App\Containers\Authorization\UI\API\Transformers\PermissionTransformer; |
28
|
|
|
use App\Containers\Authorization\UI\API\Transformers\RoleTransformer; |
29
|
|
|
use App\Containers\User\Models\User; |
30
|
|
|
use App\Containers\User\UI\API\Transformers\UserTransformer; |
31
|
|
|
use App\Port\Controller\Abstracts\PortApiController; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class Controller. |
35
|
|
|
* |
36
|
|
|
* @author Mahmoud Zalt <[email protected]> |
37
|
|
|
*/ |
38
|
|
|
class Controller extends PortApiController |
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\ListAllPermissionsRequest $request |
43
|
|
|
* @param \App\Containers\Authorization\Actions\ListAllPermissionsAction $action |
44
|
|
|
* |
45
|
|
|
* @return \Dingo\Api\Http\Response |
46
|
|
|
*/ |
47
|
|
|
public function listAllPermissions(ListAllPermissionsRequest $request, ListAllPermissionsAction $action) |
48
|
|
|
{ |
49
|
|
|
$permissions = $action->run(); |
50
|
|
|
|
51
|
|
|
return $this->response->collection($permissions, new PermissionTransformer()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\GetPermissionRequest $request |
56
|
|
|
* @param \App\Containers\Authorization\Actions\GetPermissionAction $action |
57
|
|
|
* |
58
|
|
|
* @return \Dingo\Api\Http\Response |
59
|
|
|
*/ |
60
|
|
|
public function getPermission(GetPermissionRequest $request, GetPermissionAction $action) |
61
|
|
|
{ |
62
|
|
|
$permission = $action->run($request['name']); |
63
|
|
|
|
64
|
|
|
return $this->response->item($permission, new PermissionTransformer()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\ListAllRolesRequest $request |
69
|
|
|
* @param \App\Containers\Authorization\Actions\ListAllRolesAction $action |
70
|
|
|
* |
71
|
|
|
* @return \Dingo\Api\Http\Response |
72
|
|
|
*/ |
73
|
|
|
public function listAllRoles(ListAllRolesRequest $request, ListAllRolesAction $action) |
74
|
|
|
{ |
75
|
|
|
$roles = $action->run(); |
76
|
|
|
|
77
|
|
|
return $this->response->collection($roles, new RoleTransformer()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\GetRoleRequest $request |
82
|
|
|
* @param \App\Containers\Authorization\Actions\GetRoleAction $action |
83
|
|
|
* |
84
|
|
|
* @return \Dingo\Api\Http\Response |
85
|
|
|
*/ |
86
|
|
|
public function getRole(GetRoleRequest $request, GetRoleAction $action) |
87
|
|
|
{ |
88
|
|
|
$role = $action->run($request['name']); |
89
|
|
|
|
90
|
|
|
return $this->response->item($role, new RoleTransformer()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\AssignUserToRoleRequest $request |
95
|
|
|
* @param \App\Containers\Authorization\Actions\AssignUserToRoleAction $action |
96
|
|
|
* |
97
|
|
|
* @return \Dingo\Api\Http\Response |
98
|
|
|
*/ |
99
|
|
|
public function assignUserToRole(AssignUserToRoleRequest $request, AssignUserToRoleAction $action) |
100
|
|
|
{ |
101
|
|
|
$user = $action->run($request['user_id'], $request['roles_names']); |
102
|
|
|
|
103
|
|
|
return $this->response->item($user, new UserTransformer()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\DeleteRoleRequest $request |
108
|
|
|
* @param \App\Containers\Authorization\Actions\DeleteRoleAction $action |
109
|
|
|
* |
110
|
|
|
* @return \Dingo\Api\Http\Response |
111
|
|
|
*/ |
112
|
|
|
public function deleteRole(DeleteRoleRequest $request, DeleteRoleAction $action) |
113
|
|
|
{ |
114
|
|
|
$action->run($request->id); |
|
|
|
|
115
|
|
|
|
116
|
|
|
return $this->response->accepted(null, [ |
117
|
|
|
'message' => 'Role (' . $request->id . ') Deleted Successfully.', |
|
|
|
|
118
|
|
|
]); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\RevokeUserFromRoleRequest $request |
123
|
|
|
* @param \App\Containers\Authorization\Actions\RevokeUserFromRoleAction $action |
124
|
|
|
* |
125
|
|
|
* @return \Dingo\Api\Http\Response |
126
|
|
|
*/ |
127
|
|
|
public function revokeRoleFromUser(RevokeUserFromRoleRequest $request, RevokeUserFromRoleAction $action) |
128
|
|
|
{ |
129
|
|
|
$user = $action->run($request['user_id'], $request['roles_names']); |
130
|
|
|
|
131
|
|
|
return $this->response->item($user, new UserTransformer()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\AttachPermissionToRoleRequest $request |
136
|
|
|
* @param \App\Containers\Authorization\Actions\AttachPermissionsToRoleAction $action |
137
|
|
|
* |
138
|
|
|
* @return \Dingo\Api\Http\Response |
139
|
|
|
*/ |
140
|
|
|
public function attachPermissionToRole( |
141
|
|
|
AttachPermissionToRoleRequest $request, |
142
|
|
|
AttachPermissionsToRoleAction $action |
143
|
|
|
) { |
144
|
|
|
$role = $action->run($request['role_name'], $request['permission_name']); |
145
|
|
|
|
146
|
|
|
return $this->response->item($role, new RoleTransformer()); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\DetachPermissionToRoleRequest $request |
151
|
|
|
* @param \App\Containers\Authorization\Actions\DetachPermissionsFromRoleAction $action |
152
|
|
|
* |
153
|
|
|
* @return \Dingo\Api\Http\Response |
154
|
|
|
*/ |
155
|
|
|
public function detachPermissionFromRole( |
156
|
|
|
DetachPermissionToRoleRequest $request, |
157
|
|
|
DetachPermissionsFromRoleAction $action |
158
|
|
|
) { |
159
|
|
|
$role = $action->run($request['role_name'], $request['permission_name']); |
160
|
|
|
|
161
|
|
|
return $this->response->item($role, new RoleTransformer()); |
162
|
|
|
} |
163
|
|
|
|
164
|
|
|
/** |
165
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\CreateRoleRequest $request |
166
|
|
|
* @param \App\Containers\Authorization\Actions\CreateRoleAction $action |
167
|
|
|
* |
168
|
|
|
* @return \Dingo\Api\Http\Response |
169
|
|
|
*/ |
170
|
|
|
public function createRole(CreateRoleRequest $request, CreateRoleAction $action) |
171
|
|
|
{ |
172
|
|
|
$role = $action->run($request['name'], $request['description'], $request['display_name']); |
173
|
|
|
|
174
|
|
|
return $this->response->item($role, new RoleTransformer()); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param \App\Containers\Authorization\UI\API\Requests\CreatePermissionRequest $request |
179
|
|
|
* @param \App\Containers\Authorization\Actions\CreatePermissionAction $action |
180
|
|
|
* |
181
|
|
|
* @return \Dingo\Api\Http\Response |
182
|
|
|
*/ |
183
|
|
|
public function createPermission(CreatePermissionRequest $request, CreatePermissionAction $action) |
184
|
|
|
{ |
185
|
|
|
$permission = $action->run($request['name'], $request['description'], $request['display_name']); |
186
|
|
|
|
187
|
|
|
return $this->response->item($permission, new PermissionTransformer()); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
} |
192
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.