Search in sources :

Example 1 with UserService

use of io.imunity.furms.api.users.UserService in project furms by unity-idm.

the class SitesAdminsView method init.

private void init(String siteId) {
    InviteUserComponent inviteUser = new InviteUserComponent(userService::getAllUsers, () -> siteService.findAllAdministrators(siteId));
    MembershipChangerComponent membershipLayout = new MembershipChangerComponent(getTranslation("view.fenix-admin.sites.button.join"), getTranslation("view.fenix-admin.sites.button.demit"), () -> siteService.isCurrentUserAdminOf(siteId));
    membershipLayout.addJoinButtonListener(event -> {
        siteService.addAdmin(siteId, currentUserId);
        gridReload();
        inviteUser.reload();
    });
    membershipLayout.addDemitButtonListener(event -> {
        if (siteService.findAllAdministrators(siteId).size() > 1) {
            handleExceptions(() -> siteService.removeSiteUser(siteId, currentUserId));
            gridReload();
        } else {
            showErrorNotification(getTranslation("component.administrators.error.validation.remove"));
        }
        inviteUser.reload();
        membershipLayout.loadAppropriateButton();
    });
    inviteUser.addInviteAction(event -> doInviteAction(siteId, inviteUser, membershipLayout));
    UserContextMenuFactory userContextMenuFactory = UserContextMenuFactory.builder().withCurrentUserId(currentUserId).withRemoveUserAction(userId -> siteService.removeSiteUser(siteId, userId)).withPostRemoveUserAction(userId -> {
        membershipLayout.loadAppropriateButton();
        inviteUser.reload();
    }).withRemoveInvitationAction(invitationId -> {
        siteService.removeInvitation(siteId, invitationId);
        gridReload();
    }).withResendInvitationAction(invitationId -> {
        siteService.resendInvitation(siteId, invitationId);
        gridReload();
    }).build();
    UserGrid.Builder userGrid = UserGrid.defaultInit(userContextMenuFactory);
    grid = UsersGridComponent.defaultInit(() -> siteService.findAllAdministrators(siteId), () -> siteService.findSiteAdminInvitations(siteId), userGrid);
    Site site = handleExceptions(() -> siteService.findById(siteId)).flatMap(identity()).orElseThrow(IllegalStateException::new);
    ViewHeaderLayout viewHeaderLayout = new ViewHeaderLayout(getTranslation("view.sites.administrators.title", site.getName()), membershipLayout);
    getContent().add(viewHeaderLayout, inviteUser, grid);
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory) LoggerFactory(org.slf4j.LoggerFactory) PageTitle(io.imunity.furms.ui.components.PageTitle) BeforeEvent(com.vaadin.flow.router.BeforeEvent) Route(com.vaadin.flow.router.Route) MembershipChangerComponent(io.imunity.furms.ui.components.MembershipChangerComponent) DuplicatedInvitationError(io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) FurmsViewComponent(io.imunity.furms.ui.components.FurmsViewComponent) SiteService(io.imunity.furms.api.sites.SiteService) UserService(io.imunity.furms.api.users.UserService) UsersGridComponent(io.imunity.furms.ui.components.administrators.UsersGridComponent) PersistentId(io.imunity.furms.domain.users.PersistentId) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Site(io.imunity.furms.domain.sites.Site) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) OptionalParameter(com.vaadin.flow.router.OptionalParameter) FenixAdminMenu(io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu) UserAlreadyHasRoleError(io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError) AuthzService(io.imunity.furms.api.authz.AuthzService) InviteUserComponent(io.imunity.furms.ui.components.InviteUserComponent) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) Site(io.imunity.furms.domain.sites.Site) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) MembershipChangerComponent(io.imunity.furms.ui.components.MembershipChangerComponent) ViewHeaderLayout(io.imunity.furms.ui.components.ViewHeaderLayout) InviteUserComponent(io.imunity.furms.ui.components.InviteUserComponent) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory)

Example 2 with UserService

use of io.imunity.furms.api.users.UserService in project furms by unity-idm.

the class CommunityView method loadPage1Content.

