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();
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations