Commit 926a7bc6 authored by Nicolas Widart's avatar Nicolas Widart

Decouple the role controller from sentinel

parent c24b6541
...@@ -8,6 +8,7 @@ use Modules\Core\Http\Controllers\Admin\AdminBaseController; ...@@ -8,6 +8,7 @@ use Modules\Core\Http\Controllers\Admin\AdminBaseController;
use Modules\Core\Permissions\PermissionManager; 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;
use Modules\User\Repositories\RoleRepository;
class RolesController extends AdminBaseController class RolesController extends AdminBaseController
{ {
...@@ -19,12 +20,17 @@ class RolesController extends AdminBaseController ...@@ -19,12 +20,17 @@ class RolesController extends AdminBaseController
* @var PermissionManager * @var PermissionManager
*/ */
private $permissions; private $permissions;
/**
* @var RoleRepository
*/
private $role;
public function __construct(PermissionManager $permissions) public function __construct(PermissionManager $permissions, RoleRepository $role)
{ {
parent::__construct(); parent::__construct();
$this->roles = Sentinel::getRoleRepository()->createModel(); $this->roles = Sentinel::getRoleRepository()->createModel();
$this->permissions = $permissions; $this->permissions = $permissions;
$this->role = $role;
$this->beforeFilter('permissions'); $this->beforeFilter('permissions');
} }
...@@ -35,7 +41,7 @@ class RolesController extends AdminBaseController ...@@ -35,7 +41,7 @@ class RolesController extends AdminBaseController
*/ */
public function index() public function index()
{ {
$roles = $this->roles->all(); $roles = $this->role->all();
return View::make('user::admin.roles.index', compact('roles')); return View::make('user::admin.roles.index', compact('roles'));
} }
...@@ -59,23 +65,13 @@ class RolesController extends AdminBaseController ...@@ -59,23 +65,13 @@ class RolesController extends AdminBaseController
public function store(CreateRolesRequest $request) public function store(CreateRolesRequest $request)
{ {
$data = array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]); $data = array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]);
$this->roles->create($data);
Flash::success('Role created'); $this->role->create($data);
Flash::success('Role created');
return Redirect::route('dashboard.role.index'); return Redirect::route('dashboard.role.index');
} }
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
}
/** /**
* Show the form for editing the specified resource. * Show the form for editing the specified resource.
* *
...@@ -84,7 +80,7 @@ class RolesController extends AdminBaseController ...@@ -84,7 +80,7 @@ class RolesController extends AdminBaseController
*/ */
public function edit($id) public function edit($id)
{ {
if (!$role = $this->roles->find($id)) { if (!$role = $this->role->find($id)) {
return Redirect::to('user::admin.roles.index'); return Redirect::to('user::admin.roles.index');
} }
...@@ -100,12 +96,9 @@ class RolesController extends AdminBaseController ...@@ -100,12 +96,9 @@ class RolesController extends AdminBaseController
*/ */
public function update($id, UpdateRoleRequest $request) public function update($id, UpdateRoleRequest $request)
{ {
$permissions = $this->permissions->clean($request->permissions); $data = array_merge($request->all(), ['permissions' => $this->permissions->clean($request->permissions)]);
$role = $this->roles->find($id);
$role->fill($request->all()); $this->role->update($id, $data);
$role->permissions = $permissions;
$role->save();
Flash::success('Role updated!'); Flash::success('Role updated!');
return Redirect::route('dashboard.role.index'); return Redirect::route('dashboard.role.index');
...@@ -119,14 +112,9 @@ class RolesController extends AdminBaseController ...@@ -119,14 +112,9 @@ class RolesController extends AdminBaseController
*/ */
public function destroy($id) public function destroy($id)
{ {
if ($role = $this->roles->find($id)) $this->role->delete($id);
{
$role->delete();
Flash::success('Role deleted!');
return Redirect::route('dashboard.role.index');
}
Flash::success('Role deleted!');
return Redirect::route('dashboard.role.index'); return Redirect::route('dashboard.role.index');
} }
} }
\ No newline at end of file
<?php namespace Modules\User\Repositories; <?php namespace Modules\User\Repositories;
/**
* Interface RoleRepository
* @package Modules\User\Repositories
*/
interface RoleRepository interface RoleRepository
{ {
/** /**
...@@ -13,4 +17,26 @@ interface RoleRepository ...@@ -13,4 +17,26 @@ interface RoleRepository
* @return mixed * @return mixed
*/ */
public function create($data); public function create($data);
/**
* Find a role by its id
* @param $id
* @return mixed
*/
public function find($id);
/**
* Update a role
* @param $id
* @param $data
* @return mixed
*/
public function update($id, $data);
/**
* Delete a role
* @param $id
* @return mixed
*/
public function delete($id);
} }
\ No newline at end of file
...@@ -30,6 +30,43 @@ class SentinelRoleRepository implements RoleRepository ...@@ -30,6 +30,43 @@ class SentinelRoleRepository implements RoleRepository
*/ */
public function create($data) public function create($data)
{ {
// TODO: Implement create() method. $this->role->create($data);
}
/**
* Find a role by its id
* @param $id
* @return mixed
*/
public function find($id)
{
return $this->role->find($id);
}
/**
* Update a role
* @param $id
* @param $data
* @return mixed
*/
public function update($id, $data)
{
$role = $this->role->find($id);
$role->fill($data);
$role->save();
}
/**
* Delete a role
* @param $id
* @return mixed
*/
public function delete($id)
{
$role = $this->role->find($id);
return $role->delete();
} }
} }
\ No newline at end of file
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