Skip to content

Commit

Permalink
Fix admins view
Browse files Browse the repository at this point in the history
  • Loading branch information
Portals committed Sep 17, 2024
1 parent 9f4855a commit f303272
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ public ModelAndView setAdmins(
.map(UUID::fromString)
.toList();

List<UUID> newAdmins =
formAdmins.stream().filter(userId -> !oldAdmins.contains(userId)).toList();
List<UUID> noLongerAdmins =
oldAdmins.stream().filter(userId -> !formAdmins.contains(userId)).toList();

try {
this.adminFacade.updateAdmins(newAdmins, noLongerAdmins);
this.adminFacade.updateAdmins(formAdmins, noLongerAdmins);
} catch (IllegalArgumentException e) {
return this.getAdmins(htmxRequest);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ public AdminFacade(AccessGuard accessGuard, AdminRepository adminRepository) {
this.adminRepository = adminRepository;
}

public void updateAdmins(List<UUID> adminsToAdd, List<UUID> adminsToRemove) {
public void updateAdmins(List<UUID> newAdmins, List<UUID> adminsToRemove) {
accessGuard.require(isAdmin());

if (adminsToAdd.isEmpty()) {
if (newAdmins.isEmpty()) {
throw new IllegalArgumentException("There must be at least one admin");
}

for (UUID userId : adminsToAdd) {
for (UUID userId : newAdmins) {
this.adminRepository.setAdmin(new UserId(userId), true);
}

Expand Down

0 comments on commit f303272

Please sign in to comment.