invoiceninja/app/Policies/GenericEntityPolicy.php

76 lines
2 KiB
PHP
Raw Normal View History

2016-04-25 21:53:39 -04:00
<?php
namespace App\Policies;
2016-04-25 21:53:39 -04:00
use App\Models\User;
2016-04-26 20:06:19 -04:00
use Utils;
2016-04-25 21:53:39 -04:00
use Illuminate\Auth\Access\HandlesAuthorization;
/**
* Class GenericEntityPolicy
*/
2016-04-25 21:53:39 -04:00
class GenericEntityPolicy
{
use HandlesAuthorization;
/**
* @param User $user
* @param $itemType
* @param $ownerUserId
* @return bool|mixed
*/
public static function editByOwner(User $user, $itemType, $ownerUserId) {
2016-04-26 20:06:19 -04:00
$itemType = Utils::getEntityName($itemType);
2016-04-25 21:53:39 -04:00
if (method_exists("App\\Policies\\{$itemType}Policy", 'editByOwner')) {
return call_user_func(["App\\Policies\\{$itemType}Policy", 'editByOwner'], $user, $ownerUserId);
2016-04-25 21:53:39 -04:00
}
2016-10-27 11:57:51 +03:00
2016-04-25 21:53:39 -04:00
return false;
}
/**
* @param User $user
* @param $itemType
* @param $ownerUserId
* @return bool|mixed
*/
public static function viewByOwner(User $user, $itemType, $ownerUserId) {
2016-04-26 20:06:19 -04:00
$itemType = Utils::getEntityName($itemType);
2016-04-25 21:53:39 -04:00
if (method_exists("App\\Policies\\{$itemType}Policy", 'viewByOwner')) {
return call_user_func(["App\\Policies\\{$itemType}Policy", 'viewByOwner'], $user, $ownerUserId);
2016-04-25 21:53:39 -04:00
}
2016-10-27 11:57:51 +03:00
2016-04-25 21:53:39 -04:00
return false;
}
/**
* @param User $user
* @param $itemType
* @return bool|mixed
*/
public static function create(User $user, $itemType) {
2016-10-27 11:57:51 +03:00
$entityName = Utils::getEntityName($itemType);
if (method_exists("App\\Policies\\{$entityName}Policy", 'create')) {
return call_user_func(["App\\Policies\\{$entityName}Policy", 'create'], $user, $itemType);
2016-04-25 21:53:39 -04:00
}
2016-10-27 11:57:51 +03:00
2016-04-25 21:53:39 -04:00
return false;
}
2016-10-27 11:57:51 +03:00
/**
* @param User $user
* @param $itemType
* @return bool|mixed
*/
public static function view(User $user, $itemType) {
$entityName = Utils::getEntityName($itemType);
if (method_exists("App\\Policies\\{$entityName}Policy", 'view')) {
return call_user_func(["App\\Policies\\{$entityName}Policy", 'view'], $user, $itemType);
}
return false;
}
}