locking
This commit is contained in:
parent
c771981c97
commit
a24f4d03fb
@ -12,6 +12,8 @@ final class Manager
|
|||||||
{
|
{
|
||||||
private ?User $user = null;
|
private ?User $user = null;
|
||||||
|
|
||||||
|
public function __construct(private readonly Study $study) {}
|
||||||
|
|
||||||
public static function of(Study $study): self
|
public static function of(Study $study): self
|
||||||
{
|
{
|
||||||
return new self($study);
|
return new self($study);
|
||||||
@ -30,15 +32,6 @@ public function by(User|int|null $user): self
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkUserPermission(Permission $permission): bool
|
|
||||||
{
|
|
||||||
if (is_null($this->user)) {
|
|
||||||
$this->user = auth()->user();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->user->may($permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function can(Permission $permission): bool
|
public function can(Permission $permission): bool
|
||||||
{
|
{
|
||||||
if (! $this->checkUserPermission($permission)) {
|
if (! $this->checkUserPermission($permission)) {
|
||||||
@ -53,15 +46,6 @@ public function can(Permission $permission): bool
|
|||||||
return $this->{$prop}();
|
return $this->{$prop}();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function activeStudy(Closure $fn): bool
|
|
||||||
{
|
|
||||||
if (! $this->study->isActive()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $fn();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function canAssignPhysician(): bool
|
public function canAssignPhysician(): bool
|
||||||
{
|
{
|
||||||
return $this->activeStudy(fn () => $this->study->report_status <= ReportStatus::Preliminary);
|
return $this->activeStudy(fn () => $this->study->report_status <= ReportStatus::Preliminary);
|
||||||
@ -84,11 +68,32 @@ public function canReportDownload(): bool
|
|||||||
|
|
||||||
public function canReportEdit(): bool
|
public function canReportEdit(): bool
|
||||||
{
|
{
|
||||||
return $this->activeStudy(fn () => $this->study->is_locked === false &&
|
return $this->activeStudy(fn () => $this->study->isLocked() === false &&
|
||||||
$this->study->report_status <= ReportStatus::Preliminary &&
|
$this->study->report_status <= ReportStatus::Preliminary &&
|
||||||
$this->study->assigned_physician_id === $this->user->id
|
$this->study->assigned_physician_id === $this->user->id
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct(private readonly Study $study) {}
|
public function canUnlockReport(): bool
|
||||||
|
{
|
||||||
|
return $this->activeStudy(fn () => $this->study->isLocked() && $this->study->locking_physician_id === $this->user->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function checkUserPermission(Permission $permission): bool
|
||||||
|
{
|
||||||
|
if (is_null($this->user)) {
|
||||||
|
$this->user = auth()->user();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->user->may($permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function activeStudy(Closure $fn): bool
|
||||||
|
{
|
||||||
|
if (! $this->study->isActive()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fn();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user