Search in sources :

Example 1 with UserGridItem

use of io.imunity.furms.ui.components.administrators.UserGridItem in project furms by unity-idm.

the class UsersView method loadPageContent.

private void loadPageContent() {
    String projectId = getCurrentResourceId();
    project = projectService.findById(projectId).orElseThrow(() -> new IllegalStateException("Project not found: " + getCurrentResourceId()));
    currentUserId = authzService.getCurrentUserId();
    InviteUserComponent inviteUser = new InviteUserComponent(() -> projectService.findAllAdmins(project.getCommunityId(), project.getId()).stream().filter(IS_ELIGIBLE_FOR_PROJECT_MEMBERSHIP).collect(Collectors.toList()), () -> projectService.findAllUsers(project.getCommunityId(), project.getId()));
    membershipLayout = new MembershipChangerComponent(getTranslation("view.project-admin.users.button.join"), getTranslation("view.project-admin.users.button.demit"), () -> projectService.isUser(project.getId()));
    userService.findById(currentUserId).ifPresent(user -> membershipLayout.setEnabled(IS_ELIGIBLE_FOR_PROJECT_MEMBERSHIP.test(user)));
    UserContextMenuFactory userContextMenuFactory = UserContextMenuFactory.builder().withCurrentUserId(currentUserId).allowRemovalOfLastUser().withConfirmRemovalMessageKey("view.project-admin.users.remove.confirm").withConfirmSelfRemovalMessageKey("view.project-admin.users.remove.yourself.confirm").withRemoveInvitationAction(invitationId -> {
        projectService.removeInvitation(projectId, invitationId);
        gridReload();
    }).withResendInvitationAction(invitationId -> {
        projectService.resendInvitation(projectId, invitationId);
        gridReload();
    }).withRemoveUserAction(userId -> {
        try {
            projectService.removeUser(project.getCommunityId(), project.getId(), userId);
        } catch (UserInstallationOnSiteIsNotTerminalException e) {
            showErrorNotification(getTranslation("user.currently.de-installing"));
        }
    }).withPostRemoveUserAction(userId -> {
        membershipLayout.loadAppropriateButton();
        inviteUser.reload();
    }).addCustomContextMenuItem((UserGridItem userGridItem) -> new MenuButton(getTranslation("view.project-admin.users.requested.accept"), CHECK_CIRCLE), userGridItem -> {
        try {
            projectApplicationsService.accept(projectId, userGridItem.getFenixUserId().get());
            showSuccessNotification(getTranslation("view.project-admin.users.application.accept"));
        } catch (ApplicationNotExistingException e) {
            showErrorNotification(getTranslation("application.already.not.existing"));
        }
        grid.reloadGrid();
    }, userGridItem -> UserUIStatus.ACCESS_REQUESTED.equals(userGridItem.getStatus())).addCustomContextMenuItem((UserGridItem userGridItem) -> new MenuButton(getTranslation("view.project-admin.users.requested.reject"), CLOSE_CIRCLE), userGridItem -> {
        try {
            projectApplicationsService.remove(projectId, userGridItem.getFenixUserId().get());
            showSuccessNotification(getTranslation("view.project-admin.users.application.reject"));
        } catch (ApplicationNotExistingException e) {
            showErrorNotification(getTranslation("application.already.not.existing"));
        }
        grid.reloadGrid();
    }, userGridItem -> UserUIStatus.ACCESS_REQUESTED.equals(userGridItem.getStatus())).build();
    UserGrid.Builder userGrid = UserGrid.defaultInit(userContextMenuFactory);
    grid = UsersGridComponent.defaultInit(() -> projectService.findAllUsers(project.getCommunityId(), project.getId()), () -> projectService.findAllUsersInvitations(projectId), () -> projectApplicationsService.findAllApplyingUsers(projectId), userGrid);
    membershipLayout.addJoinButtonListener(event -> {
        projectService.addUser(project.getCommunityId(), project.getId(), currentUserId);
        grid.reloadGrid();
        inviteUser.reload();
    });
    membershipLayout.addDemitButtonListener(event -> {
        projectService.removeUser(project.getCommunityId(), project.getId(), currentUserId);
        grid.reloadGrid();
        inviteUser.reload();
        membershipLayout.loadAppropriateButton();
    });
    inviteUser.addInviteAction(event -> doInviteAction(inviteUser, projectId));
    ViewHeaderLayout headerLayout = new ViewHeaderLayout(getTranslation("view.project-admin.users.header", project.getName()), membershipLayout);
    getContent().add(headerLayout, inviteUser, grid);
}
Also used : Project(io.imunity.furms.domain.projects.Project) ResourceGetter.getCurrentResourceId(io.imunity.furms.ui.utils.ResourceGetter.getCurrentResourceId) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory) LoggerFactory(org.slf4j.LoggerFactory) MenuButton(io.imunity.furms.ui.components.MenuButton) PageTitle(io.imunity.furms.ui.components.PageTitle) Route(com.vaadin.flow.router.Route) MembershipChangerComponent(io.imunity.furms.ui.components.MembershipChangerComponent) DuplicatedInvitationError(io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError) UserAlreadyAppliedForMembershipException(io.imunity.furms.api.validation.exceptions.UserAlreadyAppliedForMembershipException) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) UserUIStatus(io.imunity.furms.ui.components.administrators.UserUIStatus) UserService(io.imunity.furms.api.users.UserService) PROJECT_BASE_LANDING_PAGE(io.imunity.furms.domain.constant.RoutesConst.PROJECT_BASE_LANDING_PAGE) UsersGridComponent(io.imunity.furms.ui.components.administrators.UsersGridComponent) ProjectAdminMenu(io.imunity.furms.ui.views.project.ProjectAdminMenu) PersistentId(io.imunity.furms.domain.users.PersistentId) Logger(org.slf4j.Logger) ApplicationNotExistingException(io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException) Predicate(java.util.function.Predicate) MethodHandles(java.lang.invoke.MethodHandles) ProjectApplicationsService(io.imunity.furms.api.applications.ProjectApplicationsService) FURMSUser(io.imunity.furms.domain.users.FURMSUser) Collectors(java.util.stream.Collectors) UserAlreadyHasRoleError(io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError) AuthzService(io.imunity.furms.api.authz.AuthzService) AfterNavigationEvent(com.vaadin.flow.router.AfterNavigationEvent) InviteUserComponent(io.imunity.furms.ui.components.InviteUserComponent) UserInstallationOnSiteIsNotTerminalException(io.imunity.furms.api.validation.exceptions.UserInstallationOnSiteIsNotTerminalException) ProjectService(io.imunity.furms.api.projects.ProjectService) CLOSE_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE) CHECK_CIRCLE(com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE) UserGridItem(io.imunity.furms.ui.components.administrators.UserGridItem) FurmsLandingViewComponent(io.imunity.furms.ui.components.FurmsLandingViewComponent) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) NotificationUtils.showSuccessNotification(io.imunity.furms.ui.utils.NotificationUtils.showSuccessNotification) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) ApplicationNotExistingException(io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException) MembershipChangerComponent(io.imunity.furms.ui.components.MembershipChangerComponent) MenuButton(io.imunity.furms.ui.components.MenuButton) UserInstallationOnSiteIsNotTerminalException(io.imunity.furms.api.validation.exceptions.UserInstallationOnSiteIsNotTerminalException) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory) UserGridItem(io.imunity.furms.ui.components.administrators.UserGridItem) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) InviteUserComponent(io.imunity.furms.ui.components.InviteUserComponent)

