mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 09:14:36 -04:00
V5.0 (#2617)
* Add URL link directly to client view in list view * Implement Form requests for all client routes * Refactor how permissions are implemented on Datatable row action menus * fixes for tests * bug fix * Add ctrans global function for custom translations. Reduced DB queries for Client List. Added Debugbar for dev environments * ctrans
This commit is contained in:
parent
da325e1797
commit
37e4b67ab9
@ -95,10 +95,10 @@ trait MakesActionMenu
|
|||||||
* @param bool $isAdmin Boolean isAdmin
|
* @param bool $isAdmin Boolean isAdmin
|
||||||
* @return Collection collection of filtered actions available to the user
|
* @return Collection collection of filtered actions available to the user
|
||||||
*/
|
*/
|
||||||
public function filterActions(array $actions, array $permissions, bool $isAdmin) :Collection
|
public function filterActions(array $actions, array $permissions, bool $is_admin) :Collection
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->checkPermissions($this->actions()->whereIn('action', $actions), $permissions, $isAdmin);
|
return $this->checkPermissions($this->actions()->whereIn('action', $actions), $permissions, $is_admin);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
app/Helpers/TranslationHelper.php
Normal file
20
app/Helpers/TranslationHelper.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a custom translation string
|
||||||
|
* falls back on defaults if no string exists
|
||||||
|
*
|
||||||
|
* //Cache::forever($custom_company_translated_string, 'mogly');
|
||||||
|
*
|
||||||
|
* @param string translation string key
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
function ctrans(string $string) : string
|
||||||
|
{
|
||||||
|
//todo pass through the cached version of the custom strings here else return trans();
|
||||||
|
|
||||||
|
return trans($string);
|
||||||
|
|
||||||
|
}
|
@ -41,7 +41,8 @@ class ClientController extends Controller
|
|||||||
|
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
|
//dd(ctrans('texts.country_id'));
|
||||||
|
//dd(auth()->user());
|
||||||
if(request('page'))
|
if(request('page'))
|
||||||
return $this->clientDatatable->query(request(), $this->getCurrentCompanyId());
|
return $this->clientDatatable->query(request(), $this->getCurrentCompanyId());
|
||||||
|
|
||||||
@ -124,7 +125,6 @@ class ClientController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function edit(EditClientRequest $request, Client $client)
|
public function edit(EditClientRequest $request, Client $client)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data = [
|
$data = [
|
||||||
'client' => $client,
|
'client' => $client,
|
||||||
'settings' => [],
|
'settings' => [],
|
||||||
|
@ -27,6 +27,8 @@ class Client extends BaseModel
|
|||||||
'q'
|
'q'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $with = ['contacts', 'primary_contact'];
|
||||||
|
|
||||||
//protected $dates = ['deleted_at'];
|
//protected $dates = ['deleted_at'];
|
||||||
|
|
||||||
public function getHashedIdAttribute()
|
public function getHashedIdAttribute()
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\CompanyUser;
|
||||||
use App\Models\Traits\UserTrait;
|
use App\Models\Traits\UserTrait;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\UserSessionAttributes;
|
use App\Utils\Traits\UserSessionAttributes;
|
||||||
@ -28,6 +29,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
|
|
||||||
protected $presenter = 'App\Models\Presenters\UserPresenter';
|
protected $presenter = 'App\Models\Presenters\UserPresenter';
|
||||||
|
|
||||||
|
protected $with = ['companies', 'user_companies'];
|
||||||
/**
|
/**
|
||||||
* The attributes that are mass assignable.
|
* The attributes that are mass assignable.
|
||||||
*
|
*
|
||||||
@ -69,13 +71,24 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current company
|
* Returns the pivot tables for Company / User
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function user_companies()
|
||||||
|
{
|
||||||
|
return $this->hasMany(CompanyUser::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current company by
|
||||||
|
* querying directly on the pivot table relationship
|
||||||
*
|
*
|
||||||
* @return Collection
|
* @return Collection
|
||||||
*/
|
*/
|
||||||
public function company()
|
public function company()
|
||||||
{
|
{
|
||||||
return $this->companies()->where('company_id', $this->getCurrentCompanyId())->first();
|
return $this->user_companies->where('company_id', $this->getCurrentCompanyId())->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +99,7 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
public function permissions()
|
public function permissions()
|
||||||
{
|
{
|
||||||
|
|
||||||
$permissions = json_decode($this->company()->pivot->permissions);
|
$permissions = json_decode($this->company()->permissions);
|
||||||
|
|
||||||
if (! $permissions)
|
if (! $permissions)
|
||||||
return [];
|
return [];
|
||||||
@ -101,7 +114,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function settings()
|
public function settings()
|
||||||
{
|
{
|
||||||
return json_decode($this->company()->pivot->settings);
|
|
||||||
|
return json_decode($this->company()->settings);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,7 +126,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function isAdmin() : bool
|
public function isAdmin() : bool
|
||||||
{
|
{
|
||||||
return (bool) $this->company()->pivot->is_admin;
|
|
||||||
|
return (bool) $this->company()->is_admin;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -121,7 +138,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function contacts()
|
public function contacts()
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->hasMany(Contact::class);
|
return $this->hasMany(Contact::class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,7 +151,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function owns($entity) : bool
|
public function owns($entity) : bool
|
||||||
{
|
{
|
||||||
|
|
||||||
return ! empty($entity->user_id) && $entity->user_id == $this->id;
|
return ! empty($entity->user_id) && $entity->user_id == $this->id;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -143,7 +164,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function permissionsFlat() :Collection
|
public function permissionsFlat() :Collection
|
||||||
{
|
{
|
||||||
|
|
||||||
return collect($this->permissions())->flatten();
|
return collect($this->permissions())->flatten();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,7 +177,9 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*/
|
*/
|
||||||
public function hasPermission($permission) : bool
|
public function hasPermission($permission) : bool
|
||||||
{
|
{
|
||||||
|
|
||||||
return $this->permissionsFlat()->contains($permission);
|
return $this->permissionsFlat()->contains($permission);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -162,13 +187,14 @@ class User extends Authenticatable implements MustVerifyEmail
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function permissionsMap()
|
public function permissionsMap() : array
|
||||||
{
|
{
|
||||||
|
|
||||||
$keys = array_values((array) $this->permissions());
|
$keys = array_values((array) $this->permissions());
|
||||||
$values = array_fill(0, count($keys), true);
|
$values = array_fill(0, count($keys), true);
|
||||||
|
|
||||||
return array_combine($keys, $values);
|
return array_combine($keys, $values);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -38,9 +38,11 @@ class EntityPolicy
|
|||||||
*/
|
*/
|
||||||
public function edit(User $user, $entity) : bool
|
public function edit(User $user, $entity) : bool
|
||||||
{
|
{
|
||||||
return ($user->isAdmin() && $entity->company_id == $user->company()->pivot->company_id)
|
|
||||||
|| ($user->hasPermission('edit_' . strtolower(class_basename($entity))) && $entity->company_id == $user->company()->pivot->company_id)
|
return ($user->isAdmin() && $entity->company_id == $user->company()->company_id)
|
||||||
|
|| ($user->hasPermission('edit_' . strtolower(class_basename($entity))) && $entity->company_id == $user->company()->company_id)
|
||||||
|| $user->owns($entity);
|
|| $user->owns($entity);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -54,8 +56,9 @@ class EntityPolicy
|
|||||||
*/
|
*/
|
||||||
public function view(User $user, $entity) : bool
|
public function view(User $user, $entity) : bool
|
||||||
{
|
{
|
||||||
return ($user->isAdmin() && $entity->company_id == $user->company()->pivot->company_id)
|
|
||||||
|| ($user->hasPermission('view_' . strtolower(class_basename($entity))) && $entity->company_id == $user->company()->pivot->company_id)
|
return ($user->isAdmin() && $entity->company_id == $user->company()->company_id)
|
||||||
|
|| ($user->hasPermission('view_' . strtolower(class_basename($entity))) && $entity->company_id == $user->company()->company_id)
|
||||||
|| $user->owns($entity);
|
|| $user->owns($entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,13 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function register()
|
public function register()
|
||||||
{
|
{
|
||||||
//
|
$this->loadHelpers();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function loadHelpers()
|
||||||
|
{
|
||||||
|
foreach (glob(__DIR__.'/../Helpers/*.php') as $filename) {
|
||||||
|
require_once $filename;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Route::bind('client', function ($value) {
|
Route::bind('client', function ($value) {
|
||||||
$client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404);
|
$client = \App\Models\Client::withTrashed()->where('id', $this->decodePrimaryKey($value))->first() ?? abort(404);
|
||||||
$client->load('contacts', 'primary_contact');
|
//$client->load('contacts', 'primary_contact');
|
||||||
return $client;
|
return $client;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
"wildbit/postmark-php": "^2.6"
|
"wildbit/postmark-php": "^2.6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
"barryvdh/laravel-debugbar": "^3.2",
|
||||||
"beyondcode/laravel-dump-server": "^1.0",
|
"beyondcode/laravel-dump-server": "^1.0",
|
||||||
"filp/whoops": "^2.0",
|
"filp/whoops": "^2.0",
|
||||||
"fzaninotto/faker": "^1.4",
|
"fzaninotto/faker": "^1.4",
|
||||||
|
131
composer.lock
generated
131
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "f070f7f4ccfe346840e4dfd0e39650a5",
|
"content-hash": "b41a1819d57b9ee31cec2012cc37704f",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "asgrim/ofxparser",
|
"name": "asgrim/ofxparser",
|
||||||
@ -3796,6 +3796,74 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
{
|
||||||
|
"name": "barryvdh/laravel-debugbar",
|
||||||
|
"version": "v3.2.1",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/barryvdh/laravel-debugbar.git",
|
||||||
|
"reference": "9d5caf43c5f3a3aea2178942f281054805872e7c"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/9d5caf43c5f3a3aea2178942f281054805872e7c",
|
||||||
|
"reference": "9d5caf43c5f3a3aea2178942f281054805872e7c",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"illuminate/routing": "5.5.x|5.6.x|5.7.x",
|
||||||
|
"illuminate/session": "5.5.x|5.6.x|5.7.x",
|
||||||
|
"illuminate/support": "5.5.x|5.6.x|5.7.x",
|
||||||
|
"maximebf/debugbar": "~1.15.0",
|
||||||
|
"php": ">=7.0",
|
||||||
|
"symfony/debug": "^3|^4",
|
||||||
|
"symfony/finder": "^3|^4"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"laravel/framework": "5.5.x"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "3.2-dev"
|
||||||
|
},
|
||||||
|
"laravel": {
|
||||||
|
"providers": [
|
||||||
|
"Barryvdh\\Debugbar\\ServiceProvider"
|
||||||
|
],
|
||||||
|
"aliases": {
|
||||||
|
"Debugbar": "Barryvdh\\Debugbar\\Facade"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Barryvdh\\Debugbar\\": "src/"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"src/helpers.php"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Barry vd. Heuvel",
|
||||||
|
"email": "barryvdh@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "PHP Debugbar integration for Laravel",
|
||||||
|
"keywords": [
|
||||||
|
"debug",
|
||||||
|
"debugbar",
|
||||||
|
"laravel",
|
||||||
|
"profiler",
|
||||||
|
"webprofiler"
|
||||||
|
],
|
||||||
|
"time": "2018-11-09T08:37:55+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "beyondcode/laravel-dump-server",
|
"name": "beyondcode/laravel-dump-server",
|
||||||
"version": "1.2.2",
|
"version": "1.2.2",
|
||||||
@ -4191,6 +4259,67 @@
|
|||||||
],
|
],
|
||||||
"time": "2019-01-10T14:22:35+00:00"
|
"time": "2019-01-10T14:22:35+00:00"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "maximebf/debugbar",
|
||||||
|
"version": "v1.15.0",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/maximebf/php-debugbar.git",
|
||||||
|
"reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/30e7d60937ee5f1320975ca9bc7bcdd44d500f07",
|
||||||
|
"reference": "30e7d60937ee5f1320975ca9bc7bcdd44d500f07",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3.0",
|
||||||
|
"psr/log": "^1.0",
|
||||||
|
"symfony/var-dumper": "^2.6|^3.0|^4.0"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^4.0|^5.0"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"kriswallsmith/assetic": "The best way to manage assets",
|
||||||
|
"monolog/monolog": "Log using Monolog",
|
||||||
|
"predis/predis": "Redis storage"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"extra": {
|
||||||
|
"branch-alias": {
|
||||||
|
"dev-master": "1.14-dev"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"DebugBar\\": "src/DebugBar/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"notification-url": "https://packagist.org/downloads/",
|
||||||
|
"license": [
|
||||||
|
"MIT"
|
||||||
|
],
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Maxime Bouroumeau-Fuseau",
|
||||||
|
"email": "maxime.bouroumeau@gmail.com",
|
||||||
|
"homepage": "http://maximebf.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Barry vd. Heuvel",
|
||||||
|
"email": "barryvdh@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"description": "Debug bar in the browser for php application",
|
||||||
|
"homepage": "https://github.com/maximebf/php-debugbar",
|
||||||
|
"keywords": [
|
||||||
|
"debug",
|
||||||
|
"debugbar"
|
||||||
|
],
|
||||||
|
"time": "2017-12-15T11:13:46+00:00"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "mockery/mockery",
|
"name": "mockery/mockery",
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
|
915
public/js/client_list.js
vendored
915
public/js/client_list.js
vendored
File diff suppressed because it is too large
Load Diff
915
public/js/client_list.min.js
vendored
915
public/js/client_list.min.js
vendored
File diff suppressed because it is too large
Load Diff
@ -83,7 +83,7 @@
|
|||||||
|
|
||||||
this.$events.fire('bulk-action', 'restore')
|
this.$events.fire('bulk-action', 'restore')
|
||||||
|
|
||||||
}
|
},
|
||||||
getBulkCount() {
|
getBulkCount() {
|
||||||
|
|
||||||
return this.$store.getters['client_list/getBulkCount']
|
return this.$store.getters['client_list/getBulkCount']
|
||||||
|
Loading…
x
Reference in New Issue
Block a user