Skip to content

Commit

Permalink
Optimizes the assign permission setup further
Browse files Browse the repository at this point in the history
  • Loading branch information
artstorm committed Jul 14, 2015
1 parent ff0971b commit 50bab1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
21 changes: 17 additions & 4 deletions api/app/Extensions/Lock/LockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,23 @@ trait LockTrait
/**
* Give the subject permission to do something.
*
* @param string|array $action
* @param string|\BeatSwitch\Lock\Resources\Resource $resource
* @param int $resourceId
* @param \BeatSwitch\Lock\Permissions\Condition|\BeatSwitch\Lock\Permissions\Condition[]|\Closure $conditions
* @param string|array $action
* @param array $conditions
* @return void
*/
public function permit($action, array $conditions = [])
{
$this->allow($action, null, null, $conditions);
}

/**
* Give the subject permission to do something.
*
* @param string|array $action
* @param string|\BeatSwitch\Lock\Resources\Resource $resource
* @param int $resourceId
* @param array $conditions
* @return void
*/
public function allow($action, $resource = null, $resourceId = null, $conditions = [])
{
Expand Down
9 changes: 2 additions & 7 deletions api/app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@ public function assignPermissions(Request $request)
$user = $this->jwtAuth->user();
$owner = [User::class, 'userIsOwner', $user, last($request->segments())];

$this->lock->role(User::USER_TYPE_ADMIN)->allow('readAll');
$this->lock->role(User::USER_TYPE_ADMIN)->allow('readOne');
$this->lock->role(User::USER_TYPE_ADMIN)->allow('update');
$this->lock->role(User::USER_TYPE_ADMIN)->allow('delete');

$this->lock->role(User::USER_TYPE_GUEST)->allow('readOne', null, null, [$owner]);
$this->lock->role(User::USER_TYPE_GUEST)->allow('update', null, null, [$owner]);
$this->lock->role(User::USER_TYPE_ADMIN)->permit(['readAll', 'readOne', 'update', 'delete']);
$this->lock->role(User::USER_TYPE_GUEST)->permit(['readOne', 'update'], [$owner]);
}
}

0 comments on commit 50bab1b

Please sign in to comment.