2019-04-27 11:20:03 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-04-27 11:20:03 +02:00
|
|
|
|
|
|
|
namespace App\Policies;
|
|
|
|
|
|
|
|
use App\Models\Client;
|
|
|
|
use App\Models\User;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class UserPolicy
|
|
|
|
* @package App\Policies
|
|
|
|
*/
|
|
|
|
class UserPolicy extends EntityPolicy
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Checks if the user has create permissions
|
|
|
|
*
|
|
|
|
* @param User $user
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function create(User $user) : bool
|
|
|
|
{
|
|
|
|
return $user->isAdmin() || $user->hasPermission('create_user');
|
|
|
|
}
|
|
|
|
|
2019-06-12 01:15:17 +02:00
|
|
|
|
|
|
|
//we need to override as User does not have the company_id property!!!!!
|
|
|
|
public function edit(User $user, $entity) : bool
|
|
|
|
{
|
|
|
|
|
|
|
|
return ($user->isAdmin() && $entity->company_id == $user->companyId())
|
|
|
|
|| ($user->hasPermission('edit_' . strtolower(class_basename($entity))) && $entity->company_id == $user->companyId())
|
|
|
|
|| $user->owns($entity);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-27 11:20:03 +02:00
|
|
|
}
|