Skip to content

Commit

Permalink
SAK-32240 Access to the specific message from email footer (sakaiproj…
Browse files Browse the repository at this point in the history
  • Loading branch information
juanjmerono authored and ern committed Mar 14, 2017
1 parent 3c127f8 commit 3de3346
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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<Message> 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()");
Expand Down
5 changes: 5 additions & 0 deletions msgcntr/messageforums-app/src/webapp/WEB-INF/faces-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@
<redirect/>
</navigation-case>

<navigation-case>
<from-outcome>pvtMsgDirectAccess</from-outcome>
<to-view-id>/jsp/privateMsg/pvtMsgDirectAccess.jsp</to-view-id>
<redirect/>
</navigation-case>
<navigation-case>
<from-outcome>pvtMsgOrganize</from-outcome>
<to-view-id>/jsp/privateMsg/pvtMsgOrganize.jsp</to-view-id>
Expand Down
Original file line number Diff line number Diff line change
@@ -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" %>


<jsp:useBean id="msgs" class="org.sakaiproject.util.ResourceLoader" scope="session">
<jsp:setProperty name="msgs" property="baseName" value="org.sakaiproject.api.app.messagecenter.bundle.Messages"/>
</jsp:useBean>

<f:view>
<sakai:view title="#{msgs.pvtarea_name}">
<h:form id="prefs_pvt_form">
<%
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:
%>

<script type="text/javascript" src="/library/webjars/jquery/1.11.3/jquery.min.js?version="></script>
<sakai:script contextBase="/messageforums-tool" path="/js/sak-10625.js"/>
<sakai:script contextBase="/messageforums-tool" path="/js/forum.js"/>
<script type="text/javascript">
$(document).ready(function() {
if ($('ul[class="alertMessage"]').length==0) {
eval('function c(){' + $('a[title="shortaccess"]').attr('onclick') + '};c();');
} else {
$('a[title="shortaccess"]').toggle();
}
});
</script>

<h:messages styleClass="alertMessage" id="errorMessages" rendered="#{! empty facesContext.maximumSeverity}"/>

<h:commandLink action="#{PrivateMessagesTool.processPvtMsgTopicAndDetail}"
immediate="true" title="shortaccess">
<h:outputText value="#{msgs.loading_direct_access}" />
<f:param value="#{currentTopic}" name="pvtMsgTopicId" />
<f:param value="#{currentMessage}" name="current_msg_detail" />
</h:commandLink>
<%
}else{
//user is an anon user, just show a message saying they can't use this tool:
%>
<h:outputText value="#{msgs.pvt_anon_warning}" styleClass="information"/>
<%
}
%>

</h:form>
</sakai:view>
</f:view>
Original file line number Diff line number Diff line change
Expand Up @@ -1087,8 +1087,6 @@ public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipi
systemEmail = ServerConfigurationService.getString("msgcntr.notification.from.address", defaultEmail);
}

String bodyString = buildMessageBody(message);

Area currentArea = null;
List<PrivateForum> privateForums = null;
Map<String, PrivateForum> pfMap = null;
Expand Down Expand Up @@ -1160,24 +1158,6 @@ public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> 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(
Expand All @@ -1189,6 +1169,27 @@ public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> 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)
{
Expand Down Expand Up @@ -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();
}
}

Expand All @@ -1308,7 +1309,8 @@ private String buildMessageBody(PrivateMessage message) {
" <a href=\"" +
ServerConfigurationService.getPortalUrl() +
"/site/" + ToolManager.getCurrentPlacement().getContext() +
"/page/" + thisPageId+
"/tool/" + thisToolId+
(message!=null?"/privateMsg/pvtMsgDirectAccess?current_msg_detail="+message.getId():"")+
"\">";


Expand Down

0 comments on commit 3de3346

Please sign in to comment.