Search in sources :

Example 16 with Permission

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

the class MorphiaCollectionDaoTest method testGetCollectionsByCollectionIds.

@Test
public void testGetCollectionsByCollectionIds() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    collection.getPermissions().removeUserPermission(USER);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.READ.toString()));
    collection.getPermissions().updateUserPermissions(userPermission);
    datastore.save(collectionDao.databaseCollection(), collection);
    MorphiaCollection collection2 = prepareCollection(CODE2, NAME2);
    datastore.save(collectionDao.databaseCollection(), collection2);
    MorphiaCollection collection3 = prepareCollection(CODE3, NAME3);
    datastore.save(collectionDao.databaseCollection(), collection3);
    SearchQuery query = SearchQuery.createBuilder(USER).collectionIds(new HashSet<>(Arrays.asList(collection.getId(), collection3.getId()))).build();
    List<Collection> views = collectionDao.getCollections(query);
    assertThat(views).extracting(Collection::getId).containsOnly(collection3.getId());
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Permission(io.lumeer.api.model.Permission) MorphiaCollection(io.lumeer.storage.mongodb.model.MorphiaCollection) Collection(io.lumeer.api.model.Collection) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 17 with Permission

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

the class MorphiaViewDaoTest method testGetViewsNoReadRole.

@Test
public void testGetViewsNoReadRole() {
    MorphiaView view = prepareView();
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    view.getPermissions().updateUserPermissions(userPermission);
    datastore.save(viewDao.databaseCollection(), view);
    MorphiaView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    view2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(viewDao.databaseCollection(), view2);
    SearchQuery query = SearchQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<View> views = viewDao.getViews(query);
    assertThat(views).isEmpty();
}
Also used : SearchQuery(io.lumeer.storage.api.query.SearchQuery) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Permission(io.lumeer.api.model.Permission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) View(io.lumeer.api.model.View) MorphiaView(io.lumeer.storage.mongodb.model.MorphiaView) Test(org.junit.Test)

Example 18 with Permission

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

the class OrganizationServicePermissionsIT method testUpdateGroupPermissionManageRole.

@Test
public void testUpdateGroupPermissionManageRole() {
    String name = "testUpdateGroupPermissionNoRole";
    String code = "testUpdateGroupPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.updateUserPermissions(code, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    String group = "testGroup2";
    Permission newPermission = new JsonPermission(group, Role.toStringRoles(new HashSet<>(Collections.singletonList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions/groups").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Permission(io.lumeer.api.model.Permission) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 19 with Permission

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

the class OrganizationServicePermissionsIT method testGetOrganizationReadRole.

@Test
public void testGetOrganizationReadRole() {
    String name = "TestGetOrganizationReadRole";
    String code = "TestGetOrganizationReadRole_id";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(Collections.singleton(Role.READ)));
    organizationFacade.updateUserPermissions(code, newPermission);
    Set<Permission> perm = organizationDao.getOrganizationByCode(code).getPermissions().getUserPermissions();
    LumeerAssertions.assertPermissions(perm, newPermission);
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code).request(MediaType.APPLICATION_JSON).buildGet().invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.OK);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Permission(io.lumeer.api.model.Permission) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Example 20 with Permission

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

the class OrganizationServicePermissionsIT method testUpdateGroupPermissionNoRole.

@Test
public void testUpdateGroupPermissionNoRole() {
    String name = "testUpdateGroupPermissionNoRole";
    String code = "testUpdateGroupPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.removeUserPermission(code, userEmail);
    String group = "testGroup1";
    Permission newPermission = new JsonPermission(group, Role.toStringRoles(new HashSet<>(Collections.singletonList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/permissions/groups").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
Also used : Response(javax.ws.rs.core.Response) Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Permission(io.lumeer.api.model.Permission) JsonOrganization(io.lumeer.api.dto.JsonOrganization) JsonPermission(io.lumeer.api.dto.JsonPermission) Test(org.junit.Test)

Aggregations

Permission (io.lumeer.api.model.Permission)23 Test (org.junit.Test)15 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)10 JsonPermission (io.lumeer.api.dto.JsonPermission)9 SimplePermission (io.lumeer.core.model.SimplePermission)9 Response (javax.ws.rs.core.Response)9 Organization (io.lumeer.api.model.Organization)7 JsonOrganization (io.lumeer.api.dto.JsonOrganization)5 HashSet (java.util.HashSet)5 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 Collection (io.lumeer.api.model.Collection)2 Project (io.lumeer.api.model.Project)2 View (io.lumeer.api.model.View)2 DatabaseQuery (io.lumeer.storage.api.query.DatabaseQuery)2 MorphiaCollection (io.lumeer.storage.mongodb.model.MorphiaCollection)2 Document (org.bson.Document)2 JsonPermissions (io.lumeer.api.dto.JsonPermissions)1 JsonView (io.lumeer.api.dto.JsonView)1 Permissions (io.lumeer.api.model.Permissions)1 Resource (io.lumeer.api.model.Resource)1