Search in sources :

Example 21 with Permission

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

the class ProjectServicePermissionsIT method testUpdateUserPermissionsManageRole.

@Test
public void testUpdateUserPermissionsManageRole() {
    String projectCode = "testGetProjectPermissionsNoRole_code1";
    String projectName = "testGetProjectPermissionsNoRole";
    createProject(projectCode, projectName);
    projectFacade.updateUserPermissions(projectCode, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    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.OK);
}
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 22 with Permission

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

the class ProjectServicePermissionsIT method testUpdateGroupPermissionsManageRole.

@Test
public void testUpdateGroupPermissionsManageRole() {
    String projectCode = "testGetProjectPermissionsNoRole_code1";
    String projectName = "testGetProjectPermissionsNoRole";
    createProject(projectCode, projectName);
    projectFacade.updateUserPermissions(projectCode, new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.READ, Role.MANAGE)))));
    String group = "testGroup5";
    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.OK);
}
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 23 with Permission

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

the class PermissionsCodec method convertFromDocument.

public static JsonPermissions convertFromDocument(final Document document) {
    if (document == null) {
        return new JsonPermissions();
    }
    Permission[] userPermissions = new ArrayList<Document>(document.get(USER_ROLES, List.class)).stream().map(PermissionCodec::convertFromDocument).toArray(Permission[]::new);
    Permission[] groupPermissions = new ArrayList<Document>(document.get(GROUP_ROLES, List.class)).stream().map(PermissionCodec::convertFromDocument).toArray(Permission[]::new);
    JsonPermissions permissions = new JsonPermissions();
    permissions.updateUserPermissions(userPermissions);
    permissions.updateGroupPermissions(groupPermissions);
    return permissions;
}
Also used : JsonPermissions(io.lumeer.api.dto.JsonPermissions) Permission(io.lumeer.api.model.Permission) Document(org.bson.Document)

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