minor fix and update
parent
abae7d79b7
commit
b502781f9b
|
|
@ -97,13 +97,19 @@ class Application extends Model {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setExpert(CompanyMember $expert) {
|
public function setExpert(CompanyMember $expert) {
|
||||||
if ($this->expert->id !== $expert->id) {
|
if (($this->expert->id ?? null) !== $expert->id) {
|
||||||
$previousExpert = $this->expert;
|
$previousExpert = $this->expert;
|
||||||
$this->update(['expert_id' => $expert->id]);
|
$this->update(['expert_id' => $expert->id]);
|
||||||
event(new ApplicationExpertChanged($this, $previousExpert));
|
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 {
|
public static function generateNumber($start = 100, $digits = 5): string {
|
||||||
$res = intval(static::query()->max('number') ?? $start) + 1;
|
$res = intval(static::query()->max('number') ?? $start) + 1;
|
||||||
while (strlen($res) < $digits) {
|
while (strlen($res) < $digits) {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class PermissionsService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applicationPermissions(): array {
|
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 {
|
public function pagePermissions(): array {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue