Search in sources :

Example 1 with Permissions

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

the class PermissionsCheckerTest method prepareResource.

private Resource prepareResource(Set<Role> userRoles, Set<Role> groupRoles) {
    Permission userPermission = Mockito.mock(Permission.class);
    Mockito.when(userPermission.getName()).thenReturn(USER);
    Mockito.when(userPermission.getRoles()).thenReturn(userRoles);
    Permission groupPermission = Mockito.mock(Permission.class);
    Mockito.when(groupPermission.getName()).thenReturn(GROUP);
    Mockito.when(groupPermission.getRoles()).thenReturn(groupRoles);
    Permissions permissions = Mockito.mock(Permissions.class);
    Mockito.when(permissions.getUserPermissions()).thenReturn(Collections.singleton(userPermission));
    Mockito.when(permissions.getGroupPermissions()).thenReturn(Collections.singleton(groupPermission));
    Resource resource = Mockito.mock(Resource.class);
    Mockito.when(resource.getPermissions()).thenReturn(permissions);
    Mockito.when(resource.getType()).thenReturn(ResourceType.PROJECT);
    return resource;
}
Also used : Permission(io.lumeer.api.model.Permission) Permissions(io.lumeer.api.model.Permissions) Resource(io.lumeer.api.model.Resource)

Example 2 with Permissions

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

the class CollectionFacadeIT method testRemoveUserPermission.

@Test
public void testRemoveUserPermission() {
    String collectionId = createCollection(CODE).getId();
    collectionFacade.removeUserPermission(collectionId, USER);
    Permissions permissions = collectionDao.getCollectionByCode(CODE).getPermissions();
    assertThat(permissions).isNotNull();
    assertThat(permissions.getUserPermissions()).isEmpty();
    assertPermissions(permissions.getGroupPermissions(), GROUP_PERMISSION);
}
Also used : LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) Test(org.junit.Test)

Example 3 with Permissions

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

the class CollectionFacadeIT method testUpdateGroupPermissions.

@Test
public void testUpdateGroupPermissions() {
    String collectionId = createCollection(CODE).getId();
    SimplePermission groupPermission = new SimplePermission(GROUP, new HashSet<>(Arrays.asList(Role.SHARE, Role.READ)));
    collectionFacade.updateGroupPermissions(collectionId, groupPermission);
    Permissions permissions = collectionDao.getCollectionByCode(CODE).getPermissions();
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(permissions.getGroupPermissions(), groupPermission);
}
Also used : LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 4 with Permissions

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

the class CollectionFacadeIT method testGetCollectionPermissions.

@Test
public void testGetCollectionPermissions() {
    String collectionId = createCollection(CODE).getId();
    Permissions permissions = collectionFacade.getCollectionPermissions(collectionId);
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(permissions.getGroupPermissions(), GROUP_PERMISSION);
}
Also used : LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) Test(org.junit.Test)

Example 5 with Permissions

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

the class OrganizationFacadeIT method testRemoveGroupPermission.

@Test
public void testRemoveGroupPermission() {
    createOrganization(CODE1);
    organizationFacade.removeGroupPermission(CODE1, GROUP);
    Permissions permissions = organizationDao.getOrganizationByCode(CODE1).getPermissions();
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), USER_PERMISSION);
    assertThat(permissions.getGroupPermissions()).isEmpty();
}
Also used : Permissions(io.lumeer.api.model.Permissions) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) Test(org.junit.Test)

Aggregations

Permissions (io.lumeer.api.model.Permissions)45 LumeerAssertions.assertPermissions (io.lumeer.test.util.LumeerAssertions.assertPermissions)44 Test (org.junit.Test)44 JsonPermissions (io.lumeer.api.dto.JsonPermissions)29 Response (javax.ws.rs.core.Response)24 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)22 SimplePermission (io.lumeer.core.model.SimplePermission)20 JsonPermission (io.lumeer.api.dto.JsonPermission)12 HashSet (java.util.HashSet)12 Set (java.util.Set)12 Entity (javax.ws.rs.client.Entity)12 Permission (io.lumeer.api.model.Permission)5 Resource (io.lumeer.api.model.Resource)5 Organization (io.lumeer.api.model.Organization)4 Role (io.lumeer.api.model.Role)4 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)4 OrganizationDao (io.lumeer.storage.api.dao.OrganizationDao)4 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4