Skip to content

Commit 3de3346

Browse files
juanjmeronoern
authored andcommitted
SAK-32240 Access to the specific message from email footer (sakaiproject#4063)
1 parent 3c127f8 commit 3de3346

File tree

5 files changed

+124
-23
lines changed

5 files changed

+124
-23
lines changed

msgcntr/messageforums-api/src/bundle/org/sakaiproject/api/app/messagecenter/bundle/Messages.properties

+4
Original file line numberDiff line numberDiff line change
@@ -864,3 +864,7 @@ rank_assign_recipients_selected=recipients selected
864864
rank_assign_button_cancel=Cancel
865865
rank_assign_button_update=Update Individuals
866866
cdfm_not_selected_topic=You have to select forum and topic where moving thread
867+
868+
loading_direct_access=Loading message...
869+
error_direct_access=Error loading message
870+

msgcntr/messageforums-app/src/java/org/sakaiproject/tool/messageforums/PrivateMessagesTool.java

+27
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,33 @@ public void initializeFromSynoptic()
14571457
}
14581458
}
14591459

1460+
public String getReceivedTopicForMessage(String msgId) {
1461+
if (msgId!=null && getPvtAreaEnabled()) {
1462+
for (Topic topic : pvtTopics) {
1463+
String typeUuid = getPrivateMessageTypeFromContext(topic.getTitle());
1464+
List<Message> topicMessages = prtMsgManager.getMessagesByType(typeUuid, PrivateMessageManager.SORT_COLUMN_DATE,PrivateMessageManager.SORT_DESC);
1465+
for (Message dMsg : topicMessages) {
1466+
if (dMsg.getId().equals(Long.valueOf(msgId))) {
1467+
return topic.getUuid();
1468+
}
1469+
}
1470+
}
1471+
}
1472+
return null;
1473+
}
1474+
1475+
public String processPvtMsgTopicAndDetail() {
1476+
try {
1477+
processPvtMsgTopic();
1478+
viewChanged = true;
1479+
decoratedPvtMsgs = getDecoratedPvtMsgs();
1480+
return processPvtMsgDetail();
1481+
} catch (Exception ex) {
1482+
setErrorMessage(getResourceBundleString("error_direct_access"));
1483+
return null;
1484+
}
1485+
}
1486+
14601487
public String processPvtMsgTopic()
14611488
{
14621489
LOG.debug("processPvtMsgTopic()");

msgcntr/messageforums-app/src/webapp/WEB-INF/faces-config.xml

+5
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@
100100
<redirect/>
101101
</navigation-case>
102102

103+
<navigation-case>
104+
<from-outcome>pvtMsgDirectAccess</from-outcome>
105+
<to-view-id>/jsp/privateMsg/pvtMsgDirectAccess.jsp</to-view-id>
106+
<redirect/>
107+
</navigation-case>
103108
<navigation-case>
104109
<from-outcome>pvtMsgOrganize</from-outcome>
105110
<to-view-id>/jsp/privateMsg/pvtMsgOrganize.jsp</to-view-id>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<%@ page import="java.util.*, javax.faces.context.*, javax.faces.application.*,
2+
javax.faces.el.*, org.sakaiproject.tool.messageforums.*,
3+
org.sakaiproject.tool.messageforums.ui.*,javax.servlet.http.HttpUtils,java.util.Enumeration"%>
4+
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
5+
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
6+
<%@ taglib uri="http://sakaiproject.org/jsf/sakai" prefix="sakai" %>
7+
<%@ taglib uri="http://sakaiproject.org/jsf/messageforums" prefix="mf" %>
8+
9+
10+
<jsp:useBean id="msgs" class="org.sakaiproject.util.ResourceLoader" scope="session">
11+
<jsp:setProperty name="msgs" property="baseName" value="org.sakaiproject.api.app.messagecenter.bundle.Messages"/>
12+
</jsp:useBean>
13+
14+
<f:view>
15+
<sakai:view title="#{msgs.pvtarea_name}">
16+
<h:form id="prefs_pvt_form">
17+
<%
18+
FacesContext context = FacesContext.getCurrentInstance();
19+
ExternalContext exContext = context.getExternalContext();
20+
Map paramMap = exContext.getRequestParameterMap();
21+
Application app = context.getApplication();
22+
ValueBinding binding = app.createValueBinding("#{PrivateMessagesTool}");
23+
PrivateMessagesTool pmt = (PrivateMessagesTool) binding.getValue(context);
24+
request.setAttribute("currentTopic",pmt.getReceivedTopicForMessage((String) paramMap.get("current_msg_detail")));
25+
request.setAttribute("currentMessage",(String) paramMap.get("current_msg_detail"));
26+
27+
if(pmt.getUserId() != null){
28+
//show entire page, otherwise, don't allow anon user to use this tool:
29+
%>
30+
31+
<script type="text/javascript" src="/library/webjars/jquery/1.11.3/jquery.min.js?version="></script>
32+
<sakai:script contextBase="/messageforums-tool" path="/js/sak-10625.js"/>
33+
<sakai:script contextBase="/messageforums-tool" path="/js/forum.js"/>
34+
<script type="text/javascript">
35+
$(document).ready(function() {
36+
if ($('ul[class="alertMessage"]').length==0) {
37+
eval('function c(){' + $('a[title="shortaccess"]').attr('onclick') + '};c();');
38+
} else {
39+
$('a[title="shortaccess"]').toggle();
40+
}
41+
});
42+
</script>
43+
44+
<h:messages styleClass="alertMessage" id="errorMessages" rendered="#{! empty facesContext.maximumSeverity}"/>
45+
46+
<h:commandLink action="#{PrivateMessagesTool.processPvtMsgTopicAndDetail}"
47+
immediate="true" title="shortaccess">
48+
<h:outputText value="#{msgs.loading_direct_access}" />
49+
<f:param value="#{currentTopic}" name="pvtMsgTopicId" />
50+
<f:param value="#{currentMessage}" name="current_msg_detail" />
51+
</h:commandLink>
52+
<%
53+
}else{
54+
//user is an anon user, just show a message saying they can't use this tool:
55+
%>
56+
<h:outputText value="#{msgs.pvt_anon_warning}" styleClass="information"/>
57+
<%
58+
}
59+
%>
60+
61+
</h:form>
62+
</sakai:view>
63+
</f:view>

msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/ui/PrivateMessageManagerImpl.java

+25-23
Original file line numberDiff line numberDiff line change
@@ -1087,8 +1087,6 @@ public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipi
10871087
systemEmail = ServerConfigurationService.getString("msgcntr.notification.from.address", defaultEmail);
10881088
}
10891089

