refactor: update user roles and permissions for new role

Signed-off-by: miguel456 <me@nogueira.codes>
This commit is contained in:
Miguel Nogueira 2022-10-21 15:06:00 +01:00
parent 8c592bd82d
commit 9056ee131f
No known key found for this signature in database
GPG Key ID: 3C6A7E29AF26D370
3 changed files with 18 additions and 7 deletions

View File

@ -45,11 +45,15 @@ class PromoteUser
*/ */
public function handle(ApplicationApprovedEvent $event) public function handle(ApplicationApprovedEvent $event)
{ {
Log::info('User '.$event->application->user->name . 'has just been promoted (application approved)'); Log::info('User promoted automatically (application approved)', [
'user' => $event->application->user->name,
'vacancy' => $event->application->response->vacancy->vacancyName,
'role' => 'staff'
]);
$event->application->setStatus('APPROVED'); $event->application->setStatus('APPROVED');
$event->application->response->vacancy->decrease(); $event->application->response->vacancy->decrease();
$event->application->user->assignRole('reviewer'); $event->application->user->assignRole('staff');
$event->application->user->notify(new ApplicationApproved($event->application)); $event->application->user->notify(new ApplicationApproved($event->application));
} }

View File

@ -42,6 +42,10 @@ class PermissionSeeder extends Seeder
] ]
); );
$staff = Role::create([
'name' => 'staff'
]);
$reviewer = Role::create( $reviewer = Role::create(
[ [
'name' => 'reviewer' 'name' => 'reviewer'
@ -108,15 +112,18 @@ class PermissionSeeder extends Seeder
'profiles.view.others' 'profiles.view.others'
]); ]);
// Able to view applications and vote on them once they reach the right stage, but not approve applications up to said stage $staff->givePermissionTo([
$reviewer->givePermissionTo([
'applications.view.all',
'applications.vote',
'reviewer.viewAbsence', 'reviewer.viewAbsence',
'reviewer.requestAbsence', 'reviewer.requestAbsence',
'reviewer.withdrawAbsence', 'reviewer.withdrawAbsence',
]); ]);
// Able to view applications and vote on them once they reach the right stage, but not approve applications up to said stage
$reviewer->givePermissionTo([
'applications.view.all',
'applications.vote'
]);
$hiringManager->givePermissionTo('appointments.*', 'applications.*', 'admin.hiring.*'); $hiringManager->givePermissionTo('appointments.*', 'applications.*', 'admin.hiring.*');
$admin->givePermissionTo([ $admin->givePermissionTo([

View File

@ -25,7 +25,7 @@
{!! $position->vacancyFullDescription !!} {!! $position->vacancyFullDescription !!}
<p class="text-sm text-muted"> <p class="text-sm text-muted">
{{__('Last updated :lastUpdatedTimeValue', ['lastUpdatedTimeValue' => $position->updated_at->diffForHumans()])}} {{__('Last updated :lastUpdatedRelativeTimeValue', ['lastUpdatedRelativeTimeValue' => $position->updated_at->diffForHumans()])}}
</p> </p>
@endif @endif