megacommit

This commit is contained in:
Didier Slof 2023-02-02 08:17:38 +01:00
parent 2451ab45cb
commit 34ed81516b
Signed by: didier
GPG key ID: 01E71F18AA4398E5
51 changed files with 1200 additions and 251 deletions

View file

@ -54,14 +54,17 @@ class User extends Authenticatable
// the permissions are in the permissions table
// only return valid permissions
return $this->belongsToMany('App\Models\Permission', 'user_permissions', 'user_id', 'permission_id')->where(function ($query) {
$query->where('user_permission_start', '<=', now())->where(function ($query) {
$query->where('user_permission_end', '>=', now())->orWhereNull('user_permission_end');
});
// $query->where('user_permission_start', '<=', now())->where(function ($query) {
// $query->where('user_permission_end', '>=', now())->orWhereNull('user_permission_end');
// });
});
}
public function allowedTo($permission): bool
public function hasPermission($permission): bool
{
if ($this->role == 'admin') {
return true;
}
if ($this->permissions()->where('permission_name', $permission)->first()) {
return true;
}
@ -73,7 +76,8 @@ class User extends Authenticatable
$hierarchy = [
'default' => 0,
'employee' => 1,
'manage' => 2
'manage' => 2,
'admin' => 3
];
return $hierarchy[$this->role] >= $hierarchy[$role];
}
@ -83,4 +87,21 @@ class User extends Authenticatable
return User::all()->where('user_id', $id)->first();
}
public function cinemas()
{
// check user_assignments table for all assignments for this user
if ($this->atleast('admin')) {
// if user is a manager or admin, return all cinemas
return Cinema::all();
} else {
// if user is an employee, return only the cinemas they are assigned to
return $this->belongsToMany('App\Models\Cinema', 'user_assignments', 'user_id', 'cinema_id')->get();
}
}
public function orders()
{
return $this->hasMany('App\Models\Order', 'user_id', 'user_id');
}
}