2016-04-26 03:53:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
use App\Models\User;
|
2016-04-27 02:06:19 +02:00
|
|
|
use Utils;
|
2016-04-26 03:53:39 +02:00
|
|
|
|
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
|
|
|
|
|
|
|
class GenericEntityPolicy
|
|
|
|
{
|
|
|
|
use HandlesAuthorization;
|
|
|
|
|
|
|
|
public static function editByOwner($user, $itemType, $ownerUserId) {
|
2016-04-27 02:06:19 +02:00
|
|
|
$itemType = Utils::getEntityName($itemType);
|
2016-04-26 03:53:39 +02:00
|
|
|
if (method_exists("App\\Policies\\{$itemType}Policy", 'editByOwner')) {
|
|
|
|
return call_user_func(array("App\\Policies\\{$itemType}Policy", 'editByOwner'), $user, $ownerUserId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function viewByOwner($user, $itemType, $ownerUserId) {
|
2016-04-27 02:06:19 +02:00
|
|
|
$itemType = Utils::getEntityName($itemType);
|
2016-04-26 03:53:39 +02:00
|
|
|
if (method_exists("App\\Policies\\{$itemType}Policy", 'viewByOwner')) {
|
|
|
|
return call_user_func(array("App\\Policies\\{$itemType}Policy", 'viewByOwner'), $user, $ownerUserId);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function create($user, $itemType) {
|
2016-04-27 02:06:19 +02:00
|
|
|
$itemType = Utils::getEntityName($itemType);
|
2016-04-26 03:53:39 +02:00
|
|
|
if (method_exists("App\\Policies\\{$itemType}Policy", 'create')) {
|
|
|
|
return call_user_func(array("App\\Policies\\{$itemType}Policy", 'create'), $user);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|