1090-
String bodyString = buildMessageBody(message);
1091-
10921090
Area currentArea = null;
10931091
List<PrivateForum> privateForums = null;
10941092
Map<String, PrivateForum> pfMap = null;
@@ -1160,24 +1158,6 @@ public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipi
11601158
recipientList.add(receiver);
11611159
}
11621160

1163-
if (asEmail)
1164-
{
1165-
//send as 1 action to all recipients
1166-
//we need to add som headers
1167-
additionalHeaders.add("From: " + systemEmail);
1168-
additionalHeaders.add("Subject: " + message.getTitle());
1169-
emailService.sendToUsers(recipients.keySet(), additionalHeaders, bodyString);
1170-
}
1171-
1172-
if(!isEmailForwardDisabled() && forwardingEnabled)
1173-
{
1174-
InternetAddress fAddressesArr[] = new InternetAddress[fAddresses.size()];
1175-
fAddressesArr = fAddresses.toArray(fAddressesArr);
1176-
emailService.sendMail(new InternetAddress(systemEmail), fAddressesArr, message.getTitle(),
1177-
bodyString, null, null, additionalHeaders);
1178-
}
1179-
1180-
11811161

11821162
/** add sender as a saved recipient */
11831163
PrivateMessageRecipientImpl sender = new PrivateMessageRecipientImpl(
@@ -1189,6 +1169,27 @@ public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipi
11891169
message.setRecipients(recipientList);
11901170

11911171
savePrivateMessage(message, false);
1172+
1173+
String bodyString = buildMessageBody(message);
1174+
1175+
if (asEmail)
1176+
{
1177+
//send as 1 action to all recipients
1178+
//we need to add som headers
1179+
additionalHeaders.add("From: " + systemEmail);
1180+
additionalHeaders.add("Subject: " + message.getTitle());
1181+
emailService.sendToUsers(recipients.keySet(), additionalHeaders, bodyString);
1182+
}
1183+
1184+
if(!isEmailForwardDisabled() && forwardingEnabled)
1185+
{
1186+
InternetAddress fAddressesArr[] = new InternetAddress[fAddresses.size()];
1187+
fAddressesArr = fAddresses.toArray(fAddressesArr);
1188+
emailService.sendMail(new InternetAddress(systemEmail), fAddressesArr, message.getTitle(),
1189+
bodyString, null, null, additionalHeaders);
1190+
}
1191+
1192+
11921193
}
11931194
catch (MessagingException e)
11941195
{
@@ -1289,14 +1290,14 @@ private String buildMessageBody(PrivateMessage message) {
12891290
LOG.error(e.getMessage(), e);
12901291
}
12911292

1292-
String thisPageId = "";
1293+
String thisToolId = "";
12931294
ToolSession ts = sessionManager.getCurrentToolSession();
12941295
if (ts != null)
12951296
{
12961297
ToolConfiguration tool = SiteService.findTool(ts.getPlacementId());
12971298
if (tool != null)
12981299
{
1299-
thisPageId = tool.getPageId();
1300+
thisToolId = tool.getId();
13001301
}
13011302
}
13021303

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

13141316

0 commit comments

Comments
 (0)