use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationServiceTest method shouldCreateOrganization.
@Test
public void shouldCreateOrganization() throws Exception {
when(orgManager.create(any())).thenAnswer(invocationOnMock -> new OrganizationImpl((Organization) invocationOnMock.getArguments()[0]));
final OrganizationDto toCreate = createOrganization();
final Response response = given().auth().basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD).contentType("application/json").body(toCreate).when().post(SECURE_PATH + "/organization");
assertEquals(response.statusCode(), 201);
final OrganizationDto createdOrganization = unwrapDto(response, OrganizationDto.class);
assertEquals(createdOrganization, toCreate);
verify(linksInjector).injectLinks(any(), any());
verify(orgManager).create(eq(toCreate));
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationResourceDistributionServicePermissionsFilter method filter.
@Override
protected void filter(GenericResourceMethod genericMethodResource, Object[] arguments) throws ApiException {
final String methodName = genericMethodResource.getMethod().getName();
final Subject currentSubject = EnvironmentContext.getCurrent().getSubject();
String organizationId;
switch(methodName) {
case GET_RESOURCES_CAP_METHOD:
if (superPrivilegesChecker.hasSuperPrivileges()) {
// user is able to see information about all organizations
return;
}
// fall through
case CAP_RESOURCES_METHOD:
// we should check permissions on parent organization level
Organization organization = organizationManager.getById((String) arguments[0]);
organizationId = organization.getParent();
if (organizationId == null) {
// requested organization is root so manager should throw exception
return;
}
break;
case GET_DISTRIBUTED_RESOURCES:
organizationId = (String) arguments[0];
// get organization to ensure that organization exists
organizationManager.getById(organizationId);
if (superPrivilegesChecker.hasSuperPrivileges()) {
// user is able to see information about all organizations
return;
}
break;
default:
throw new ForbiddenException("The user does not have permission to perform this operation");
}
if (!currentSubject.hasPermission(OrganizationDomain.DOMAIN_ID, organizationId, OrganizationDomain.MANAGE_RESOURCES)) {
throw new ForbiddenException("The user does not have permission to manage resources of organization with id '" + organizationId + "'");
}
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project devspaces-images by redhat-developer.
the class OrganizationalAccountAvailableResourcesProvider method getUsedResourcesBySuborganizations.
/**
* Returns resources which are used by suborganizations of specified organization.
*
* <p>Note that the result will includes used resources of all direct and nested suborganizations.
*
* @param parentQualifiedName parent qualified name, e.g. 'parentName/suborgName
* @return resources which are used by suborganizations of specified organization.
* @throws ServerException when any other exception occurs on calculation of used resources
*/
@VisibleForTesting
List<Resource> getUsedResourcesBySuborganizations(String parentQualifiedName) throws NotFoundException, ServerException {
ResourceManager resourceManager = resourceManagerProvider.get();
List<Resource> usedResources = new ArrayList<>();
for (Organization suborganization : Pages.iterate((maxItems, skipCount) -> organizationManager.getSuborganizations(parentQualifiedName, maxItems, skipCount))) {
usedResources.addAll(resourceManager.getUsedResources(suborganization.getId()));
}
return usedResources;
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.
the class OrganizationManagerTest method shouldThrowConflictExceptionOnCreationIfOrganizationNameIsReserved.
@Test(expectedExceptions = ConflictException.class)
public void shouldThrowConflictExceptionOnCreationIfOrganizationNameIsReserved() throws Exception {
final Organization organization = DtoFactory.newDto(OrganizationDto.class).withName("reserved").withParent(null);
manager.create(organization);
}
use of org.eclipse.che.multiuser.organization.shared.model.Organization in project che-server by eclipse-che.
the class OrganizationalAccountAvailableResourcesProvider method getUsedResourcesBySuborganizations.
/**
* Returns resources which are used by suborganizations of specified organization.
*
* <p>Note that the result will includes used resources of all direct and nested suborganizations.
*
* @param parentQualifiedName parent qualified name, e.g. 'parentName/suborgName
* @return resources which are used by suborganizations of specified organization.
* @throws ServerException when any other exception occurs on calculation of used resources
*/
@VisibleForTesting
List<Resource> getUsedResourcesBySuborganizations(String parentQualifiedName) throws NotFoundException, ServerException {
ResourceManager resourceManager = resourceManagerProvider.get();
List<Resource> usedResources = new ArrayList<>();
for (Organization suborganization : Pages.iterate((maxItems, skipCount) -> organizationManager.getSuborganizations(parentQualifiedName, maxItems, skipCount))) {
usedResources.addAll(resourceManager.getUsedResources(suborganization.getId()));
}
return usedResources;
}
Aggregations