Search in sources :

Example 1 with UserAlreadyAppliedForMembershipException

use of io.imunity.furms.api.validation.exceptions.UserAlreadyAppliedForMembershipException in project furms by unity-idm.

the class InvitatoryService method inviteUser.

public void inviteUser(PersistentId userId, ResourceId resourceId, Role role, String resourceName) {
    FURMSUser user = usersDAO.findById(userId).orElseThrow(() -> new IllegalArgumentException("Could not invite user due to wrong email address."));
    if (user.fenixUserId.isEmpty())
        throw new UnsupportedUserException("Only fenix users supported");
    if (invitationRepository.findBy(user.email, role, resourceId).isPresent())
        throw new DuplicatedInvitationError("This invitation already exists");
    if (isSupportRoleCheckExistingAlsoForAdminRole(resourceId, role, user.email))
        throw new DuplicatedInvitationError("This invitation already exists");
    if (isSiteAdminRoleCheckExistingAlsoForSupportRole(resourceId, role, user.email))
        throw new DuplicatedInvitationError("This invitation already exists");
    if (resourceId.type.equals(PROJECT) && applicationRepository.existsBy(resourceId.id.toString(), user.fenixUserId.get()))
        throw new UserAlreadyAppliedForMembershipException("User waiting for application approval");
    if (usersDAO.getUserAttributes(user.fenixUserId.get()).attributesByResource.getOrDefault(resourceId, Set.of()).contains(new UserAttribute(role)))
        throw new UserAlreadyHasRoleError("User already has this role");
    Invitation invitation = Invitation.builder().resourceId(resourceId).role(role).resourceName(resourceName).userId(user.fenixUserId.get()).originator(authzService.getCurrentAuthNUser().email).email(user.email).utcExpiredAt(getExpiredAtTime()).build();
    invitationRepository.create(invitation);
    LOG.info("Inviting FENIX admin role to {}", userId);
    userInvitationNotificationService.notifyUserAboutNewRole(user.id.get(), invitation.role);
    publisher.publishEvent(new InviteUserEvent(user.fenixUserId.get(), user.email, resourceId));
}
Also used : UserAlreadyAppliedForMembershipException(io.imunity.furms.api.validation.exceptions.UserAlreadyAppliedForMembershipException) UnsupportedUserException(io.imunity.furms.api.validation.exceptions.UnsupportedUserException) DuplicatedInvitationError(io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError) UserAttribute(io.imunity.furms.domain.users.UserAttribute) Invitation(io.imunity.furms.domain.invitations.Invitation) UserAlreadyHasRoleError(io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError) FURMSUser(io.imunity.furms.domain.users.FURMSUser) InviteUserEvent(io.imunity.furms.domain.invitations.InviteUserEvent)

Aggregations

DuplicatedInvitationError (io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError)1 UnsupportedUserException (io.imunity.furms.api.validation.exceptions.UnsupportedUserException)1 UserAlreadyAppliedForMembershipException (io.imunity.furms.api.validation.exceptions.UserAlreadyAppliedForMembershipException)1 UserAlreadyHasRoleError (io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError)1 Invitation (io.imunity.furms.domain.invitations.Invitation)1 InviteUserEvent (io.imunity.furms.domain.invitations.InviteUserEvent)1 FURMSUser (io.imunity.furms.domain.users.FURMSUser)1 UserAttribute (io.imunity.furms.domain.users.UserAttribute)1