1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Ninja/Datatables/ProjectDatatable.php
David Bomba a9f2d0d855
This PR implements Create/View/Edit permissions based on ENTITY TYPE (ie invoice/expense/client). (#2150)
* migration for new permissions schema

* update permissions across data tables

* refactor migrations to prevent duplicate attribute

* update permissions in views

* Product Permissions

* permissions via controllers

* Refactor to use Laravel authorization gate

* Doc Blocks for EntityPolicy

* check permissions conditional on create new client

* Bug Fixes

* Data table permissions

* working on UI

* settings UI/UX finalised

* Datatable permissions

* remove legacy permissions

* permission fix for viewing client

* remove all instances of viewByOwner

* refactor after PR

* Bug fix for Functional test and implementation of Functional tests for Permissions

* fix for tests
2018-06-07 20:08:34 +10:00

87 lines
2.5 KiB
PHP

<?php
namespace App\Ninja\Datatables;
use Auth;
use URL;
use Utils;
class ProjectDatatable extends EntityDatatable
{
public $entityType = ENTITY_PROJECT;
public $sortCol = 1;
public function columns()
{
return [
[
'project',
function ($model) {
if (Auth::user()->can('view', [ENTITY_PROJECT, $model]))
return $this->addNote(link_to("projects/{$model->public_id}", $model->project)->toHtml(), $model->private_notes);
else
return $model->project;
},
],
[
'client_name',
function ($model) {
if ($model->client_public_id) {
if (Auth::user()->can('view', [ENTITY_CLIENT, $model]))
return link_to("clients/{$model->client_public_id}", $model->client_name)->toHtml();
else
return Utils::getClientDisplayName($model);
} else {
return '';
}
},
],
[
'due_date',
function ($model) {
return Utils::fromSqlDate($model->due_date);
},
],
[
'budgeted_hours',
function ($model) {
return $model->budgeted_hours ?: '';
},
],
[
'task_rate',
function ($model) {
return floatval($model->task_rate) ? Utils::formatMoney($model->task_rate) : '';
}
],
];
}
public function actions()
{
return [
[
trans('texts.edit_project'),
function ($model) {
return URL::to("projects/{$model->public_id}/edit");
},
function ($model) {
return Auth::user()->can('view', [ENTITY_PROJECT, $model]);
},
],
[
trans('texts.invoice_project'),
function ($model) {
return "javascript:submitForm_project('invoice', {$model->public_id})";
},
function ($model) {
return Auth::user()->can('create', ENTITY_INVOICE);
},
],
];
}
}