Search in sources :

Example 1 with InvitationNotExistingException

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

the class InvitationsView method createContextMenu.

private Component createContextMenu(InvitationId id) {
    GridActionMenu contextMenu = new GridActionMenu();
    contextMenu.addItem(new MenuButton(getTranslation("view.user-settings.invitations.grid.context-menu.confirm"), CHECK_CIRCLE), event -> {
        try {
            inviteeService.acceptBy(id);
        } catch (InvitationNotExistingException e) {
            showErrorNotification(getTranslation("invitation.already.removed"));
        } catch (Exception e) {
            LOG.warn("Could not accept Invitation. ", e);
            showErrorNotification(getTranslation("base.error.message"));
        }
        loadGrid();
    });
    Dialog confirmDialog = createConfirmDialog(id);
    contextMenu.addItem(new MenuButton(getTranslation("view.user-settings.invitations.grid.context-menu.reject"), CLOSE_CIRCLE), event -> confirmDialog.open());
    return contextMenu.getTarget();
}
Also used : GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) Dialog(com.vaadin.flow.component.dialog.Dialog) MenuButton(io.imunity.furms.ui.components.MenuButton) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException)

Example 2 with InvitationNotExistingException

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

the class InviteeServiceImpl method acceptBy.

@Override
@FurmsAuthorize(capability = AUTHENTICATED)
public void acceptBy(InvitationId id) {
    FURMSUser user = authzService.getCurrentAuthNUser();
    Invitation invitation = invitationRepository.findBy(id).orElseThrow(() -> new InvitationNotExistingException(String.format("Invitation id %s doesn't exist for user %s", id, user.fenixUserId)));
    switch(invitation.resourceId.type) {
        case APP_LEVEL:
            fenixUsersDAO.addFenixAdminRole(user.id.get());
            break;
        case SITE:
            siteGroupDAO.addSiteUser(invitation.resourceId.id.toString(), user.id.get(), invitation.role);
            break;
        case COMMUNITY:
            communityGroupsDAO.addAdmin(invitation.resourceId.id.toString(), user.id.get());
            break;
        case PROJECT:
            String projectId = invitation.resourceId.id.toString();
            String communityId = projectRepository.findById(projectId).get().getCommunityId();
            projectGroupsDAO.addProjectUser(communityId, projectId, user.id.get(), invitation.role);
            break;
    }
    invitationRepository.deleteBy(invitation.id);
    notifyOriginatorAndSameHierarchyAdmins(invitation, usr -> userInvitationNotificationService.notifyAdminAboutRoleAcceptance(usr.id.get(), invitation.role, invitation.email));
    publisher.publishEvent(new InvitationAcceptedEvent(user.fenixUserId.get(), user.email, invitation.resourceId));
    publisher.publishEvent(new UserRoleGrantedByInvitationEvent(invitation.originator, user.id.get(), invitation.resourceId, invitation.resourceName, invitation.role));
}
Also used : UserRoleGrantedByInvitationEvent(io.imunity.furms.domain.users.UserRoleGrantedByInvitationEvent) InvitationAcceptedEvent(io.imunity.furms.domain.invitations.InvitationAcceptedEvent) Invitation(io.imunity.furms.domain.invitations.Invitation) FURMSUser(io.imunity.furms.domain.users.FURMSUser) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException) FurmsAuthorize(io.imunity.furms.core.config.security.method.FurmsAuthorize)

Example 3 with InvitationNotExistingException

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

the class InvitationsView method createMainContextMenu.