private void loadPage1Content(String communityId, String communityName) {
    InviteUserComponent inviteUser = new InviteUserComponent(userService::getAllUsers, () -> communityService.findAllAdmins(communityId));
    MembershipChangerComponent membershipLayout = new MembershipChangerComponent(getTranslation("view.fenix-admin.community.button.join"), getTranslation("view.fenix-admin.community.button.demit"), () -> communityService.isAdmin(communityId));
    UserContextMenuFactory userContextMenuFactory = UserContextMenuFactory.builder().withCurrentUserId(currentUserId).withRemoveUserAction(userId -> communityService.removeAdmin(communityId, userId)).withPostRemoveUserAction(userId -> {
        membershipLayout.loadAppropriateButton();
        inviteUser.reload();
    }).withRemoveInvitationAction(invitationId -> {
        communityService.removeInvitation(communityId, invitationId);
        gridReload();
    }).withResendInvitationAction(invitationId -> {
        communityService.resendInvitation(communityId, invitationId);
        gridReload();
    }).build();
    UserGrid.Builder userGrid = UserGrid.defaultInit(userContextMenuFactory);
    grid = UsersGridComponent.defaultInit(() -> communityService.findAllAdmins(communityId), () -> communityService.findAllInvitations(communityId), userGrid);
    membershipLayout.addJoinButtonListener(event -> {
        communityService.addAdmin(communityId, currentUserId);
        gridReload();
        inviteUser.reload();
    });
    membershipLayout.addDemitButtonListener(event -> {
        if (communityService.findAllAdmins(communityId).size() > 1) {
            handleExceptions(() -> communityService.removeAdmin(communityId, currentUserId));
            gridReload();
        } else {
            showErrorNotification(getTranslation("component.administrators.error.validation.remove"));
        }
        inviteUser.reload();
        membershipLayout.loadAppropriateButton();
    });
    ViewHeaderLayout headerLayout = new ViewHeaderLayout(getTranslation("view.fenix-admin.community.page.header", communityName), membershipLayout);
    inviteUser.addInviteAction(event -> doInviteAction(communityId, inviteUser, membershipLayout));
    page1.add(headerLayout, inviteUser, grid);
}
Also used : VaadinExceptionHandler.handleExceptions(io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions) java.util(java.util) Component(com.vaadin.flow.component.Component) Tab(com.vaadin.flow.component.tabs.Tab) io.imunity.furms.ui.components(io.imunity.furms.ui.components) NotificationUtils.showErrorNotification(io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory) LoggerFactory(org.slf4j.LoggerFactory) Div(com.vaadin.flow.component.html.Div) Community(io.imunity.furms.domain.communities.Community) Tabs(com.vaadin.flow.component.tabs.Tabs) CommunityConst(io.imunity.furms.ui.views.fenix.communites.CommunityConst) CommunityAllocationService(io.imunity.furms.api.community_allocation.CommunityAllocationService) PageTitle(io.imunity.furms.ui.components.PageTitle) DuplicatedInvitationError(io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) com.vaadin.flow.router(com.vaadin.flow.router) UserService(io.imunity.furms.api.users.UserService) UsersGridComponent(io.imunity.furms.ui.components.administrators.UsersGridComponent) PersistentId(io.imunity.furms.domain.users.PersistentId) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) BreadCrumbParameter(io.imunity.furms.ui.components.layout.BreadCrumbParameter) FenixAdminMenu(io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu) UserAlreadyHasRoleError(io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError) AuthzService(io.imunity.furms.api.authz.AuthzService) CommunityAllocationComponent(io.imunity.furms.ui.views.fenix.communites.allocations.CommunityAllocationComponent) Function.identity(java.util.function.Function.identity) CommunityService(io.imunity.furms.api.communites.CommunityService) UserGrid(io.imunity.furms.ui.components.administrators.UserGrid) UserContextMenuFactory(io.imunity.furms.ui.components.administrators.UserContextMenuFactory)

Aggregations

AuthzService (io.imunity.furms.api.authz.AuthzService)2 UserService (io.imunity.furms.api.users.UserService)2 DuplicatedInvitationError (io.imunity.furms.api.validation.exceptions.DuplicatedInvitationError)2 UserAlreadyHasRoleError (io.imunity.furms.api.validation.exceptions.UserAlreadyHasRoleError)2 PersistentId (io.imunity.furms.domain.users.PersistentId)2 PageTitle (io.imunity.furms.ui.components.PageTitle)2 UserContextMenuFactory (io.imunity.furms.ui.components.administrators.UserContextMenuFactory)2 UserGrid (io.imunity.furms.ui.components.administrators.UserGrid)2 UsersGridComponent (io.imunity.furms.ui.components.administrators.UsersGridComponent)2 BreadCrumbParameter (io.imunity.furms.ui.components.layout.BreadCrumbParameter)2 NotificationUtils.showErrorNotification (io.imunity.furms.ui.utils.NotificationUtils.showErrorNotification)2 VaadinExceptionHandler.handleExceptions (io.imunity.furms.ui.utils.VaadinExceptionHandler.handleExceptions)2 FenixAdminMenu (io.imunity.furms.ui.views.fenix.menu.FenixAdminMenu)2 MethodHandles (java.lang.invoke.MethodHandles)2 Function.identity (java.util.function.Function.identity)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Component (com.vaadin.flow.component.Component)1 Div (com.vaadin.flow.component.html.Div)1 Tab (com.vaadin.flow.component.tabs.Tab)1