1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Policies/GenericEntityPolicy.php

76 lines
2.0 KiB
PHP
Raw Normal View History

2016-04-26 03:53:39 +02:00
<?php
namespace App\Policies;
2016-04-26 03:53:39 +02:00
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
*/
2016-04-26 03:53:39 +02: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-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(["App\\Policies\\{$itemType}Policy", 'editByOwner'], $user, $ownerUserId);
2016-04-26 03:53:39 +02:00
}
2016-10-27 10:57:51 +02:00
2016-04-26 03:53:39 +02:00
return false;
}
/**
* @param User $user
* @param $itemType
* @param $ownerUserId
* @return bool|mixed
*/
public static function viewByOwner(User $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(["App\\Policies\\{$itemType}Policy", 'viewByOwner'], $user, $ownerUserId);
2016-04-26 03:53:39 +02:00
}
2016-10-27 10:57:51 +02:00
2016-04-26 03:53:39 +02:00
return false;
}
/**
* @param User $user
* @param $itemType
* @return bool|mixed
*/
public static function create(User $user, $itemType) {
2016-10-27 10:57:51 +02: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-26 03:53:39 +02:00
}
2016-10-27 10:57:51 +02:00
2016-04-26 03:53:39 +02:00
return false;
}
2016-10-27 10:57:51 +02: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;
}
}