Search in sources :

Example 6 with MorphiaPermission

use of io.lumeer.storage.mongodb.model.embedded.MorphiaPermission 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)

Example 7 with MorphiaPermission

use of io.lumeer.storage.mongodb.model.embedded.MorphiaPermission 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 8 with MorphiaPermission

use of io.lumeer.storage.mongodb.model.embedded.MorphiaPermission 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 9 with MorphiaPermission

use of io.lumeer.storage.mongodb.model.embedded.MorphiaPermission in project engine by Lumeer.

the class ProjectServicePermissionsIT method configureProject.

@Before
public void configureProject() {
    MorphiaOrganization organization = new MorphiaOrganization();
    organization.setCode(organizationCode);
    organization.setName(organizationName);
    organization.setPermissions(new MorphiaPermissions());
    organization.getPermissions().updateUserPermissions(new MorphiaPermission(userEmail, Role.toStringRoles(new HashSet<>(Arrays.asList(Role.WRITE, Role.READ, Role.MANAGE)))));
    Organization storedOrganization = organizationDao.createOrganization(organization);
    projectDao.setOrganization(storedOrganization);
    workspaceKeeper.setOrganization(organizationCode);
    User user = new User(userEmail);
    userDao.createUser(user);
}
Also used : Organization(io.lumeer.api.model.Organization) JsonOrganization(io.lumeer.api.dto.JsonOrganization) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) User(io.lumeer.api.model.User) AuthenticatedUser(io.lumeer.core.AuthenticatedUser) MorphiaPermission(io.lumeer.storage.mongodb.model.embedded.MorphiaPermission) MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) MorphiaPermissions(io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions) Before(org.junit.Before)

Aggregations

MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)9 Permission (io.lumeer.api.model.Permission)6 Test (org.junit.Test)6 Organization (io.lumeer.api.model.Organization)4 SearchQuery (io.lumeer.storage.api.query.SearchQuery)4 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)4 User (io.lumeer.api.model.User)3 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)3 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)3 Before (org.junit.Before)3 Collection (io.lumeer.api.model.Collection)2 View (io.lumeer.api.model.View)2 DatabaseQuery (io.lumeer.storage.api.query.DatabaseQuery)2 MorphiaCollection (io.lumeer.storage.mongodb.model.MorphiaCollection)2 JsonOrganization (io.lumeer.api.dto.JsonOrganization)1 JsonView (io.lumeer.api.dto.JsonView)1 Project (io.lumeer.api.model.Project)1 MorphiaProject (io.lumeer.storage.mongodb.model.MorphiaProject)1 MorphiaView (io.lumeer.storage.mongodb.model.MorphiaView)1 HashSet (java.util.HashSet)1