1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace A17\Twill\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use A17\Twill\Models\Permission; |
6
|
|
|
use Illuminate\Contracts\Foundation\Application; |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
|
9
|
|
|
class RoleController extends ModuleController |
10
|
|
|
{ |
11
|
|
|
protected $namespace = 'A17\Twill'; |
12
|
|
|
|
13
|
|
|
protected $moduleName = 'roles'; |
14
|
|
|
|
15
|
|
|
protected $indexWith = ['medias']; |
16
|
|
|
|
17
|
|
|
protected $defaultOrders = ['name' => 'asc']; |
18
|
|
|
|
19
|
|
|
protected $defaultFilters = [ |
20
|
|
|
'search' => 'search', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
protected $titleColumnKey = 'name'; |
24
|
|
|
|
25
|
|
|
protected $indexOptions = [ |
26
|
|
|
'permalink' => false, |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
protected $labels = [ |
30
|
|
|
'published' => 'twill::lang.permissions.roles.published', |
31
|
|
|
'draft' => 'twill::lang.permissions.roles.draft', |
32
|
|
|
'listing' => [ |
33
|
|
|
'filter' => [ |
34
|
|
|
'published' => 'twill::lang.permissions.roles.published', |
35
|
|
|
'draft' => 'twill::lang.permissions.roles.draft', |
36
|
|
|
], |
37
|
|
|
], |
38
|
|
|
]; |
39
|
|
|
|
40
|
|
|
public function __construct(Application $app, Request $request) |
41
|
|
|
{ |
42
|
|
|
parent::__construct($app, $request); |
43
|
|
|
$this->middleware('can:edit-user-roles'); |
44
|
|
|
|
45
|
|
|
$this->primaryNavigation = [ |
|
|
|
|
46
|
|
|
'users' => [ |
47
|
|
|
'title' => twillTrans('twill::lang.user-management.users'), |
48
|
|
|
'module' => true, |
49
|
|
|
'can' => 'edit-users', |
50
|
|
|
], |
51
|
|
|
'roles' => [ |
52
|
|
|
'title' => twillTrans('twill::lang.permissions.roles.title'), |
53
|
|
|
'module' => true, |
54
|
|
|
'active' => true, |
55
|
|
|
'can' => 'edit-user-roles', |
56
|
|
|
], |
57
|
|
|
'groups' => [ |
58
|
|
|
'title' => twillTrans('twill::lang.permissions.groups.title'), |
59
|
|
|
'module' => true, |
60
|
|
|
'can' => 'edit-user-groups', |
61
|
|
|
], |
62
|
|
|
]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
protected $indexColumns = [ |
66
|
|
|
'name' => [ |
67
|
|
|
'title' => 'Name', |
68
|
|
|
'field' => 'name', |
69
|
|
|
'sort' => true, |
70
|
|
|
], |
71
|
|
|
'created_at' => [ |
72
|
|
|
'title' => 'Date created', |
73
|
|
|
'field' => 'created_at', |
74
|
|
|
'sort' => true |
75
|
|
|
], |
76
|
|
|
'users' => [ |
77
|
|
|
'title' => 'Users', |
78
|
|
|
'field' => 'users_count', |
79
|
|
|
'html' => true |
80
|
|
|
] |
81
|
|
|
]; |
82
|
|
|
|
83
|
|
|
protected function indexData($request) |
84
|
|
|
{ |
85
|
|
|
return [ |
86
|
|
|
'primary_navigation' => $this->primaryNavigation, |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function getIndexItems($scopes = [], $forcePagination = false) |
91
|
|
|
{ |
92
|
|
|
$scopes = $scopes + ['accessible' => true]; |
93
|
|
|
|
94
|
|
|
return parent::getIndexItems($scopes, $forcePagination); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
protected function getIndexOption($option, $item = null) |
98
|
|
|
{ |
99
|
|
|
if (in_array($option, ['publish', 'bulkEdit', 'create'])) { |
100
|
|
|
return auth('twill_users')->user()->can('edit-user-roles'); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
return parent::getIndexOption($option); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
protected function formData($request) |
107
|
|
|
{ |
108
|
|
|
return [ |
109
|
|
|
'primary_navigation' => $this->primaryNavigation, |
110
|
|
|
'permission_modules' => Permission::permissionableParentModuleItems(), |
111
|
|
|
]; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
protected function indexItemData($item) |
115
|
|
|
{ |
116
|
|
|
$canEdit = auth('twill_users')->user()->can('edit-user-roles') && ($item->canEdit ?? true); |
117
|
|
|
|
118
|
|
|
return ['edit' => $canEdit ? $this->getModuleRoute($item->id, 'edit') : null]; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function index($parentModuleId = null) |
122
|
|
|
{ |
123
|
|
|
// Superadmins can reorder groups to determine the access-level of each one. |
124
|
|
|
// A given group can't edit other groups with a higher access-level. |
125
|
|
|
$this->indexOptions['reorder'] = auth('twill_users')->user()->isSuperAdmin(); |
|
|
|
|
126
|
|
|
|
127
|
|
|
return parent::index($parentModuleId); |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function edit($id, $submoduleId = null) |
131
|
|
|
{ |
132
|
|
|
$this->authorizableOptions['edit'] = 'edit-role'; |
133
|
|
|
|
134
|
|
|
return parent::edit($id, $submoduleId); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function update($id, $submoduleId = null) |
138
|
|
|
{ |
139
|
|
|
$this->authorizableOptions['edit'] = 'edit-role'; |
140
|
|
|
|
141
|
|
|
return parent::update($id, $submoduleId); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|