minor fix and update

master
Константин 2023-09-11 09:22:52 +03:00
parent abae7d79b7
commit b502781f9b
2 changed files with 8 additions and 2 deletions

View File

@ -97,13 +97,19 @@ class Application extends Model {
}
public function setExpert(CompanyMember $expert) {
if ($this->expert->id !== $expert->id) {
if (($this->expert->id ?? null) !== $expert->id) {
$previousExpert = $this->expert;
$this->update(['expert_id' => $expert->id]);
event(new ApplicationExpertChanged($this, $previousExpert));
}
}
public function isExpert(?User $user = null): bool {
return $this->expert()->whereHas('user', function($query) use($user) {
$query->where(['user_id' => $user->id ?? null]);
})->exists();
}
public static function generateNumber($start = 100, $digits = 5): string {
$res = intval(static::query()->max('number') ?? $start) + 1;
while (strlen($res) < $digits) {

View File

@ -41,7 +41,7 @@ class PermissionsService {
}
public function applicationPermissions(): array {
return ['edit' => $this->model->submitter_id === $this->user->id, 'reply' => $this->user->isExpert, 'manage' => $this->user->isApplicationsManager];
return ['edit' => $this->model->submitter_id === $this->user->id, 'reply' => $this->model->isExpert($this->user), 'manage' => $this->user->isApplicationsManager];
}
public function pagePermissions(): array {