Commit 8c63d2bc authored by Nicolas Widart's avatar Nicolas Widart

Refactoring the permissions

parent 48d62cfd
...@@ -11,12 +11,20 @@ use Modules\User\Http\Requests\UpdateRoleRequest; ...@@ -11,12 +11,20 @@ use Modules\User\Http\Requests\UpdateRoleRequest;
class RolesController extends AdminBaseController class RolesController extends AdminBaseController
{ {
/**
* @var \Cartalyst\Sentinel\Roles\EloquentRole
*/
protected $roles; protected $roles;
/**
* @var PermissionManager
*/
private $permissions;
public function __construct() public function __construct(PermissionManager $permissions)
{ {
parent::__construct(); parent::__construct();
$this->roles = Sentinel::getRoleRepository()->createModel(); $this->roles = Sentinel::getRoleRepository()->createModel();
$this->permissions = $permissions;
} }
/** /**
...@@ -72,14 +80,14 @@ class RolesController extends AdminBaseController ...@@ -72,14 +80,14 @@ class RolesController extends AdminBaseController
* @param int $id * @param int $id
* @return Response * @return Response
*/ */
public function edit($id, PermissionManager $manager) public function edit($id)
{ {
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');
} }
// Get all permissions // Get all permissions
$permissions = $manager->all(); $permissions = $this->permissions->all();
return View::make('user::admin.roles.edit', compact('role', 'permissions')); return View::make('user::admin.roles.edit', compact('role', 'permissions'));
} }
...@@ -93,18 +101,14 @@ class RolesController extends AdminBaseController ...@@ -93,18 +101,14 @@ class RolesController extends AdminBaseController
*/ */
public function update($id, UpdateRoleRequest $request) public function update($id, UpdateRoleRequest $request)
{ {
$roles = []; $permissions = $this->permissions->clean($request->permissions);
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->permissions = $permissions;
$role->save(); $role->save();
Flash::success('Role updated!'); Flash::success('Role updated!');
return Redirect::route('dashboard.role.index'); return Redirect::route('dashboard.role.index');
} }
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
<div class="checkbox"> <div class="checkbox">
<label for="<?php echo "$subRoleTitle.$rolePerm" ?>"> <label for="<?php echo "$subRoleTitle.$rolePerm" ?>">
{{ $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" /> <input id="<?php echo "$subRoleTitle.$rolePerm" ?>" name="permissions[<?php echo "$subRoleTitle.$rolePerm" ?>]" type="checkbox" class="simple" <?php echo $role->hasAccess("$subRoleTitle.$rolePerm") ? 'checked' : '' ?> value="true" />
</label> </label>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
......
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