use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.
the class DataAccessRequestResource method changeApplicant.
@PUT
@Path("/_applicant")
public Response changeApplicant(@PathParam("id") String id, @QueryParam("username") String applicant) {
if (!SecurityUtils.getSubject().hasRole(Roles.MICA_DAO) && !SecurityUtils.getSubject().hasRole(Roles.MICA_ADMIN)) {
throw new AuthorizationException();
}
if (Strings.isNullOrEmpty(applicant))
throw new IllegalArgumentException("An applicant name is required");
DataAccessRequest request = dataAccessRequestService.findById(id);
String originalApplicant = request.getApplicant();
dataAccessRequestService.changeApplicantAndSave(request, applicant);
commentsService.findPublicComments("/data-access-request", id).stream().filter(comment -> comment.getCreatedBy().equals(originalApplicant)).map(comment -> Comment.newBuilder(comment).createdBy(applicant).build()).forEach(comment -> commentsService.save(comment, null));
return Response.noContent().build();
}
use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.
the class DataAccessController method getComments.
@GetMapping("/data-access-comments/{id:.+}")
public ModelAndView getComments(@PathVariable String id) {
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
Map<String, Object> params = newParameters(id);
addDataAccessConfiguration(params);
List<Comment> comments = commentsService.findPublicComments("/data-access-request", id);
params.put("comments", comments);
params.put("authors", comments.stream().map(AbstractAuditableDocument::getCreatedBy).distinct().collect(Collectors.toMap(u -> u, u -> userProfileService.getProfileMap(u, true))));
return new ModelAndView("data-access-comments", params);
} else {
return new ModelAndView("redirect:../signin?redirect=" + micaConfigService.getContextPath() + "/data-access-comments%2F" + id);
}
}
use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.
the class DataAccessRequestResource method createComment.
@POST
@Path("/comments")
public Response createComment(@PathParam("id") String id, String message) {
subjectAclService.checkPermission("/data-access-request", "VIEW", id);
dataAccessRequestService.findById(id);
Comment comment = //
commentsService.save(//
Comment.newBuilder().createdBy(//
SecurityUtils.getSubject().getPrincipal().toString()).message(//
message).resourceId(//
"/data-access-request").instanceId(//
id).build(), //
commentMailNotification);
subjectAclService.addPermission("/data-access-request/" + id + "/comment", "VIEW,EDIT,DELETE", comment.getId());
subjectAclService.addGroupPermission(Roles.MICA_DAO, "/data-access-request/" + id + "/comment", "DELETE", comment.getId());
return Response.noContent().build();
}
use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.
the class DataAccessRequestResource method createComment.
@POST
@Path("/comments")
public Response createComment(@PathParam("id") String id, String message, @QueryParam("admin") @DefaultValue("false") boolean admin) {
subjectAclService.checkPermission("/data-access-request", "VIEW", id);
DataAccessRequest request = dataAccessRequestService.findById(id);
if (request.isArchived())
throw new BadRequestException("Data access request is archived");
Comment.Builder buildComment = //
Comment.newBuilder().createdBy(//
SecurityUtils.getSubject().getPrincipal().toString()).message(//
message).resourceId(//
"/data-access-request").instanceId(id);
if (admin) {
if (!subjectAclService.isPermitted("/data-access-request/private-comment", "VIEW"))
subjectAclService.checkPermission("/private-comment/data-access-request", "ADD");
buildComment.admin(admin);
}
//
Comment comment = commentsService.save(buildComment.build(), commentMailNotification);
subjectAclService.addPermission("/data-access-request/" + id + "/comment", "VIEW,EDIT,DELETE", comment.getId());
subjectAclService.addGroupPermission(Roles.MICA_DAO, "/data-access-request/" + id + "/comment", "DELETE", comment.getId());
return Response.noContent().build();
}
use of org.obiba.mica.core.domain.Comment in project mica2 by obiba.
the class CommentsResource method createComment.
@POST
public Response createComment(@PathParam("id") String id, String message) {
subjectAclService.checkPermission(String.format("/draft/%s", service.getTypeName()), "VIEW", id);
Comment comment = //
commentsService.save(//
Comment.newBuilder().createdBy(//
SecurityUtils.getSubject().getPrincipal().toString()).message(//
message).resourceId(//
String.format("/draft/%s", service.getTypeName())).instanceId(//
id).build(), commentMailNotification);
subjectAclService.addPermission(String.format("/draft/%s/%s/comment", service.getTypeName(), id), "VIEW,EDIT,DELETE", comment.getId());
return Response.noContent().build();
}
Aggregations