2016-04-23 17:52:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\EntityModel;
|
|
|
|
|
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
2016-04-26 03:53:39 +02:00
|
|
|
class EntityPolicy
|
2016-04-23 17:52:36 +02:00
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
2016-04-26 03:53:39 +02:00
|
|
|
public static function create($user) {
|
|
|
|
return $user->hasPermission('create_all');
|
2016-04-23 17:52:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function edit($user, $item) {
|
2016-04-26 03:53:39 +02:00
|
|
|
return $user->hasPermission('edit_all') || $user->owns($item);
|
2016-04-23 17:52:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function view($user, $item) {
|
2016-04-26 03:53:39 +02:00
|
|
|
return $user->hasPermission('view_all') || $user->owns($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function viewByOwner($user, $ownerUserId) {
|
|
|
|
return $user->hasPermission('view_all') || $user->id == $ownerUserId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function editByOwner($user, $ownerUserId) {
|
|
|
|
return $user->hasPermission('edit_all') || $user->id == $ownerUserId;
|
2016-04-23 17:52:36 +02:00
|
|
|
}
|
|
|
|
}
|