mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
cf1e65f1c0
* Refactor pivot table accessors * Add select2 for client - country selector * Fixes for client contact update * implement ctrans() function across application * Increase custom fields to 4 across the application * Refactor: remove repos calling other repos, implement 4 custom values across application * include querying the custom values in the client list * Fix null custom value labels * Scaffold for client - show view * Working on Client Show
67 lines
1.5 KiB
PHP
67 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Policies;
|
|
|
|
use App\Models\User;
|
|
|
|
/**
|
|
* Class EntityPolicy
|
|
* @package App\Policies
|
|
*/
|
|
class EntityPolicy
|
|
{
|
|
/**
|
|
* Fires before any of the custom policy methods
|
|
*
|
|
* Only fires if true, if false we continue.....
|
|
*
|
|
* Do not use this function!!!! We MUST also check company_id,
|
|
*
|
|
* @param User $user
|
|
* @param $ability
|
|
* @return bool/void
|
|
*/
|
|
public function before($user, $ability)
|
|
{
|
|
//if($user->isAdmin())
|
|
// return true;
|
|
}
|
|
|
|
/**
|
|
* Checks if the user has edit permissions
|
|
*
|
|
* We MUST also check that the user can both edit a entity and also check the entity belongs to the users company!!!!!!
|
|
*
|
|
* @param User $user
|
|
* @param $entity
|
|
* @return bool
|
|
*/
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
* Checks if the user has view permissions
|
|
*
|
|
* We MUST also check that the user can both view a entity and also check the entity belongs to the users company!!!!!!
|
|
* @param User $user
|
|
* @param $entity
|
|
* @return bool
|
|
*/
|
|
public function view(User $user, $entity) : bool
|
|
{
|
|
|
|
return ($user->isAdmin() && $entity->company_id == $user->companyId())
|
|
|| ($user->hasPermission('view_' . strtolower(class_basename($entity))) && $entity->company_id == $user->companyId())
|
|
|| $user->owns($entity);
|
|
}
|
|
|
|
|
|
}
|