Обновлен стартовый экран
Переписаны запросы для статистики, отчетов Добавлена интеграция отчета сестры
This commit is contained in:
@@ -26,8 +26,10 @@ class User extends Authenticatable
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'login',
|
||||
'email',
|
||||
'password',
|
||||
'is_active',
|
||||
'rf_lpudoctor_id',
|
||||
'rf_department_id',
|
||||
'current_role_id',
|
||||
@@ -76,7 +78,8 @@ class User extends Authenticatable
|
||||
return $this->hasMany(UserRole::class, 'rf_user_id', 'id');
|
||||
}
|
||||
|
||||
public function roles(): HasManyThrough
|
||||
// Переименовано из roles() чтобы не конфликтовать с Spatie HasRoles::roles()
|
||||
public function appRoles(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(
|
||||
Role::class,
|
||||
@@ -90,7 +93,7 @@ class User extends Authenticatable
|
||||
|
||||
public function currentRole()
|
||||
{
|
||||
$defaultRoleId = $this->roles()->where('is_default', true)->first()->role_id;
|
||||
$defaultRoleId = $this->appRoles()->where('is_default', true)->first()->role_id;
|
||||
|
||||
if (app()->runningInConsole()) {
|
||||
// Код выполняется в CLI (команда artisan, тесты и т.д.)
|
||||
@@ -128,19 +131,47 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
// Методы для проверки ролей
|
||||
public function isAdmin()
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->currentRole()->slug === 'admin';
|
||||
}
|
||||
|
||||
public function isDoctor()
|
||||
public function isChiefDoctor(): bool
|
||||
{
|
||||
return $this->currentRole()->slug === 'doctor';
|
||||
return $this->currentRole()->slug === 'gv';
|
||||
}
|
||||
|
||||
public function isHeadOfDepartment()
|
||||
public function isDeputyChief(): bool
|
||||
{
|
||||
return $this->currentRole()->slug === 'head_of_department';
|
||||
return $this->currentRole()->slug === 'zam';
|
||||
}
|
||||
|
||||
public function isHeadOfDepartment(): bool
|
||||
{
|
||||
return $this->currentRole()->slug === 'zav';
|
||||
}
|
||||
|
||||
public function isDoctor(): bool
|
||||
{
|
||||
return $this->currentRole()->slug === 'dej';
|
||||
}
|
||||
|
||||
public function isNurse(): bool
|
||||
{
|
||||
return $this->currentRole()->slug === 'nurse';
|
||||
}
|
||||
|
||||
public function isSeniorStaff(): bool
|
||||
{
|
||||
return $this->isAdmin() || $this->isChiefDoctor() || $this->isDeputyChief() || $this->isHeadOfDepartment();
|
||||
}
|
||||
|
||||
public function currentRoleCan(string $permission): bool
|
||||
{
|
||||
$slug = $this->currentRole()->slug;
|
||||
return \Spatie\Permission\Models\Role::findByName($slug)
|
||||
?->permissions->pluck('name')
|
||||
->contains($permission) ?? false;
|
||||
}
|
||||
|
||||
public function lpuDoctor()
|
||||
@@ -153,29 +184,12 @@ class User extends Authenticatable
|
||||
{
|
||||
$departments = Department::all();
|
||||
|
||||
if ($this->isAdmin()) {
|
||||
if ($this->isSeniorStaff()) {
|
||||
return $departments;
|
||||
}
|
||||
|
||||
return $this->department ? [$this->department] : [];
|
||||
}
|
||||
|
||||
// Получение доступных действий
|
||||
public function permissions()
|
||||
{
|
||||
$permissions = [
|
||||
'view_dashboard' => true,
|
||||
'view_metrics' => true,
|
||||
'view_reports' => true,
|
||||
];
|
||||
|
||||
if ($this->isAdmin() || $this->isDoctor() || $this->isHeadOfDepartment()) {
|
||||
$permissions['create_metrics'] = true;
|
||||
$permissions['edit_metrics'] = true;
|
||||
$permissions['delete_metrics'] = true;
|
||||
$permissions['manage_users'] = $this->isAdmin();
|
||||
}
|
||||
|
||||
return $permissions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user