mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Permission fixes. (#2407)
* Patch for permissions * fixes for production * fix for doc uploads
This commit is contained in:
parent
e2d8ba4b60
commit
cd10003d64
@ -19,19 +19,8 @@ class CreateDocumentRequest extends DocumentRequest
|
|||||||
*/
|
*/
|
||||||
public function authorize()
|
public function authorize()
|
||||||
{
|
{
|
||||||
if (! $this->user()->hasFeature(FEATURE_DOCUMENTS)) {
|
if($this->user()->hasFeature(FEATURE_DOCUMENTS))
|
||||||
return false;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->invoice && $this->user()->cannot('edit', $this->invoice)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->expense && $this->user()->cannot('edit', $this->expense)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->user()->can('create', ENTITY_DOCUMENT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +25,15 @@ class InvoiceRequest extends EntityRequest
|
|||||||
else
|
else
|
||||||
$standardOrRecurringInvoice = ENTITY_INVOICE;
|
$standardOrRecurringInvoice = ENTITY_INVOICE;
|
||||||
|
|
||||||
|
if(request()->is('invoices/*/edit') && request()->isMethod('get') && $this->user()->can('edit', $invoice))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if(request()->is('quotes/*/edit') && request()->isMethod('get') && $this->user()->can('edit', $invoice))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if(request()->is('invoices/create') && $this->user()->can('create', ENTITY_INVOICE))
|
||||||
|
return true;
|
||||||
|
|
||||||
if(request()->is('invoices/create') && !$this->user()->can('create', ENTITY_INVOICE))
|
if(request()->is('invoices/create') && !$this->user()->can('create', ENTITY_INVOICE))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -364,6 +364,17 @@ class User extends Authenticatable
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function viewModel($model, $entityType)
|
||||||
|
{
|
||||||
|
if($this->hasPermission('view_'.$entityType))
|
||||||
|
return true;
|
||||||
|
elseif($model->user_id == $this->id)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $entity
|
* @param $entity
|
||||||
*
|
*
|
||||||
|
@ -20,7 +20,7 @@ class InvoiceDatatable extends EntityDatatable
|
|||||||
[
|
[
|
||||||
$entityType == ENTITY_INVOICE ? 'invoice_number' : 'quote_number',
|
$entityType == ENTITY_INVOICE ? 'invoice_number' : 'quote_number',
|
||||||
function ($model) use ($entityType) {
|
function ($model) use ($entityType) {
|
||||||
if(Auth::user()->can('view', [$this->entityType, $model])) {
|
if(Auth::user()->viewModel($model, $entityType)) {
|
||||||
$str = link_to("{$entityType}s/{$model->public_id}/edit", $model->invoice_number, ['class' => Utils::getEntityRowClass($model)])->toHtml();
|
$str = link_to("{$entityType}s/{$model->public_id}/edit", $model->invoice_number, ['class' => Utils::getEntityRowClass($model)])->toHtml();
|
||||||
return $this->addNote($str, $model->private_notes);
|
return $this->addNote($str, $model->private_notes);
|
||||||
}
|
}
|
||||||
|
@ -57,12 +57,18 @@ class GenericEntityPolicy
|
|||||||
*/
|
*/
|
||||||
public static function create(User $user, $entityType)
|
public static function create(User $user, $entityType)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
$className = static::className($entityType);
|
$className = static::className($entityType);
|
||||||
if (method_exists($className, 'create')) {
|
if (method_exists($className, 'create')) {
|
||||||
return call_user_func([$className, 'create'], $user, $entityType);
|
return call_user_func([$className, 'create'], $user, $entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
*/
|
||||||
|
if($user->hasPermission('create_'.$entityType))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -73,12 +79,18 @@ class GenericEntityPolicy
|
|||||||
*/
|
*/
|
||||||
public static function view(User $user, $entityType)
|
public static function view(User $user, $entityType)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
$className = static::className($entityType);
|
$className = static::className($entityType);
|
||||||
if (method_exists($className, 'view')) {
|
if (method_exists($className, 'view')) {
|
||||||
return call_user_func([$className, 'view'], $user, $entityType);
|
return call_user_func([$className, 'view'], $user, $entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;*/
|
||||||
|
|
||||||
|
if($user->hasPermission('view_'.$entityType))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user