private Component createMainContextMenu(InviteeService inviteeService, Map<InvitationId, Checkbox> checkboxes) {
    GridActionMenu contextMenu = new GridActionMenu();
    contextMenu.addItem(new MenuButton(getTranslation("view.user-settings.invitations.main.context-menu.confirm"), CHECK_CIRCLE), event -> {
        try {
            checkboxes.entrySet().stream().filter(x -> x.getValue().getValue()).forEach(x -> inviteeService.acceptBy(x.getKey()));
        } catch (InvitationNotExistingException e) {
            showErrorNotification(getTranslation("invitation.already.removed"));
        } catch (Exception e) {
            LOG.warn("Could not accept Invitations. ", e);
            showErrorNotification(getTranslation("base.error.message"));
        }
        loadGrid();
    });
    contextMenu.addItem(new MenuButton(getTranslation("view.user-settings.invitations.main.context-menu.reject"), CLOSE_CIRCLE), event -> {
        if (checkboxes.entrySet().stream().anyMatch(x -> x.getValue().getValue()))
            createMainConfirmDialog(checkboxes).open();
    });
    return contextMenu.getTarget();
}
Also used : UTCTimeUtils.convertToZoneTime(io.imunity.furms.utils.UTCTimeUtils.convertToZoneTime) Component(com.vaadin.flow.component.Component) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) HorizontalLayout(com.vaadin.flow.component.orderedlayout.HorizontalLayout) LoggerFactory(org.slf4j.LoggerFactory) Label(com.vaadin.flow.component.html.Label) FurmsDialog(io.imunity.furms.ui.components.FurmsDialog) MenuButton(io.imunity.furms.ui.components.MenuButton) HashMap(java.util.HashMap) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) DenseGrid(io.imunity.furms.ui.components.DenseGrid) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) Map(java.util.Map) UserSettingsMenu(io.imunity.furms.ui.views.user_settings.UserSettingsMenu) Grid(com.vaadin.flow.component.grid.Grid) UIContext(io.imunity.furms.ui.user_context.UIContext) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) Checkbox(com.vaadin.flow.component.checkbox.Checkbox) DateTimeFormatter(java.time.format.DateTimeFormatter) ColumnTextAlign(com.vaadin.flow.component.grid.ColumnTextAlign) InvitationId(io.imunity.furms.domain.invitations.InvitationId) Optional(java.util.Optional) CLOSE_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE) CHECK_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE) Dialog(com.vaadin.flow.component.dialog.Dialog) InviteeService(io.imunity.furms.api.invitations.InviteeService) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) GridActionMenu(io.imunity.furms.ui.components.GridActionMenu) MenuButton(io.imunity.furms.ui.components.MenuButton) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException) InvitationNotExistingException(io.imunity.furms.api.validation.exceptions.InvitationNotExistingException)

Aggregations

InvitationNotExistingException (io.imunity.furms.api.validation.exceptions.InvitationNotExistingException)3 Dialog (com.vaadin.flow.component.dialog.Dialog)2 FurmsDialog (io.imunity.furms.ui.components.FurmsDialog)2 GridActionMenu (io.imunity.furms.ui.components.GridActionMenu)2 MenuButton (io.imunity.furms.ui.components.MenuButton)2 Component (com.vaadin.flow.component.Component)1 Checkbox (com.vaadin.flow.component.checkbox.Checkbox)1 ColumnTextAlign (com.vaadin.flow.component.grid.ColumnTextAlign)1 Grid (com.vaadin.flow.component.grid.Grid)1 Label (com.vaadin.flow.component.html.Label)1 CHECK_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE)1 CLOSE_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE)1 HorizontalLayout (com.vaadin.flow.component.orderedlayout.HorizontalLayout)1 Route (com.vaadin.flow.router.Route)1 InviteeService (io.imunity.furms.api.invitations.InviteeService)1 FurmsAuthorize (io.imunity.furms.core.config.security.method.FurmsAuthorize)1 Invitation (io.imunity.furms.domain.invitations.Invitation)1 InvitationAcceptedEvent (io.imunity.furms.domain.invitations.InvitationAcceptedEvent)1 InvitationId (io.imunity.furms.domain.invitations.InvitationId)1 FURMSUser (io.imunity.furms.domain.users.FURMSUser)1