Search in sources :

Example 11 with Permission

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

the class ProjectServicePermissionsIT method testUpdateGroupPermissionsNoRole.

@Test
public void testUpdateGroupPermissionsNoRole() {
    String projectCode = "testGetProjectPermissionsNoRole_code1";
    String projectName = "testGetProjectPermissionsNoRole";
    createProject(projectCode, projectName);
    projectFacade.removeUserPermission(projectCode, userEmail);
    String group = "testGroup4";
    Permission newPermission = new JsonPermission(group, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + projectCode + "/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) JsonPermission(io.lumeer.api.dto.JsonPermission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Permission(io.lumeer.api.model.Permission) JsonPermission(io.lumeer.api.dto.JsonPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with Permission

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

the class ProjectServicePermissionsIT method testUpdateUserPermissionsNoRole.

@Test
public void testUpdateUserPermissionsNoRole() {
    String projectCode = "testGetProjectPermissionsNoRole_code1";
    String projectName = "testGetProjectPermissionsNoRole";
    createProject(projectCode, projectName);
    projectFacade.removeUserPermission(projectCode, userEmail);
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + projectCode + "/permissions/users").request(MediaType.APPLICATION_JSON).buildPut(Entity.json(newPermission)).invoke();
    assertThat(response.getStatusInfo()).isEqualTo(Response.Status.UNAUTHORIZED);
}
Also used : Response(javax.ws.rs.core.Response) JsonPermission(io.lumeer.api.dto.JsonPermission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) SimplePermission(io.lumeer.core.model.SimplePermission) Permission(io.lumeer.api.model.Permission) JsonPermission(io.lumeer.api.dto.JsonPermission) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 13 with Permission

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

the class AbstractFacade method keepOnlyActualUserRoles.

protected <T extends Resource> T keepOnlyActualUserRoles(final T resource) {
    Set<Role> roles = permissionsChecker.getActualRoles(resource);
    Permission permission = new SimplePermission(authenticatedUser.getUserEmail(), roles);
    resource.getPermissions().clear();
    resource.getPermissions().updateUserPermissions(permission);
    return resource;
}
Also used : Role(io.lumeer.api.model.Role) Permission(io.lumeer.api.model.Permission) SimplePermission(io.lumeer.core.model.SimplePermission) SimplePermission(io.lumeer.core.model.SimplePermission)

Example 14 with Permission

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

the class MorphiaProjectDaoTest method testGetProjectsNoReadRole.

@Test
public void testGetProjectsNoReadRole() {
    MorphiaProject project = prepareProject(CODE1);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    project.getPermissions().updateUserPermissions(userPermission);
    datastore.save(projectDao.databaseCollection(), project);
    MorphiaProject project2 = prepareProject(CODE2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    project2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(projectDao.databaseCollection(), project2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<Project> projects = projectDao.getProjects(query);
    assertThat(projects).isEmpty();
}
Also used : MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Project(io.lumeer.api.model.Project) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) MorphiaProject(io.lumeer.storage.mongodb.model.MorphiaProject) Permission(io.lumeer.api.model.Permission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Test(org.junit.Test)

Example 15 with Permission

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

the class MorphiaCollectionDaoTest method testGetCollectionsNoReadRole.

@Test
public void testGetCollectionsNoReadRole() {
    MorphiaCollection collection = prepareCollection(CODE, NAME);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    collection.getPermissions().updateUserPermissions(userPermission);
    datastore.save(collectionDao.databaseCollection(), collection);
    MorphiaCollection collection2 = prepareCollection(CODE2, NAME2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    collection2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(collectionDao.databaseCollection(), collection2);
    SearchQuery query = SearchQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<Collection> collections = collectionDao.getCollections(query);
    assertThat(collections).isEmpty();
}
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) 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