use of de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission in project webanno by webanno.
the class ProjectServiceImpl method setProjectPermissionLevels.
@Override
@Transactional(noRollbackFor = NoResultException.class)
public void setProjectPermissionLevels(User aUser, Project aProject, Collection<PermissionLevel> aLevels) {
Set<PermissionLevel> levelsToBeGranted = new HashSet<>(aLevels);
List<ProjectPermission> permissions = new ArrayList<>();
try {
permissions.addAll(listProjectPermissionLevel(aUser, aProject));
} catch (NoResultException e) {
// Nothing to do
}
// Remove permissions that no longer exist
for (ProjectPermission permission : permissions) {
if (!aLevels.contains(permission.getLevel())) {
removeProjectPermission(permission);
} else {
levelsToBeGranted.remove(permission.getLevel());
}
}
// Grant new permissions
for (PermissionLevel level : levelsToBeGranted) {
createProjectPermission(new ProjectPermission(aProject, aUser.getUsername(), level));
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission in project webanno by webanno.
the class ProjectServiceImpl method removeProject.
@Override
@Transactional
public void removeProject(Project aProject) throws IOException {
// remove metadata from DB
Project project = aProject;
if (!entityManager.contains(project)) {
project = entityManager.merge(project);
}
applicationEventPublisher.publishEvent(new BeforeProjectRemovedEvent(this, aProject));
for (ProjectPermission permissions : getProjectPermissions(aProject)) {
entityManager.remove(permissions);
}
entityManager.remove(project);
// remove the project directory from the file system
String path = dir.getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aProject.getId();
try {
FileUtils.deleteDirectory(new File(path));
} catch (FileNotFoundException e) {
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aProject.getId()))) {
log.info("Project directory to be deleted was not found: [{}]. Ignoring.", path);
}
}
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aProject.getId()))) {
log.info("Removed project [{}]({})", aProject.getName(), aProject.getId());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission in project webanno by webanno.
the class RemoteApiController2 method projectCreate.
@ApiOperation(value = "Create a new project")
@RequestMapping(value = ("/" + PROJECTS), method = RequestMethod.POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<RProject>> projectCreate(@RequestParam(PARAM_NAME) String aName, @RequestParam(PARAM_CREATOR) Optional<String> aCreator, UriComponentsBuilder aUcb) throws Exception {
// Get current user - this will throw an exception if the current user does not exit
User user = getCurrentUser();
// Check for the access
assertPermission("User [" + user.getUsername() + "] is not allowed to create projects", isProjectCreator(projectService, user) || isSuperAdmin(projectService, user));
// Check if the user can create projects for another user
assertPermission("User [" + user.getUsername() + "] is not allowed to create projects for user [" + aCreator.orElse("<unspecified>") + "]", isSuperAdmin(projectService, user) || (aCreator.isPresent() && aCreator.get().equals(user.getUsername())));
// Existing project
if (projectService.existsProject(aName)) {
throw new ObjectExistsException("A project with name [" + aName + "] already exists");
}
// Create the project and initialize tags
LOG.info("Creating project [" + aName + "]");
Project project = new Project();
project.setName(aName);
projectService.createProject(project);
annotationService.initializeProject(project);
// Create permission for the project creator
String owner = aCreator.isPresent() ? aCreator.get() : user.getUsername();
projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.ADMIN));
projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.CURATOR));
projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.USER));
RResponse<RProject> response = new RResponse<>(new RProject(project));
return ResponseEntity.created(aUcb.path(API_BASE + "/" + PROJECTS + "/{id}").buildAndExpand(project.getId()).toUri()).body(response);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission in project webanno by webanno.
the class UserSelectionPanel method actionAdd.
private void actionAdd(AjaxRequestTarget aTarget, Form<List<User>> aForm) {
for (User user : aForm.getModelObject()) {
projectRepository.createProjectPermission(new ProjectPermission(projectModel.getObject(), user.getUsername(), PermissionLevel.USER));
}
aForm.getModelObject().clear();
usersToAdd.getChoicesModel().detach();
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission in project webanno by webanno.
the class ProjectDetailPanel method actionSave.
private void actionSave(AjaxRequestTarget aTarget, Form<Project> aForm) {
aTarget.add(getPage());
// aTarget.add(((ApplicationPageBase) getPage()).getPageContent());
// aTarget.addChildren(getPage(), IFeedback.class);
Project project = aForm.getModelObject();
if (isNull(project.getId())) {
try {
String username = SecurityContextHolder.getContext().getAuthentication().getName();
projectService.createProject(project);
projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.ADMIN));
projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.CURATOR));
projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.USER));
annotationService.initializeProject(project);
} catch (IOException e) {
error("Project repository path not found " + ":" + ExceptionUtils.getRootCauseMessage(e));
LOG.error("Project repository path not found " + ":" + ExceptionUtils.getRootCauseMessage(e));
}
} else {
projectService.updateProject(project);
}
}
Aggregations