mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-12-31 16:10:54 -05:00
* Wire up Create Entity Button to create route * Refactor permissions, we must also ensure the user company id and entity id matches at the Gate:: * Add translations for Status filters * Bug fix for initial list view not displaying * Apply actions to menu for list items * Wire up list view actions, individual * Place permission filters on datatable lists
68 lines
1.6 KiB
PHP
68 lines
1.6 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
|
|
{
|
|
$entity = strtolower(class_basename($entity));
|
|
|
|
return ($user->isAdmin() && $entity->company_id == $user->company()->pivot->company_id)
|
|
|| ($user->hasPermission('edit_' . $entity) && $entity->company_id == $user->company()->pivot->company_id)
|
|
|| $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
|
|
{
|
|
$entity = strtolower(class_basename($entity));
|
|
|
|
return ($user->isAdmin() && $entity->company_id == $user->company()->pivot->company_id)
|
|
|| ($user->hasPermission('view_' . $entity) && $entity->company_id == $user->company()->pivot->company_id)
|
|
|| $user->owns($entity);
|
|
}
|
|
|
|
|
|
}
|