Search in sources :

Example 6 with InterpretationComment

use of org.hisp.dhis.interpretation.InterpretationComment in project dhis2-core by dhis2.

the class InterpretationController method updateComment.

@PutMapping("/{uid}/comments/{cuid}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public WebMessage updateComment(@PathVariable("uid") String uid, @PathVariable("cuid") String cuid, @RequestBody String content) {
    Interpretation interpretation = interpretationService.getInterpretation(uid);
    if (interpretation == null) {
        return conflict("Interpretation does not exist: " + uid);
    }
    for (InterpretationComment comment : interpretation.getComments()) {
        if (comment.getUid().equals(cuid)) {
            if (!currentUserService.getCurrentUser().equals(comment.getCreatedBy()) && !currentUserService.currentUserIsSuper()) {
                throw new AccessDeniedException("You are not allowed to update this comment.");
            }
            comment.setText(content);
            interpretationService.updateComment(interpretation, comment);
        }
    }
    return null;
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) InterpretationComment(org.hisp.dhis.interpretation.InterpretationComment) Interpretation(org.hisp.dhis.interpretation.Interpretation) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) PutMapping(org.springframework.web.bind.annotation.PutMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

Interpretation (org.hisp.dhis.interpretation.Interpretation)6 InterpretationComment (org.hisp.dhis.interpretation.InterpretationComment)6 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)3 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 Date (java.util.Date)1 User (org.hisp.dhis.user.User)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 PostMapping (org.springframework.web.bind.annotation.PostMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1