1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/app/Policies/UserPolicy.php

46 lines
1013 B
PHP
Raw Normal View History

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');
}
//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
}