1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Policies/GenericEntityPolicy.php

60 lines
1.6 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
}
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
}
return false;
}
/**
* @param User $user
* @param $itemType
* @return bool|mixed
*/
public static function create(User $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(["App\\Policies\\{$itemType}Policy", 'create'], $user);
2016-04-26 03:53:39 +02:00
}
return false;
}
}