Search in sources :

Example 6 with Organization

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

the class GroupFacade method checkPermissions.

private void checkPermissions() {
    if (!workspaceKeeper.getOrganization().isPresent()) {
        throw new ResourceNotFoundException(ResourceType.ORGANIZATION);
    }
    Organization organization = workspaceKeeper.getOrganization().get();
    permissionsChecker.checkRole(organization, Role.MANAGE);
}
Also used : Organization(io.lumeer.api.model.Organization) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException)

Example 7 with Organization

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

the class AuthenticatedUser method getCurrentUserGroups.

public Set<String> getCurrentUserGroups() {
    Optional<Organization> organizationOptional = workspaceKeeper.getOrganization();
    if (!organizationOptional.isPresent()) {
        throw new ResourceNotFoundException(ResourceType.ORGANIZATION);
    }
    Organization organization = organizationOptional.get();
    Map<String, Set<String>> userGroups = userCache.getUser(getCurrentUsername()).getGroups();
    return userGroups != null && userGroups.containsKey(organization.getId()) ? userGroups.get(organization.getId()) : Collections.emptySet();
}
Also used : Organization(io.lumeer.api.model.Organization) Set(java.util.Set) ResourceNotFoundException(io.lumeer.storage.api.exception.ResourceNotFoundException)

Example 8 with Organization

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

the class MorphiaProjectDaoTest method initProjectDao.

@Before
public void initProjectDao() {
    Organization organization = Mockito.mock(Organization.class);
    Mockito.when(organization.getId()).thenReturn(ORGANIZATION_ID);
    projectDao = new MorphiaProjectDao();
    projectDao.setDatabase(database);
    projectDao.setDatastore(datastore);
    projectDao.setOrganization(organization);
    projectDao.ensureIndexes();
}
Also used : Organization(io.lumeer.api.model.Organization) Before(org.junit.Before)

Example 9 with Organization

use of io.lumeer.api.model.Organization 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 10 with Organization

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

the class MorphiaOrganizationDaoTest method testGetOrganizations.

@Test
public void testGetOrganizations() {
    Organization organization = prepareOrganization(CODE1);
    datastore.save(organization);
    Organization organization2 = prepareOrganization(CODE2);
    datastore.save(organization2);
    DatabaseQuery query = DatabaseQuery.createBuilder(USER).build();
    List<Organization> organizations = organizationDao.getOrganizations(query);
    assertThat(organizations).extracting(Organization::getCode).containsOnly(CODE1, CODE2);
}
Also used : MorphiaOrganization(io.lumeer.storage.mongodb.model.MorphiaOrganization) Organization(io.lumeer.api.model.Organization) DatabaseQuery(io.lumeer.storage.api.query.DatabaseQuery) Test(org.junit.Test)

Aggregations

Organization (io.lumeer.api.model.Organization)69 JsonOrganization (io.lumeer.api.dto.JsonOrganization)42 Test (org.junit.Test)31 JsonPermission (io.lumeer.api.dto.JsonPermission)22 Response (javax.ws.rs.core.Response)20 Before (org.junit.Before)18 User (io.lumeer.api.model.User)17 AuthenticatedUser (io.lumeer.core.AuthenticatedUser)17 Project (io.lumeer.api.model.Project)15 JsonProject (io.lumeer.api.dto.JsonProject)14 JsonPermissions (io.lumeer.api.dto.JsonPermissions)13 MorphiaOrganization (io.lumeer.storage.mongodb.model.MorphiaOrganization)13 JsonCollection (io.lumeer.api.dto.JsonCollection)8 Permission (io.lumeer.api.model.Permission)7 SoftAssertions (org.assertj.core.api.SoftAssertions)6 MorphiaPermissions (io.lumeer.storage.mongodb.model.embedded.MorphiaPermissions)5 ResourceNotFoundException (io.lumeer.storage.api.exception.ResourceNotFoundException)4 MorphiaPermission (io.lumeer.storage.mongodb.model.embedded.MorphiaPermission)4 Role (io.lumeer.api.model.Role)3 DatabaseQuery (io.lumeer.storage.api.query.DatabaseQuery)3