Search in sources :

Example 91 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationPermissionsFilterTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    lenient().when(subject.getUserId()).thenReturn(USER_ID);
    lenient().when(manager.getById(anyString())).thenReturn(new OrganizationImpl("organization123", "test", null));
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 92 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationPermissionsFilterTest method shouldCheckPermissionsOnChildOrganizationUpdatingWhenUserDoesNotHavePermissionsOnParentOrgLevel.

@Test
public void shouldCheckPermissionsOnChildOrganizationUpdatingWhenUserDoesNotHavePermissionsOnParentOrgLevel() throws Exception {
    when(manager.getById(anyString())).thenReturn(new OrganizationImpl("organization123", "test", "parent123"));
    doReturn(false).when(subject).hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS);
    doReturn(true).when(subject).hasPermission(DOMAIN_ID, "organization123", UPDATE);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().post(SECURE_PATH + "/organization/organization123");
    assertEquals(response.getStatusCode(), 204);
    verify(service).update(eq("organization123"), any());
    verify(subject).hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS);
    verify(subject).hasPermission(DOMAIN_ID, "organization123", UPDATE);
}
Also used : Response(io.restassured.response.Response) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 93 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class OrganizationResourceDistributionServicePermissionsFilterTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    lenient().when(manager.getById(SUBORGANIZATION)).thenReturn(new OrganizationImpl(SUBORGANIZATION, "testOrg", PARENT_ORGANIZATION));
    lenient().when(manager.getById(PARENT_ORGANIZATION)).thenReturn(new OrganizationImpl(PARENT_ORGANIZATION, "parentOrg", null));
    lenient().when(subject.hasPermission(anyString(), anyString(), anyString())).thenReturn(true);
}
Also used : OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 94 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class JpaOrganizationDao method getSuborganizations.

@Override
@Transactional
public Page<OrganizationImpl> getSuborganizations(String parentQualifiedName, int maxItems, long skipCount) throws ServerException {
    requireNonNull(parentQualifiedName, "Required non-null parent qualified name");
    checkArgument(skipCount <= Integer.MAX_VALUE, "The number of items to skip can't be greater than " + Integer.MAX_VALUE);
    try {
        final EntityManager manager = managerProvider.get();
        List<OrganizationImpl> result = manager.createNamedQuery("Organization.getSuborganizations", OrganizationImpl.class).setParameter("qualifiedName", parentQualifiedName + "/%").setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList();
        final long suborganizationsCount = manager.createNamedQuery("Organization.getSuborganizationsCount", Long.class).setParameter("qualifiedName", parentQualifiedName + "/%").getSingleResult();
        return new Page<>(result, skipCount, maxItems, suborganizationsCount);
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) Page(org.eclipse.che.api.core.Page) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 95 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project devspaces-images by redhat-developer.

the class JpaOrganizationDao method getById.

@Override
@Transactional
public OrganizationImpl getById(String organizationId) throws NotFoundException, ServerException {
    requireNonNull(organizationId, "Required non-null organization id");
    try {
        final EntityManager manager = managerProvider.get();
        OrganizationImpl organization = manager.find(OrganizationImpl.class, organizationId);
        if (organization == null) {
            throw new NotFoundException(format("Organization with id '%s' doesn't exist", organizationId));
        }
        return organization;
    } catch (RuntimeException e) {
        throw new ServerException(e.getLocalizedMessage(), e);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) NotFoundException(org.eclipse.che.api.core.NotFoundException) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Aggregations

OrganizationImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl)100 Test (org.testng.annotations.Test)56 Transactional (com.google.inject.persist.Transactional)18 BeforeMethod (org.testng.annotations.BeforeMethod)16 EntityManager (javax.persistence.EntityManager)14 MemberImpl (org.eclipse.che.multiuser.organization.spi.impl.MemberImpl)14 Organization (org.eclipse.che.multiuser.organization.shared.model.Organization)13 Response (io.restassured.response.Response)12 Page (org.eclipse.che.api.core.Page)10 ServerException (org.eclipse.che.api.core.ServerException)8 UserImpl (org.eclipse.che.api.user.server.model.impl.UserImpl)8 OrganizationDao (org.eclipse.che.multiuser.organization.spi.OrganizationDao)8 OrganizationDistributedResourcesImpl (org.eclipse.che.multiuser.organization.spi.impl.OrganizationDistributedResourcesImpl)7 TypeLiteral (com.google.inject.TypeLiteral)6 JpaPersistModule (com.google.inject.persist.jpa.JpaPersistModule)6 NotFoundException (org.eclipse.che.api.core.NotFoundException)6 OrganizationDto (org.eclipse.che.multiuser.organization.shared.dto.OrganizationDto)6 UserDevfilePermissionImpl (org.eclipse.che.multiuser.permission.devfile.server.model.impl.UserDevfilePermissionImpl)6 TckResourcesCleaner (org.eclipse.che.commons.test.tck.TckResourcesCleaner)5 DBInitializer (org.eclipse.che.core.db.DBInitializer)5