Commit 48d62cfd authored by Nicolas Widart's avatar Nicolas Widart

Adding the permissions UI to the roles

parent bb4d02ed
<?php
return [
'users' => [
'index',
'create',
'edit',
'delete'
],
'roles' => [
'index',
'create',
'edit',
'delete'
],
];
\ No newline at end of file
<?php <?php
return [ return [
]; ];
\ No newline at end of file
...@@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Redirect; ...@@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash; use Laracasts\Flash\Flash;
use Modules\Core\Http\Controllers\Admin\AdminBaseController; use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Core\Permissions\PermissionManager;
use Modules\User\Http\Requests\CreateRolesRequest; use Modules\User\Http\Requests\CreateRolesRequest;
use Modules\User\Http\Requests\UpdateRoleRequest; use Modules\User\Http\Requests\UpdateRoleRequest;
...@@ -71,13 +72,16 @@ class RolesController extends AdminBaseController ...@@ -71,13 +72,16 @@ class RolesController extends AdminBaseController
* @param int $id * @param int $id
* @return Response * @return Response
*/ */
public function edit($id) public function edit($id, PermissionManager $manager)
{ {
if (!$role = $this->roles->find($id)) { if (!$role = $this->roles->find($id)) {
return Redirect::to('user::admin.roles.index'); return Redirect::to('user::admin.roles.index');
} }
return View::make('user::admin.roles.edit', compact('role')); // Get all permissions
$permissions = $manager->all();
return View::make('user::admin.roles.edit', compact('role', 'permissions'));
} }
/** /**
...@@ -89,9 +93,14 @@ class RolesController extends AdminBaseController ...@@ -89,9 +93,14 @@ class RolesController extends AdminBaseController
*/ */
public function update($id, UpdateRoleRequest $request) public function update($id, UpdateRoleRequest $request)
{ {
$roles = [];
foreach ($request->roles as $roleName => $checkedRole) {
$roles[$roleName] = (bool)$checkedRole;
}
$role = $this->roles->find($id); $role = $this->roles->find($id);
$role->fill($request->all()); $role->fill($request->all());
$role->permissions = $roles;
$role->save(); $role->save();
Flash::success('Role updated!'); Flash::success('Role updated!');
......
...@@ -54,12 +54,19 @@ ...@@ -54,12 +54,19 @@
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-6">
<?php foreach($role->permissions as $name => $value): ?> <?php foreach($permissions as $name => $value): ?>
<div class="checkbox"> <h3>{{ $name }} Module</h3>
<label for="perm1"> <?php foreach($value as $subRoleTitle => $roleName): ?>
{{ $name }}<input id="perm1" type="checkbox" class="simple" <?php echo $value ? 'checked' : '' ?> /> <h4>{{ $subRoleTitle }}</h4>
</label> <?php foreach($roleName as $rolePerm): ?>
</div> <div class="checkbox">
<label for="<?php echo "$subRoleTitle.$rolePerm" ?>">
{{ $rolePerm }}
<input id="<?php echo "$subRoleTitle.$rolePerm" ?>" name="roles[<?php echo "$subRoleTitle.$rolePerm" ?>]" type="checkbox" class="simple" <?php echo $role->hasAccess("$subRoleTitle.$rolePerm") ? 'checked' : '' ?> value="true" />
</label>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
</div> </div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment