From 3de3346154d6814f5e122868e2e73ad9d09d2ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20Mero=C3=B1o=20S=C3=A1nchez?= Date: Tue, 14 Mar 2017 16:19:04 +0100 Subject: [PATCH] SAK-32240 Access to the specific message from email footer (#4063) --- .../messagecenter/bundle/Messages.properties | 4 ++ .../messageforums/PrivateMessagesTool.java | 27 ++++++++ .../src/webapp/WEB-INF/faces-config.xml | 5 ++ .../jsp/privateMsg/pvtMsgDirectAccess.jsp | 63 +++++++++++++++++++ .../ui/PrivateMessageManagerImpl.java | 48 +++++++------- 5 files changed, 124 insertions(+), 23 deletions(-) create mode 100644 msgcntr/messageforums-app/src/webapp/jsp/privateMsg/pvtMsgDirectAccess.jsp diff --git a/msgcntr/messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties b/msgcntr/messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties index 7cb6f17cca85..4333d833b484 100644 --- a/msgcntr/messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties +++ b/msgcntr/messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties @@ -864,3 +864,7 @@ rank_assign_recipients_selected=recipients selected rank_assign_button_cancel=Cancel rank_assign_button_update=Update Individuals cdfm_not_selected_topic=You have to select forum and topic where moving thread + +loading_direct_access=Loading message... +error_direct_access=Error loading message + diff --git a/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/PrivateMessagesTool.java b/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/PrivateMessagesTool.java index fca9458792e3..a7c41a0a6342 100644 --- a/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/PrivateMessagesTool.java +++ b/msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/PrivateMessagesTool.java @@ -1457,6 +1457,33 @@ public void initializeFromSynoptic() } } + public String getReceivedTopicForMessage(String msgId) { + if (msgId!=null && getPvtAreaEnabled()) { + for (Topic topic : pvtTopics) { + String typeUuid = getPrivateMessageTypeFromContext(topic.getTitle()); + List topicMessages = prtMsgManager.getMessagesByType(typeUuid, PrivateMessageManager.SORT_COLUMN_DATE,PrivateMessageManager.SORT_DESC); + for (Message dMsg : topicMessages) { + if (dMsg.getId().equals(Long.valueOf(msgId))) { + return topic.getUuid(); + } + } + } + } + return null; + } + + public String processPvtMsgTopicAndDetail() { + try { + processPvtMsgTopic(); + viewChanged = true; + decoratedPvtMsgs = getDecoratedPvtMsgs(); + return processPvtMsgDetail(); + } catch (Exception ex) { + setErrorMessage(getResourceBundleString("error_direct_access")); + return null; + } + } + public String processPvtMsgTopic() { LOG.debug("processPvtMsgTopic()"); diff --git a/msgcntr/messageforums-app/src/webapp/WEB-INF/faces-config.xml b/msgcntr/messageforums-app/src/webapp/WEB-INF/faces-config.xml index 194dab77cac2..c2597722396b 100644 --- a/msgcntr/messageforums-app/src/webapp/WEB-INF/faces-config.xml +++ b/msgcntr/messageforums-app/src/webapp/WEB-INF/faces-config.xml @@ -100,6 +100,11 @@ + + pvtMsgDirectAccess + /jsp/privateMsg/pvtMsgDirectAccess.jsp + + pvtMsgOrganize /jsp/privateMsg/pvtMsgOrganize.jsp diff --git a/msgcntr/messageforums-app/src/webapp/jsp/privateMsg/pvtMsgDirectAccess.jsp b/msgcntr/messageforums-app/src/webapp/jsp/privateMsg/pvtMsgDirectAccess.jsp new file mode 100644 index 000000000000..ec94018ddd48 --- /dev/null +++ b/msgcntr/messageforums-app/src/webapp/jsp/privateMsg/pvtMsgDirectAccess.jsp @@ -0,0 +1,63 @@ +<%@ page import="java.util.*, javax.faces.context.*, javax.faces.application.*, + javax.faces.el.*, org.sakaiproject.tool.messageforums.*, + org.sakaiproject.tool.messageforums.ui.*,javax.servlet.http.HttpUtils,java.util.Enumeration"%> +<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> +<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> +<%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %> +<%@ taglib uri="http://sakaiproject.org/jsf/messageforums" prefix="mf" %> + + + + + + + + + +<% + FacesContext context = FacesContext.getCurrentInstance(); + ExternalContext exContext = context.getExternalContext(); + Map paramMap = exContext.getRequestParameterMap(); + Application app = context.getApplication(); + ValueBinding binding = app.createValueBinding("#{PrivateMessagesTool}"); + PrivateMessagesTool pmt = (PrivateMessagesTool) binding.getValue(context); + request.setAttribute("currentTopic",pmt.getReceivedTopicForMessage((String) paramMap.get("current_msg_detail"))); + request.setAttribute("currentMessage",(String) paramMap.get("current_msg_detail")); + + if(pmt.getUserId() != null){ + //show entire page, otherwise, don't allow anon user to use this tool: +%> + + + + + + + + + + + + + +<% + }else{ + //user is an anon user, just show a message saying they can't use this tool: +%> + +<% + } +%> + + + + diff --git a/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java b/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java index 651e98c2fc9d..9d065e5e1464 100644 --- a/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java +++ b/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java @@ -1087,8 +1087,6 @@ public void sendPrivateMessage(PrivateMessage message, Map recipi systemEmail = ServerConfigurationService.getString("msgcntr.notification.from.address", defaultEmail); } - String bodyString = buildMessageBody(message); - Area currentArea = null; List privateForums = null; Map pfMap = null; @@ -1160,24 +1158,6 @@ public void sendPrivateMessage(PrivateMessage message, Map recipi recipientList.add(receiver); } - if (asEmail) - { - //send as 1 action to all recipients - //we need to add som headers - additionalHeaders.add("From: " + systemEmail); - additionalHeaders.add("Subject: " + message.getTitle()); - emailService.sendToUsers(recipients.keySet(), additionalHeaders, bodyString); - } - - if(!isEmailForwardDisabled() && forwardingEnabled) - { - InternetAddress fAddressesArr[] = new InternetAddress[fAddresses.size()]; - fAddressesArr = fAddresses.toArray(fAddressesArr); - emailService.sendMail(new InternetAddress(systemEmail), fAddressesArr, message.getTitle(), - bodyString, null, null, additionalHeaders); - } - - /** add sender as a saved recipient */ PrivateMessageRecipientImpl sender = new PrivateMessageRecipientImpl( @@ -1189,6 +1169,27 @@ public void sendPrivateMessage(PrivateMessage message, Map recipi message.setRecipients(recipientList); savePrivateMessage(message, false); + + String bodyString = buildMessageBody(message); + + if (asEmail) + { + //send as 1 action to all recipients + //we need to add som headers + additionalHeaders.add("From: " + systemEmail); + additionalHeaders.add("Subject: " + message.getTitle()); + emailService.sendToUsers(recipients.keySet(), additionalHeaders, bodyString); + } + + if(!isEmailForwardDisabled() && forwardingEnabled) + { + InternetAddress fAddressesArr[] = new InternetAddress[fAddresses.size()]; + fAddressesArr = fAddresses.toArray(fAddressesArr); + emailService.sendMail(new InternetAddress(systemEmail), fAddressesArr, message.getTitle(), + bodyString, null, null, additionalHeaders); + } + + } catch (MessagingException e) { @@ -1289,14 +1290,14 @@ private String buildMessageBody(PrivateMessage message) { LOG.error(e.getMessage(), e); } - String thisPageId = ""; + String thisToolId = ""; ToolSession ts = sessionManager.getCurrentToolSession(); if (ts != null) { ToolConfiguration tool = SiteService.findTool(ts.getPlacementId()); if (tool != null) { - thisPageId = tool.getPageId(); + thisToolId = tool.getId(); } } @@ -1308,7 +1309,8 @@ private String buildMessageBody(PrivateMessage message) { " ";