Search in sources :

Example 26 with Group

use of io.lumeer.api.model.Group in project engine by Lumeer.

the class OrganizationServiceIT method testRemoveGroupPermission.

@Test
public void testRemoveGroupPermission() {
    Organization organization = createOrganizationWithSpecificPermissions(CODE1);
    Group group = new Group(GROUP);
    groupDao.setOrganization(organization);
    this.group = groupDao.createGroup(group);
    organization.getPermissions().removeGroupPermission(GROUP);
    organization.getPermissions().updateGroupPermissions(new Permission(group.getId(), GROUP_ROLES));
    organization = organizationDao.updateOrganization(organization.getId(), organization);
    Response response = client.target(organizationUrl).path(organization.getId()).path("permissions").path("groups").path(this.group.getId()).request(MediaType.APPLICATION_JSON).buildDelete().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    assertThat(response.getLinks()).extracting(Link::getUri).containsOnly(UriBuilder.fromUri(organizationUrl + "/" + organization.getId() + "/permissions").build());
    Permissions permissions = organizationDao.getOrganizationByCode(CODE1).getPermissions();
    assertPermissions(permissions.getUserPermissions(), userPermission);
    assertThat(permissions.getGroupPermissions()).isEmpty();
}
Also used : Response(javax.ws.rs.core.Response) Group(io.lumeer.api.model.Group) Organization(io.lumeer.api.model.Organization) Permission(io.lumeer.api.model.Permission) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Permissions(io.lumeer.api.model.Permissions) Test(org.junit.Test)

Example 27 with Group

use of io.lumeer.api.model.Group in project engine by Lumeer.

the class OrganizationFacadeIT method createOrganizationWithGroupPermissions.

private String createOrganizationWithGroupPermissions(final String code, final RoleType roleType) {
    Organization organization = new Organization(code, NAME, ICON, COLOR, null, null, null);
    Organization storedOrganization = organizationDao.createOrganization(organization);
    groupDao.setOrganization(storedOrganization);
    group = groupDao.createGroup(new Group(GROUP, Collections.singletonList(user.getId())));
    user.setOrganizations(Collections.singleton(storedOrganization.getId()));
    user = userDao.updateUser(user.getId(), user);
    permissionsChecker.getPermissionAdapter().invalidateUserCache();
    groupPermission = Permission.buildWithRoles(this.group.getId(), Collections.singleton(new Role(roleType)));
    storedOrganization.getPermissions().updateGroupPermissions(groupPermission);
    organizationDao.updateOrganization(storedOrganization.getId(), storedOrganization);
    return storedOrganization.getId();
}
Also used : Role(io.lumeer.api.model.Role) Group(io.lumeer.api.model.Group) Organization(io.lumeer.api.model.Organization)

Example 28 with Group

use of io.lumeer.api.model.Group in project engine by Lumeer.

the class FunctionFacadeIT method configureProject.

@Before
public void configureProject() {
    User user = userDao.createUser(new User(USER));
    Organization organization = new Organization();
    organization.setCode(ORGANIZATION_CODE);
    Permissions organizationPermissions = new Permissions();
    userPermission = Permission.buildWithRoles(user.getId(), Organization.ROLES);
    organizationPermissions.updateUserPermissions(userPermission);
    organization.setPermissions(organizationPermissions);
    organization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(organization);
    groupDao.setOrganization(organization);
    Group group = groupDao.createGroup(new Group(GROUP));
    userPermission = Permission.buildWithRoles(user.getId(), Collection.ROLES);
    groupPermission = Permission.buildWithRoles(group.getId(), Collections.singleton(new Role(RoleType.Read)));
    Project project = new Project();
    project.setCode(PROJECT_CODE);
    Permissions projectPermissions = new Permissions();
    projectPermissions.updateUserPermissions(Permission.buildWithRoles(user.getId(), Project.ROLES));
    project.setPermissions(projectPermissions);
    Project storedProject = projectDao.createProject(project);
    workspaceKeeper.setWorkspaceIds(organization.getId(), storedProject.getId());
    functionDao.setProject(project);
}
Also used : Role(io.lumeer.api.model.Role) Group(io.lumeer.api.model.Group) Project(io.lumeer.api.model.Project) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.auth.AuthenticatedUser) Organization(io.lumeer.api.model.Organization) Permissions(io.lumeer.api.model.Permissions) Before(org.junit.Before)

Example 29 with Group

use of io.lumeer.api.model.Group in project engine by Lumeer.

the class GroupFacadeIT method testUpdateGroupNoPermission.

@Test
public void testUpdateGroupNoPermission() {
    String groupId = groupFacade.createGroup(new Group(GROUP1)).getId();
    setOrganizationWithoutPermissions();
    assertThatThrownBy(() -> groupFacade.updateGroup(groupId, new Group(GROUP2))).isInstanceOf(NoResourcePermissionException.class);
}
Also used : Group(io.lumeer.api.model.Group) Test(org.junit.Test)

Example 30 with Group

use of io.lumeer.api.model.Group in project engine by Lumeer.

the class GroupFacadeIT method testCreateGroupNotPermission.

@Test
public void testCreateGroupNotPermission() {
    setOrganizationWithoutPermissions();
    assertThatThrownBy(() -> groupFacade.createGroup(new Group(GROUP1))).isInstanceOf(NoResourcePermissionException.class);
}
Also used : Group(io.lumeer.api.model.Group) Test(org.junit.Test)

Aggregations

Group (io.lumeer.api.model.Group)44 Test (org.junit.Test)22 Organization (io.lumeer.api.model.Organization)19 Permissions (io.lumeer.api.model.Permissions)16 Project (io.lumeer.api.model.Project)16 Role (io.lumeer.api.model.Role)16 User (io.lumeer.api.model.User)16 Before (org.junit.Before)15 AuthenticatedUser (io.lumeer.core.auth.AuthenticatedUser)14 Permission (io.lumeer.api.model.Permission)10 Response (javax.ws.rs.core.Response)9 Collection (io.lumeer.api.model.Collection)7 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)6 List (java.util.List)4 LinkType (io.lumeer.api.model.LinkType)2 Query (io.lumeer.api.model.Query)2 QueryStem (io.lumeer.api.model.QueryStem)2 ResourceType (io.lumeer.api.model.ResourceType)2 RoleType (io.lumeer.api.model.RoleType)2 Resource (io.lumeer.api.model.common.Resource)2