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
return [
];
\ No newline at end of file
......@@ -5,6 +5,7 @@ use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash;
use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Core\Permissions\PermissionManager;
use Modules\User\Http\Requests\CreateRolesRequest;
use Modules\User\Http\Requests\UpdateRoleRequest;
......@@ -71,13 +72,16 @@ class RolesController extends AdminBaseController
* @param int $id
* @return Response
*/
public function edit($id)
public function edit($id, PermissionManager $manager)
{
if (!$role = $this->roles->find($id)) {
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
*/
public function update($id, UpdateRoleRequest $request)
{
$roles = [];
foreach ($request->roles as $roleName => $checkedRole) {
$roles[$roleName] = (bool)$checkedRole;
}
$role = $this->roles->find($id);
$role->fill($request->all());
$role->permissions = $roles;
$role->save();
Flash::success('Role updated!');
......
......@@ -54,12 +54,19 @@
</div>
<div class="row">
<div class="col-md-6">
<?php foreach($role->permissions as $name => $value): ?>
<div class="checkbox">
<label for="perm1">
{{ $name }}<input id="perm1" type="checkbox" class="simple" <?php echo $value ? 'checked' : '' ?> />
</label>
</div>
<?php foreach($permissions as $name => $value): ?>
<h3>{{ $name }} Module</h3>
<?php foreach($value as $subRoleTitle => $roleName): ?>
<h4>{{ $subRoleTitle }}</h4>
<?php foreach($roleName as $rolePerm): ?>
<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; ?>
</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