Search in sources :

Example 21 with Permissions

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

the class CollectionServiceIT method testUpdateUserPermissions.

@Test
public void testUpdateUserPermissions() {
    String collectionId = createCollection(CODE).getId();
    SimplePermission userPermission = new SimplePermission(USER, new HashSet<>(Arrays.asList(Role.MANAGE, Role.READ)));
    Entity entity = Entity.json(userPermission);
    Response response = client.target(COLLECTIONS_URL).path(collectionId).path("permissions").path("users").request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Set<JsonPermission> returnedPermissions = response.readEntity(new GenericType<Set<JsonPermission>>() {
    });
    assertThat(returnedPermissions).isNotNull().hasSize(1);
    assertPermissions(Collections.unmodifiableSet(returnedPermissions), userPermission);
    Permissions storedPermissions = collectionDao.getCollectionByCode(CODE).getPermissions();
    assertThat(storedPermissions).isNotNull();
    assertPermissions(storedPermissions.getUserPermissions(), userPermission);
    assertPermissions(storedPermissions.getGroupPermissions(), GROUP_PERMISSION);
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) HashSet(java.util.HashSet) Set(java.util.Set) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) JsonPermission(io.lumeer.api.dto.JsonPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 22 with Permissions

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

the class CollectionServiceIT method testGetAllCollections.

@Test
public void testGetAllCollections() {
    createCollection(CODE);
    createCollection(CODE2);
    Response response = client.target(COLLECTIONS_URL).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    List<JsonCollection> collections = response.readEntity(new GenericType<List<JsonCollection>>() {
    });
    assertThat(collections).extracting(Resource::getCode).containsOnly(CODE, CODE2);
    Permissions permissions1 = collections.get(0).getPermissions();
    assertThat(permissions1).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions1).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions1).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
    Permissions permissions2 = collections.get(1).getPermissions();
    assertThat(permissions2).extracting(Permissions::getUserPermissions).containsOnly(Collections.singleton(USER_PERMISSION));
    assertThat(permissions2).extracting(p -> p.getUserPermissions().iterator().next().getRoles()).containsOnly(USER_ROLES);
    assertThat(permissions2).extracting(Permissions::getGroupPermissions).containsOnly(Collections.emptySet());
}
Also used : Response(javax.ws.rs.core.Response) UserDao(io.lumeer.storage.api.dao.UserDao) Arrays(java.util.Arrays) SoftAssertions(org.assertj.core.api.SoftAssertions) ProjectDao(io.lumeer.storage.api.dao.ProjectDao) Arquillian(org.jboss.arquillian.junit.Arquillian) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) JsonPermission(io.lumeer.api.dto.JsonPermission) User(io.lumeer.api.model.User) RunWith(org.junit.runner.RunWith) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonCollection(io.lumeer.api.dto.JsonCollection) Resource(io.lumeer.api.model.Resource) JsonPermissions(io.lumeer.api.dto.JsonPermissions) HashSet(java.util.HashSet) Inject(javax.inject.Inject) OrganizationDao(io.lumeer.storage.api.dao.OrganizationDao) MediaType(javax.ws.rs.core.MediaType) CollectionDao(io.lumeer.storage.api.dao.CollectionDao) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Role(io.lumeer.api.model.Role) JsonAttribute(io.lumeer.api.dto.JsonAttribute) JsonProject(io.lumeer.api.dto.JsonProject) SimplePermission(io.lumeer.core.model.SimplePermission) UriBuilder(javax.ws.rs.core.UriBuilder) Organization(io.lumeer.api.model.Organization) Before(org.junit.Before) Permission(io.lumeer.api.model.Permission) View(io.lumeer.api.model.View) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException) Permissions(io.lumeer.api.model.Permissions) JsonOrganization(io.lumeer.api.dto.JsonOrganization) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) Project(io.lumeer.api.model.Project) List(java.util.List) Response(javax.ws.rs.core.Response) Attribute(io.lumeer.api.model.Attribute) Collections(java.util.Collections) Collection(io.lumeer.api.model.Collection) Link(javax.ws.rs.core.Link) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) List(java.util.List) JsonCollection(io.lumeer.api.dto.JsonCollection) Test(org.junit.Test)

Example 23 with Permissions

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

the class CollectionServiceIT method testUpdateGroupPermissions.

@Test
public void testUpdateGroupPermissions() {
    String collectionId = createCollection(CODE).getId();
    SimplePermission groupPermission = new SimplePermission(GROUP, new HashSet<>(Arrays.asList(Role.SHARE, Role.READ)));
    Entity entity = Entity.json(groupPermission);
    Response response = client.target(COLLECTIONS_URL).path(collectionId).path("permissions").path("groups").request(MediaType.APPLICATION_JSON).buildPut(entity).invoke();
    assertThat(response).isNotNull();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
    Set<JsonPermission> returnedPermissions = response.readEntity(new GenericType<Set<JsonPermission>>() {
    });
    assertThat(returnedPermissions).isNotNull().hasSize(1);
    assertPermissions(Collections.unmodifiableSet(returnedPermissions), groupPermission);
    Permissions storedPermissions = collectionDao.getCollectionByCode(CODE).getPermissions();
    assertThat(storedPermissions).isNotNull();
    assertPermissions(storedPermissions.getUserPermissions(), USER_PERMISSION);
    assertPermissions(storedPermissions.getGroupPermissions(), groupPermission);
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) HashSet(java.util.HashSet) Set(java.util.Set) LumeerAssertions.assertPermissions(io.lumeer.test.util.LumeerAssertions.assertPermissions) JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permissions(io.lumeer.api.model.Permissions) JsonPermission(io.lumeer.api.dto.JsonPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 24 with Permissions

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

the class CollectionFacadeIT method testUpdateUserPermissions.

@Test
public void testUpdateUserPermissions() {
    String collectionId = createCollection(CODE).getId();
    SimplePermission userPermission = new SimplePermission(USER, new HashSet<>(Arrays.asList(Role.MANAGE, Role.READ)));
    collectionFacade.updateUserPermissions(collectionId, userPermission);
    Permissions permissions = collectionDao.getCollectionByCode(CODE).getPermissions();
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), userPermission);
    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) SimplePermission(io.lumeer.core.model.SimplePermission) Test(org.junit.Test)

Example 25 with Permissions

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

the class CollectionFacadeIT method testRemoveGroupPermission.

@Test
public void testRemoveGroupPermission() {
    String collectionId = createCollection(CODE).getId();
    collectionFacade.removeGroupPermission(collectionId, GROUP);
    Permissions permissions = collectionDao.getCollectionByCode(CODE).getPermissions();
    assertThat(permissions).isNotNull();
    assertPermissions(permissions.getUserPermissions(), USER_PERMISSION);
    assertThat(permissions.getGroupPermissions()).isEmpty();
}
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)

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