use of org.hisp.dhis.user.CurrentUser in project dhis2-core by dhis2.
the class MessageConversationController method markMessageConversationFollowup.
// --------------------------------------------------------------------------
// Mark conversations for follow up
// --------------------------------------------------------------------------
@PostMapping(value = "followup", produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseBody
public RootNode markMessageConversationFollowup(@RequestParam(value = "user", required = false) String userUid, @RequestBody List<String> uids, HttpServletResponse response, @CurrentUser User currentUser) {
RootNode responseNode = new RootNode("response");
User user = userUid != null ? userService.getUser(userUid) : currentUser;
if (user == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
return responseNode;
}
if (!canModifyUserConversation(currentUser, user)) {
throw new UpdateAccessDeniedException("Not authorized to modify this object.");
}
Collection<org.hisp.dhis.message.MessageConversation> messageConversations = messageService.getMessageConversations(user, uids);
if (messageConversations.isEmpty()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No MessageConversations found for the given UIDs"));
return responseNode;
}
CollectionNode marked = responseNode.addChild(new CollectionNode("markedFollowup"));
marked.setWrapping(false);
for (org.hisp.dhis.message.MessageConversation conversation : messageConversations) {
if (!conversation.isFollowUp()) {
conversation.toggleFollowUp(user);
messageService.updateMessageConversation(conversation);
}
marked.addChild(new SimpleNode("uid", conversation.getUid()));
}
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
use of org.hisp.dhis.user.CurrentUser in project dhis2-core by dhis2.
the class MessageConversationController method modifyMessageConversationRead.
/**
* Internal handler for setting the read property of MessageConversation.
*
* @param readValue true when setting as read, false when setting unread.
*/
private RootNode modifyMessageConversationRead(String userUid, List<String> uids, HttpServletResponse response, boolean readValue, User currentUser) {
RootNode responseNode = new RootNode("response");
User user = userUid != null ? userService.getUser(userUid) : currentUser;
if (user == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No user with uid: " + userUid));
return responseNode;
}
if (!canModifyUserConversation(currentUser, user)) {
throw new UpdateAccessDeniedException("Not authorized to modify this object.");
}
Collection<org.hisp.dhis.message.MessageConversation> messageConversations = messageService.getMessageConversations(user, uids);
if (messageConversations.isEmpty()) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
responseNode.addChild(new SimpleNode("message", "No MessageConversations found for the given IDs."));
return responseNode;
}
CollectionNode marked = responseNode.addChild(new CollectionNode(readValue ? "markedRead" : "markedUnread"));
marked.setWrapping(false);
for (org.hisp.dhis.message.MessageConversation conversation : messageConversations) {
boolean success = (readValue ? conversation.markRead(user) : conversation.markUnread(user));
if (success) {
messageService.updateMessageConversation(conversation);
marked.addChild(new SimpleNode("uid", conversation.getUid()));
}
}
response.setStatus(HttpServletResponse.SC_OK);
return responseNode;
}
use of org.hisp.dhis.user.CurrentUser in project dhis2-core by dhis2.
the class MeController method updateCurrentUser.
@PutMapping(value = "", consumes = APPLICATION_JSON_VALUE)
public void updateCurrentUser(HttpServletRequest request, HttpServletResponse response, @CurrentUser(required = true) User currentUser) throws Exception {
List<String> fields = Lists.newArrayList(contextService.getParameterValues("fields"));
User user = renderService.fromJson(request.getInputStream(), User.class);
merge(currentUser, user);
if (user.getWhatsApp() != null && !ValidationUtils.validateWhatsapp(user.getWhatsApp())) {
throw new WebMessageException(conflict("Invalid format for WhatsApp value '" + user.getWhatsApp() + "'"));
}
manager.update(currentUser);
if (fields.isEmpty()) {
fields.addAll(Preset.ALL.getFields());
}
CollectionNode collectionNode = oldFieldFilterService.toCollectionNode(User.class, new org.hisp.dhis.fieldfilter.FieldFilterParams(Collections.singletonList(currentUser), fields));
response.setContentType(APPLICATION_JSON_VALUE);
nodeService.serialize(NodeUtils.createRootNode(collectionNode.getChildren().get(0)), APPLICATION_JSON_VALUE, response.getOutputStream());
}
use of org.hisp.dhis.user.CurrentUser in project dhis2-core by dhis2.
the class UserController method putJsonObject.
@Override
@PutMapping(value = "/{uid}", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage putJsonObject(@PathVariable("uid") String pvUid, @CurrentUser User currentUser, HttpServletRequest request) throws Exception {
User parsed = renderService.fromJson(request.getInputStream(), getEntityClass());
populateUserCredentialsDtoFields(parsed);
return importReport(updateUser(pvUid, parsed)).withPlainResponseBefore(DhisApiVersion.V38);
}
use of org.hisp.dhis.user.CurrentUser in project dhis2-core by dhis2.
the class UserRoleController method removeUserFromRole.
@DeleteMapping("/{id}/users/{userId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void removeUserFromRole(@PathVariable(value = "id") String pvId, @PathVariable("userId") String pvUserId, @CurrentUser User currentUser, HttpServletResponse response) throws WebMessageException {
UserAuthorityGroup userAuthorityGroup = userService.getUserAuthorityGroup(pvId);
if (userAuthorityGroup == null) {
throw new WebMessageException(notFound("UserRole does not exist: " + pvId));
}
User user = userService.getUser(pvUserId);
if (user == null) {
throw new WebMessageException(notFound("User does not exist: " + pvId));
}
if (!aclService.canUpdate(currentUser, userAuthorityGroup)) {
throw new DeleteAccessDeniedException("You don't have the proper permissions to delete this object.");
}
if (user.getUserAuthorityGroups().contains(userAuthorityGroup)) {
user.getUserAuthorityGroups().remove(userAuthorityGroup);
userService.updateUser(user);
}
}
Aggregations