Search in sources :

Example 6 with Permission

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

the class MongoViewDaoTest method testGetViewsNoReadRole.

@Test
public void testGetViewsNoReadRole() {
    JsonView view = prepareView();
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    view.getPermissions().updateUserPermissions(userPermission);
    viewDao.databaseCollection().insertOne(view);
    JsonView view2 = prepareView();
    view2.setCode(CODE2);
    view2.setName(NAME2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    view2.getPermissions().updateGroupPermissions(groupPermission);
    viewDao.databaseCollection().insertOne(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) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Permission(io.lumeer.api.model.Permission) JsonView(io.lumeer.api.dto.JsonView) JsonView(io.lumeer.api.dto.JsonView) View(io.lumeer.api.model.View) Test(org.junit.Test)

Example 7 with Permission

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

the class MorphiaOrganizationDaoTest method testGetOrganizationsNoReadRole.

@Test
public void testGetOrganizationsNoReadRole() {
    Organization organization = prepareOrganization(CODE1);
    Permission userPermission = new MorphiaPermission(USER2, Collections.singleton(Role.CLONE.toString()));
    organization.getPermissions().updateUserPermissions(userPermission);
    datastore.save(organization);
    Organization organization2 = prepareOrganization(CODE2);
    Permission groupPermission = new MorphiaPermission(GROUP2, Collections.singleton(Role.SHARE.toString()));
    organization2.getPermissions().updateGroupPermissions(groupPermission);
    datastore.save(organization2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER2).groups(Collections.singleton(GROUP2)).build();
    List<Organization> organizations = organizationDao.getOrganizations(query);
    assertThat(organizations).isEmpty();
}
Also used : MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) Organization(io.lumeer.api.model.Organization) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) Permission(io.lumeer.api.model.Permission) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) Test(org.junit.Test)

Example 8 with Permission

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

the class PermissionsCodec method encode.

@Override
public void encode(final BsonWriter writer, final JsonPermissions value, final EncoderContext encoderContext) {
    Set<Permission> userPermissions = value.getUserPermissions();
    Set<Permission> groupPermissions = value.getGroupPermissions();
    Document bson = new Document(USER_ROLES, userPermissions).append(GROUP_ROLES, groupPermissions);
    documentCodec.encode(writer, bson, encoderContext);
}
Also used : Permission(io.lumeer.api.model.Permission) Document(org.bson.Document)

Example 9 with Permission

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

the class OrganizationServicePermissionsIT method testUpdateUserPermissionManageRole.

@Test
public void testUpdateUserPermissionManageRole() {
    String name = "testUpdateUserPermissionNoRole";
    String code = "testUpdateUserPermissionNoRole_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)))));
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Collections.singletonList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/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) 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 10 with Permission

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

the class OrganizationServicePermissionsIT method testUpdateUserPermissionNoRole.

@Test
public void testUpdateUserPermissionNoRole() {
    String name = "testUpdateUserPermissionNoRole";
    String code = "testUpdateUserPermissionNoRole_code";
    Organization organization = new JsonOrganization(code, name, "a", "b", null, null);
    organizationFacade.createOrganization(organization);
    organizationFacade.removeUserPermission(code, userEmail);
    Permission newPermission = new JsonPermission(userEmail, Role.toStringRoles(new HashSet<>(Collections.singletonList(Role.WRITE))));
    Response response = client.target(TARGET_URI).path(PATH_PREFIX + code + "/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) 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