You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

89 lines
1.8 KiB

<?php
namespace App\Models;
use Foundation\UuidModel;
class Role extends UuidModel
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'rights',
];
public static $availableRights = [
'SEMINAR_LIST_NON_APPLYABLE',
'SEMINAR_WRITE',
'SEMINAR_DELETE',
'SEMINAR_TYPE_ADMIN',
'FACULTY_ADMIN',
'STUDENT_COUNCIL_ADMIN',
'APPLICATION_HAVE',
'APPLICATION_GLOBAL_LIST',
'APPLICATION_GLOBAL_WRITE',
'APPLICATION_GLOBAL_DELETE',
'APPLICATION_FACULTY_LIST',
'APPLICATION_FACULTY_WRITE',
'APPLICATION_FACULTY_DELETE',
'USER_GLOBAL_LIST',
'USER_GLOBAL_WRITE',
'USER_GLOBAL_DELETE',
'USER_FACULTY_LIST',
'USER_FACULTY_WRITE',
'USER_FACULTY_DELETE',
'ROLES_ADMIN',
];
public function setRightsAttribute($rights) {
$this->attributes['rights'] = implode(',', $rights);
}
public function getRightsAttribute($rights) {
$rights = explode(',', $rights);
if (count($rights) === 1 && $rights[0] === '') {
return [];
}
return $rights;
}
public function hasRight(string $right)
{
return in_array($right, $this->rights);
}
public function hasAllRights(Array $rights)
{
foreach ($rights as $right) {
if (!$this->hasRight($right)) {
return false;
}
}
return true;
}
public function hasOneRight(Array $rights)
{
foreach ($rights as $right) {
if ($this->hasRight($right)) {
return true;
}
}
return true;
}
public function users()
{
return $this->hasMany(App\User::class);
}
}