Fixes for permissions (#3575)

This commit is contained in:
David Bomba 2020-04-01 23:34:50 +11:00 committed by GitHub
parent eba0c19824
commit ceb82ad275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 9 deletions

View File

@ -174,6 +174,7 @@ class ClientFilters extends QueryFilters
* limit the user to only the invoices they have created * limit the user to only the invoices they have created
*/ */
if (Gate::denies('view-list', Client::class)) { if (Gate::denies('view-list', Client::class)) {
info("the gate!");
$query->where('clients.user_id', '=', $user->id); $query->where('clients.user_id', '=', $user->id);
} }
@ -189,7 +190,6 @@ class ClientFilters extends QueryFilters
*/ */
public function entityFilter() public function entityFilter()
{ {
//return $this->builder->whereCompanyId(auth()->user()->company()->id); //return $this->builder->whereCompanyId(auth()->user()->company()->id);
return $this->builder->company(); return $this->builder->company();
} }

View File

@ -131,14 +131,16 @@ class BaseController extends Controller
$query->with($includes); $query->with($includes);
if (auth()->user()->cannot('view_'.$this->entity_type)) { if (!auth()->user()->hasPermission('view_'.lcfirst(class_basename($this->entity_type)))) {
if ($this->entity_type == Company::class || $this->entity_type == Design::class) {
//no user keys exist on the company table, so we need to skip // if ($this->entity_type == Company::class || $this->entity_type == Design::class) {
} elseif ($this->entity_type == User::class) { // //no user keys exist on the company table, so we need to skip
//$query->where('id', '=', auth()->user()->id); @todo why? // } elseif ($this->entity_type == User::class) {
} else { // //$query->where('id', '=', auth()->user()->id); @todo why?
// } else {
$query->where('user_id', '=', auth()->user()->id); $query->where('user_id', '=', auth()->user()->id);
} // }
} }
if (request()->has('updated_at') && request()->input('updated_at') > 0) { if (request()->has('updated_at') && request()->input('updated_at') > 0) {

View File

@ -286,7 +286,16 @@ class User extends Authenticatable implements MustVerifyEmail
*/ */
public function hasPermission($permission) : bool public function hasPermission($permission) : bool
{ {
return (stripos($this->company_user->permissions, $permission) !== false); $parts = explode("_", $permission);
$all_permission = '';
if(count($parts) > 1)
$all_permission = $parts[0] . '_all';
return $this->isOwner() ||
$this->isAdmin() ||
(stripos($this->company_user->permissions, $all_permission) !== false) ||
(stripos($this->company_user->permissions, $permission) !== false);
} }
public function documents() public function documents()