Aggregations

CHECK_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.CHECK_CIRCLE)1 CLOSE_CIRCLE (com.vaadin.flow.component.icon.VaadinIcon.CLOSE_CIRCLE)1 AfterNavigationEvent (com.vaadin.flow.router.AfterNavigationEvent)1 Route (com.vaadin.flow.router.Route)1 ProjectApplicationsService (io.imunity.furms.api.applications.ProjectApplicationsService)1 AuthzService (io.imunity.furms.api.authz.AuthzService)1 ProjectService (io.imunity.furms.api.projects.ProjectService)1 UserService (io.imunity.furms.api.users.UserService)1 ApplicationNotExistingException (io.imunity.furms.api.validation.exceptions.ApplicationNotExistingException)1 DuplicatedInvitationError (io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError)1 UserAlreadyAppliedForMembershipException (io.imunity.furms.api.validation.exceptions.UserAlreadyAppliedForMembershipException)1 UserAlreadyHasRoleError (io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError)1 UserInstallationOnSiteIsNotTerminalException (io.imunity.furms.api.validation.exceptions.UserInstallationOnSiteIsNotTerminalException)1 PROJECT_BASE_LANDING_PAGE (io.imunity.furms.domain.constant.RoutesConst.PROJECT_BASE_LANDING_PAGE)1 Project (io.imunity.furms.domain.projects.Project)1 FURMSUser (io.imunity.furms.domain.users.FURMSUser)1 PersistentId (io.imunity.furms.domain.users.PersistentId)1 FurmsLandingViewComponent (io.imunity.furms.ui.components.FurmsLandingViewComponent)1 InviteUserComponent (io.imunity.furms.ui.components.InviteUserComponent)1 MembershipChangerComponent (io.imunity.furms.ui.components.MembershipChangerComponent)1