FEATURE: add form for setting default permissions and fix few bugs

This commit is contained in:
Michal Kváček
2017-08-23 21:34:56 +02:00
parent 0aaa626124
commit e0f5cba9a4
31 changed files with 150 additions and 482 deletions
+13 -11
View File
@@ -9,15 +9,23 @@ use Illuminate\Database\Eloquent\Model;
abstract class BasicPolicy
{
use HandlesAuthorization;
protected $entity;
/**
* Check if user has ability to manage entity before evaluating any other policy method
* @param User $user
* @param $ability
*
* @return bool|null
*/
public function before(User $user, $ability)
{
// check if user can operate on given entity
if (!$this->manage($user)) {
return false;
}
return null;
}
/**
@@ -27,15 +35,9 @@ abstract class BasicPolicy
*
* @return bool
*/
public function manage(User $user) {
if (!$user->hasAbility($this->entity.'-management')) {
// echo "<pre>";
// debug_print_backtrace();
// echo "</pre>";
// die();
}
return $user->hasAbility($this->entity.'-management');
public function manage(User $user)
{
return $user->hasAbility($this->entity . '-management');
}
/**
@@ -48,6 +50,6 @@ abstract class BasicPolicy
*/
public function delete(User $user, Model $model)
{
return $user->hasAbility('delete-'.$this->entity);
return $user->hasAbility('delete-' . $this->entity);
}
}