Skip to content

Commit

Permalink
simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Apr 28, 2024
1 parent 359257c commit d7e8e09
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions backend/src/main/java/org/cryptomator/hub/api/VaultResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class VaultResource {
@Inject
EffectiveVaultAccess.Repository effectiveVaultAccessRepo;
@Inject
@Deprecated
LegacyAccessToken.Repository legacyAccessTokenRepo;
@Inject
Vault.Repository vaultRepo;
Expand Down Expand Up @@ -166,16 +167,12 @@ public Response addUser(@PathParam("vaultId") UUID vaultId, @PathParam("userId")
var vault = vaultRepo.findById(vaultId); // should always be found, since @VaultRole filter would have triggered
var user = userRepo.findByIdOptional(userId).orElseThrow(NotFoundException::new);
var usedSeats = effectiveVaultAccessRepo.countSeatOccupyingUsers();
//check if license seats are free
if (usedSeats < license.getSeats()) {
return addAuthority(vault, user, role);
}
// else check, if all seats are taken, but the person to add is already sitting
if (usedSeats == license.getSeats() && effectiveVaultAccessRepo.isUserOccupyingSeat(userId)) {
if (usedSeats < license.getSeats() // free seats available
|| effectiveVaultAccessRepo.isUserOccupyingSeat(userId)) { // or user already sitting
return addAuthority(vault, user, role);
} else {
throw new PaymentRequiredException("License seats exceeded. Cannot add more users.");
}
//otherwise block
throw new PaymentRequiredException("License seats exceeded. Cannot add more users.");
}

@PUT
Expand Down

0 comments on commit d7e8e09

Please sign in to comment.