Skip to content

Commit

Permalink
[1.x][suspend] fix: formally suspended admin users cannot remove thei…
Browse files Browse the repository at this point in the history
…r avatar after suspension
  • Loading branch information
imorland committed Oct 14, 2024
1 parent 5bd7e5d commit ee1d704
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function handle($event)
$actor = $event->actor;
$user = $event->user;

if ($actor->id === $user->id && $user->suspended_until) {
if (!$actor->isAdmin() && $actor->id === $user->id && $user->suspended_until && $user->suspended_until->isFuture()) {
throw new PermissionDeniedException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ public function setUp(): void
['id' => 3, 'username' => 'acme', 'email' => '[email protected]', 'is_email_confirmed' => 1, 'suspended_until' => Carbon::now()->addDay(), 'suspend_message' => 'You have been suspended.', 'suspend_reason' => 'Suspended for acme reasons.'],
['id' => 4, 'username' => 'acme4', 'email' => '[email protected]', 'is_email_confirmed' => 1],
['id' => 5, 'username' => 'acme5', 'email' => '[email protected]', 'is_email_confirmed' => 1, 'suspended_until' => Carbon::now()->subDay(), 'suspend_message' => 'You have been suspended.', 'suspend_reason' => 'Suspended for acme reasons.'],
['id' => 6, 'username' => 'acme6', 'email' => '[email protected]', 'is_email_confirmed' => 1, 'suspended_until' => Carbon::now()->subWeek(), 'suspend_message' => 'You have been suspended.', 'suspend_reason' => 'Suspended for acme reasons.'],
],
'groups' => [
['id' => 5, 'name_singular' => 'can_edit_users', 'name_plural' => 'can_edit_users', 'is_hidden' => 0]
],
'group_user' => [
['user_id' => 2, 'group_id' => 5]
['user_id' => 2, 'group_id' => 5],
['user_id' => 6, 'group_id' => 1],
],
'group_permission' => [
['permission' => 'user.edit', 'group_id' => 5],
Expand Down Expand Up @@ -73,6 +75,9 @@ public function allowedToRemoveAvatar(): array
[4, 4, 'Normal user can remove their own avatar'],
[1, 3, 'Admin can remove avatar of suspended user'],
[2, 3, 'Normal user with permission can remove avatar of suspended user'],
[1, 6, 'Admin can remove avatar of expired suspended user'],
[2, 6, 'Normal user with permission can remove avatar of expired suspended user'],
[6, 6, 'Admin user can remove avatar if they have an expired suspension'],
];
}

Expand Down

0 comments on commit ee1d704

Please sign in to comment.