use of org.eclipse.vorto.repository.model.ModelNamespaceNotOfficialException in project vorto by eclipse.
the class ModelRepositoryController method makeModelPublic.
@PreAuthorize("isAuthenticated()")
@PostMapping(value = "/{modelId:.+}/makePublic", produces = "application/json")
public ResponseEntity<Status> makeModelPublic(@PathVariable final String modelId) {
IUserContext user = UserContext.user(SecurityContextHolder.getContext().getAuthentication(), getWorkspaceId(ControllerUtils.sanitize(modelId)));
ModelId modelID = ModelId.fromPrettyFormat(modelId);
try {
if (!userRepositoryRoleService.isSysadmin(user.getUsername()) && !userNamespaceRoleService.hasRole(user.getUsername(), modelID.getNamespace(), "model_publisher")) {
return new ResponseEntity<>(Status.fail("Only users with Publisher roles are allowed to make models public"), HttpStatus.UNAUTHORIZED);
}
} catch (DoesNotExistException dnee) {
return new ResponseEntity<>(Status.fail(dnee.getMessage()), HttpStatus.NOT_FOUND);
}
if (modelID.getNamespace().startsWith(Namespace.PRIVATE_NAMESPACE_PREFIX)) {
return new ResponseEntity<>(Status.fail("Only models with official namespace can be made public"), HttpStatus.FORBIDDEN);
}
try {
LOGGER.info("Making the model '" + ControllerUtils.sanitize(modelId) + "' public.");
modelService.makeModelPublic(ModelId.fromPrettyFormat(ControllerUtils.sanitize(modelId)));
} catch (ModelNotReleasedException | ModelNamespaceNotOfficialException e) {
return new ResponseEntity<>(Status.fail(e.getMessage()), HttpStatus.FORBIDDEN);
}
return new ResponseEntity<>(Status.success(), HttpStatus.OK);
}
use of org.eclipse.vorto.repository.model.ModelNamespaceNotOfficialException in project vorto by eclipse.
the class DefaultBulkOperationsService method makeModelPublicRecursively.
private void makeModelPublicRecursively(ModelId modelId, List<ModelId> modelsMadePublicAcc) throws ExecutionException {
if (hasPrivateNamespace(modelId)) {
throw new ModelNamespaceNotOfficialException(modelId);
}
IModelRepository repository = repositoryFactory.getRepositoryByModel(modelId);
ModelInfo modelInfo = repository.getById(modelId);
if (!modelInfo.isReleased()) {
throw new ModelNotReleasedException(modelId);
}
if (isPrivate(modelInfo)) {
LOGGER.info("Changing visibility of model " + modelId.getPrettyFormat() + " to public.");
// Add public visibility property
repository.updateVisibility(modelId, IModelRepository.VISIBILITY_PUBLIC);
// Add corresponding policy to model
IModelPolicyManager policyMgr = this.repositoryFactory.getPolicyManager(repository.getWorkspaceId(), getAuthenticationToken());
policyMgr.addPolicyEntry(modelId, PolicyEntry.of(IModelPolicyManager.ANONYMOUS_ACCESS_POLICY, PrincipalType.User, Permission.READ));
modelsMadePublicAcc.add(modelId);
// Make references public
for (ModelId referencedModelId : modelInfo.getReferences()) {
makeModelPublicRecursively(referencedModelId, modelsMadePublicAcc);
}
}
}
Aggregations