1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\Module\AssignRoles\Http\Controllers\ParticipantApi; |
4
|
|
|
|
5
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\DataRole; |
6
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Role; |
7
|
|
|
use BristolSU\Module\AssignRoles\Events\RoleCreated; |
8
|
|
|
use BristolSU\Module\AssignRoles\Http\Controllers\Controller; |
9
|
|
|
use BristolSU\Module\AssignRoles\Http\Requests\ParticipantApi\RoleController\DestroyRequest; |
10
|
|
|
use BristolSU\Module\AssignRoles\Http\Requests\ParticipantApi\RoleController\StoreRequest; |
11
|
|
|
use BristolSU\Module\AssignRoles\Http\Requests\ParticipantApi\RoleController\UpdateRequest; |
12
|
|
|
use BristolSU\Support\Activity\Activity; |
13
|
|
|
use BristolSU\Support\Authentication\Contracts\Authentication; |
14
|
|
|
use BristolSU\Support\ModuleInstance\ModuleInstance; |
15
|
|
|
|
16
|
|
|
class RoleController extends Controller |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
|
19
|
3 |
|
public function index(Activity $activity, ModuleInstance $moduleInstance, Role $role, Authentication $authentication) |
|
|
|
|
20
|
|
|
{ |
21
|
3 |
|
$this->authorize('role.index'); |
22
|
2 |
|
$roles = $role->allThroughGroup( |
23
|
2 |
|
$authentication->getGroup() |
|
|
|
|
24
|
|
|
); |
25
|
|
|
|
26
|
|
|
return $roles->map(function(\BristolSU\ControlDB\Contracts\Models\Role $role) { |
|
|
|
|
27
|
2 |
|
$roleArray = $role->toArray(); |
28
|
2 |
|
$roleArray['position'] = $role->position(); |
29
|
2 |
|
$roleArray['users'] = $role->users(); |
30
|
2 |
|
return $roleArray; |
31
|
2 |
|
}); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
7 |
|
public function store(Activity $activity, ModuleInstance $moduleInstance, StoreRequest $request, Role $roleRepository, DataRole $dataRoleRepository, Authentication $authentication) |
|
|
|
|
35
|
|
|
{ |
36
|
7 |
|
$this->authorize('role.store'); |
37
|
|
|
|
38
|
6 |
|
$dataRole = $dataRoleRepository->create( |
39
|
6 |
|
$request->input('role_name'), |
40
|
6 |
|
$request->input('email') |
41
|
|
|
); |
42
|
|
|
|
43
|
6 |
|
$role = $roleRepository->create( |
44
|
6 |
|
$request->input('position_id'), |
45
|
6 |
|
$authentication->getGroup()->id(), |
46
|
6 |
|
$dataRole->id() |
47
|
|
|
); |
48
|
|
|
|
49
|
6 |
|
event(new RoleCreated($role)); |
50
|
|
|
|
51
|
6 |
|
return $role; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
public function destroy(Activity $activity, ModuleInstance $moduleInstance, int $roleId, DestroyRequest $request, Role $roleRepository) |
|
|
|
|
55
|
|
|
{ |
56
|
2 |
|
$this->authorize('role.delete'); |
57
|
|
|
|
58
|
1 |
|
$roleRepository->delete($roleId); |
59
|
1 |
|
} |
60
|
|
|
|
61
|
5 |
|
public function update(Activity $activity, ModuleInstance $moduleInstance, int $roleId, UpdateRequest $request, Role $roleRepository, DataRole $dataRoleRepository) |
|
|
|
|
62
|
|
|
{ |
63
|
5 |
|
$this->authorize('role.update'); |
64
|
|
|
|
65
|
5 |
|
$role = $roleRepository->getById($roleId); |
66
|
5 |
|
$dataRole = $role->data(); |
67
|
5 |
|
$dataRole->setEmail($request->input('email', $dataRole->email())); |
68
|
5 |
|
$dataRole->setRoleName($request->input('role_name', $dataRole->roleName())); |
69
|
5 |
|
return $dataRole; |
70
|
|
|
} |
71
|
|
|
} |