Completed
Push — master ( 0b2677...ff7e0f )
by Mahmoud
03:45
created

Controller::detachPermissionFromRole()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace App\Containers\Authorization\UI\API\Controllers;
4
5
use App\Containers\Authorization\Actions\AssignRoleAction;
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\DetachPermissionsFromRoleAction;
10
use App\Containers\Authorization\Actions\GetPermissionAction;
11
use App\Containers\Authorization\Actions\GetRoleAction;
12
use App\Containers\Authorization\Actions\ListAllPermissionsAction;
13
use App\Containers\Authorization\Actions\ListAllRolesAction;
14
use App\Containers\Authorization\UI\API\Requests\AssignUserToRoleRequest;
15
use App\Containers\Authorization\UI\API\Requests\AttachPermissionToRoleRequest;
16
use App\Containers\Authorization\UI\API\Requests\CreatePermissionRequest;
17
use App\Containers\Authorization\UI\API\Requests\CreateRoleRequest;
18
use App\Containers\Authorization\UI\API\Requests\DetachPermissionToRoleRequest;
19
use App\Containers\Authorization\UI\API\Requests\GetPermissionRequest;
20
use App\Containers\Authorization\UI\API\Requests\GetRoleRequest;
21
use App\Containers\Authorization\UI\API\Requests\ListAllPermissionsRequest;
22
use App\Containers\Authorization\UI\API\Requests\ListAllRolesRequest;
23
use App\Containers\Authorization\UI\API\Transformers\PermissionTransformer;
24
use App\Containers\Authorization\UI\API\Transformers\RoleTransformer;
25
use App\Containers\User\UI\API\Transformers\UserTransformer;
26
use App\Port\Controller\Abstracts\PortApiController;
27
28
/**
29
 * Class Controller.
30
 *
31
 * @author Mahmoud Zalt <[email protected]>
32
 */
33
class Controller extends PortApiController
34
{
35
36
    /**
37
     * @param \App\Containers\Authorization\UI\API\Requests\ListAllPermissionsRequest $request
38
     * @param \App\Containers\Authorization\Actions\ListAllPermissionsAction          $action
39
     *
40
     * @return  \Dingo\Api\Http\Response
41
     */
42
    public function listAllPermissions(ListAllPermissionsRequest $request, ListAllPermissionsAction $action)
43
    {
44
        $permissions = $action->run();
45
46
        return $this->response->collection($permissions, new PermissionTransformer());
47
    }
48
49
    /**
50
     * @param \App\Containers\Authorization\UI\API\Requests\GetPermissionRequest $request
51
     * @param \App\Containers\Authorization\Actions\GetPermissionAction          $action
52
     *
53
     * @return  \Dingo\Api\Http\Response
54
     */
55
    public function getPermission(GetPermissionRequest $request, GetPermissionAction $action)
56
    {
57
        $permission = $action->run($request['name']);
58
59
        return $this->response->item($permission, new PermissionTransformer());
60
    }
61
62
    /**
63
     * @param \App\Containers\Authorization\UI\API\Requests\ListAllRolesRequest $request
64
     * @param \App\Containers\Authorization\Actions\ListAllRolesAction          $action
65
     *
66
     * @return  \Dingo\Api\Http\Response
67
     */
68
    public function listAllRoles(ListAllRolesRequest $request, ListAllRolesAction $action)
69
    {
70
        $roles = $action->run();
71
72
        return $this->response->collection($roles, new RoleTransformer());
73
    }
74
75
    /**
76
     * @param \App\Containers\Authorization\UI\API\Requests\GetRoleRequest $request
77
     * @param \App\Containers\Authorization\Actions\GetRoleAction          $action
78
     *
79
     * @return  \Dingo\Api\Http\Response
80
     */
81
    public function getRole(GetRoleRequest $request, GetRoleAction $action)
82
    {
83
        $role = $action->run($request['name']);
84
85
        return $this->response->item($role, new RoleTransformer());
86
    }
87
88
    /**
89
     * @param \App\Containers\Authorization\UI\API\Requests\AssignUserToRoleRequest $request
90
     * @param \App\Containers\Authorization\Actions\AssignRoleAction                $action
91
     *
92
     * @return  \Dingo\Api\Http\Response
93
     */
94
    public function assignUserToRole(AssignUserToRoleRequest $request, AssignRoleAction $action)
95
    {
96
        $user = $action->run($request['user_id'], $request['roles_names']);
97
98
        return $this->response->item($user, new UserTransformer());
99
    }
100
101
    /**
102
     * @param \App\Containers\Authorization\UI\API\Requests\AttachPermissionToRoleRequest $request
103
     * @param \App\Containers\Authorization\Actions\AttachPermissionsToRoleAction         $action
104
     *
105
     * @return  \Dingo\Api\Http\Response
106
     */
107
    public function attachPermissionToRole(
108
        AttachPermissionToRoleRequest $request,
109
        AttachPermissionsToRoleAction $action
110
    ) {
111
        $role = $action->run($request['role_name'], $request['permission_name']);
112
113
        return $this->response->item($role, new RoleTransformer());
114
    }
115
116
    /**
117
     * @param \App\Containers\Authorization\UI\API\Requests\DetachPermissionToRoleRequest $request
118
     * @param \App\Containers\Authorization\Actions\DetachPermissionsFromRoleAction       $action
119
     *
120
     * @return  \Dingo\Api\Http\Response
121
     */
122
    public function detachPermissionFromRole(
123
        DetachPermissionToRoleRequest $request,
124
        DetachPermissionsFromRoleAction $action
125
    ) {
126
        $role = $action->run($request['role_name'], $request['permission_name']);
127
128
        return $this->response->item($role, new RoleTransformer());
129
    }
130
131
    /**
132
     * @param \App\Containers\Authorization\UI\API\Requests\CreateRoleRequest $request
133
     * @param \App\Containers\Authorization\Actions\CreateRoleAction          $action
134
     *
135
     * @return  \Dingo\Api\Http\Response
136
     */
137
    public function createRole(CreateRoleRequest $request, CreateRoleAction $action)
138
    {
139
        $role = $action->run($request['name'], $request['description'], $request['display_name']);
140
141
        return $this->response->item($role, new RoleTransformer());
142
    }
143
144
    /**
145
     * @param \App\Containers\Authorization\UI\API\Requests\CreatePermissionRequest $request
146
     * @param \App\Containers\Authorization\Actions\CreatePermissionAction          $action
147
     *
148
     * @return  \Dingo\Api\Http\Response
149
     */
150
    public function createPermission(CreatePermissionRequest $request, CreatePermissionAction $action)
151
    {
152
        $permission = $action->run($request['name'], $request['description'], $request['display_name']);
153
154
        return $this->response->item($permission, new PermissionTransformer());
155
    }
156
157
158
}
159