Search in sources :

Example 66 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class JpaOrganizationDao method doRemove.

@Transactional
protected void doRemove(String organizationId) {
    final EntityManager manager = managerProvider.get();
    final OrganizationImpl organization = manager.find(OrganizationImpl.class, organizationId);
    if (organization != null) {
        manager.remove(organization);
        manager.flush();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Transactional(com.google.inject.persist.Transactional)

Example 67 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class JpaOrganizationDao method getByParent.

@Override
@Transactional
public Page<OrganizationImpl> getByParent(String parent, int maxItems, long skipCount) throws ServerException {
    requireNonNull(parent, "Required non-null parent");
    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();
        final List<OrganizationImpl> result = manager.createNamedQuery("Organization.getByParent", OrganizationImpl.class).setParameter("parent", parent).setMaxResults(maxItems).setFirstResult((int) skipCount).getResultList();
        final Long suborganizationsCount = manager.createNamedQuery("Organization.getByParentCount", Long.class).setParameter("parent", parent).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 68 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationPermissionsFilterTest method shouldCheckPermissionsOnParentOrgLevelOnChildOrganizationRemoving.

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

Example 69 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationPermissionsFilterTest method shouldCheckPermissionsOnChildOrganizationRemovingWhenUserDoesNotHavePermissionsOnParentOrgLevel.

@Test
public void shouldCheckPermissionsOnChildOrganizationRemovingWhenUserDoesNotHavePermissionsOnParentOrgLevel() 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", DELETE);
    final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").when().delete(SECURE_PATH + "/organization/organization123");
    assertEquals(response.getStatusCode(), 204);
    verify(service).remove(eq("organization123"));
    verify(subject).hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS);
    verify(subject).hasPermission(DOMAIN_ID, "organization123", DELETE);
    verify(superPrivilegesChecker, never()).hasSuperPrivileges();
    verifyNoMoreInteractions(subject);
}
Also used : Response(io.restassured.response.Response) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

Example 70 with OrganizationImpl

use of org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl in project che-server by eclipse-che.

the class OrganizationPermissionsFilterTest method shouldCheckPermissionsOnParentOrgLevelOnChildOrganizationUpdating.

@Test
public void shouldCheckPermissionsOnParentOrgLevelOnChildOrganizationUpdating() throws Exception {
    when(manager.getById(anyString())).thenReturn(new OrganizationImpl("organization123", "test", "parent123"));
    when(subject.hasPermission(DOMAIN_ID, "parent123", MANAGE_SUBORGANIZATIONS)).thenReturn(true);
    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(superPrivilegesChecker, never()).hasSuperPrivileges();
    verifyNoMoreInteractions(subject);
}
Also used : Response(io.restassured.response.Response) OrganizationImpl(org.eclipse.che.multiuser.organization.spi.impl.OrganizationImpl) Test(org.testng.annotations.Test)

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