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