Skip to content

Commit

Permalink
SAK-30079: Provide global setting for the option Auto forward Message… (
Browse files Browse the repository at this point in the history
sakaiproject#7652)

* SAK-30079: Provide global setting for the option Auto forward Messages in Messages tool

* SAK-30079: Resolve Issues Sonar

* SAK-30079: Fix minor comments

* SAK-30079: Provide global setting for the option Auto forward Message

* SAK-30079: Provide global setting for the option Auto forward Message

* Resolve Fixes

* SAK-30079: Resolved Fixes

* Correcting properties
  • Loading branch information
victorGomollon authored Feb 20, 2020
1 parent 0909adb commit 2847ea2
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2531,6 +2531,10 @@
# DEFAULT: false.
# prefs.research.collab=true

# To set the default value for message notifications on sites
# DEFAULT: 0 = NO; 1 = YES.
#prefs.msg.notification=1

## PRESENCE
# Enables logging of presence events as expected for site stats. Does not enable the presence list.
# DEFAULT: true
Expand Down Expand Up @@ -3780,6 +3784,7 @@
# prefs.tool.order.2=sakai.resources
# prefs.tool.order.3=sakai.syllabus
# prefs.tool.order.4=sakai.mailbox
# prefs.tool.order.5=sakai.messages

# Comma seperated list of tools to hide.
# NOTE: Unavailable tools are: the stealth tools plus the hidden tools, minus the visible ones
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ pvt_rename_folder_button = Rename Folder
pvt_rename_folder_label = Rename Messages Folder
pvt_yes = Yes
pvt_no = No
pvt_default = Default
pvt_reply_prefix = Re:
#SAKAI-10505
pvt_forward_prefix = FW:
Expand Down Expand Up @@ -900,4 +901,12 @@ topic_associate_label=Use the following rubric to grade this topic
option_pointsoverride=Adjust individual student scores
option_hidepoints=Hide point values (feedback only)
option_studentpreview=Hide Rubric from student
grading_rubric=Grading Rubric
grading_rubric=Grading Rubric

prefs_title=Messages
# Do not remove prefs_description or prefs_title_override, check SAK-21078 for risk and code for reason
prefs_description=Configure an alternative messages forwarding email address in the 'Messages' tool.
prefs_title_override=
prefs_opt2=Do not forward private messages to my email address
prefs_opt1=Forward private messages from all my sites to my main email address
prefs_msg_default=1
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ pvt_rename_folder_button=Renombrar carpeta
pvt_rename_folder_label=Renombrar carpeta de mensajes
pvt_yes=S\u00ed
pvt_no=No
pvt_default = Por defecto
pvt_reply_prefix=Re\:
#SAKAI-10505
pvt_forward_prefix=RV\:
Expand Down Expand Up @@ -896,3 +897,10 @@ option_pointsoverride=Ajustar notas individuales de estudiantes
option_hidepoints=Ocultar valores de puntuaci\u00f3n (solo en feedback)
option_studentpreview=Ocultar r\u00fabrica al estudiante
grading_rubric=Evaluaci\u00f3n de r\u00fabricas

prefs_title=Mensajes Privados
# Do not remove prefs_description or prefs_title_override, check SAK-21078 for risk and code for reason
prefs_description=Configure reenviar los mensajes privados de todos sus sitios a su correo principal. En caso de querer otro correo configure esta opci\u00f3n en "Mensajes Privados"
prefs_title_override=
prefs_opt2=No
prefs_opt1=S\u00ed
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public interface PrivateForum extends BaseForum {

public void setOwner(String owner);

public Boolean getAutoForward();
public Integer getAutoForward();

public void setAutoForward(Boolean autoForward);
public void setAutoForward(Integer autoForward);

public String getAutoForwardEmail();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.app.messageforums.MembershipItem;
import org.sakaiproject.component.app.messageforums.dao.hibernate.HiddenGroupImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateForumImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateTopicImpl;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.content.api.ContentHostingService;
Expand Down Expand Up @@ -273,7 +274,8 @@ public class PrivateMessagesTool {

public static final String SET_AS_YES="yes";
public static final String SET_AS_NO="no";

public static final String SET_AS_DEFAULT="default";

public static final String THREADED_VIEW = "threaded";

//huxt
Expand Down Expand Up @@ -365,7 +367,7 @@ public class PrivateMessagesTool {
@Getter @Setter
private String activatePvtMsg=SET_AS_NO;
@Getter @Setter
private String forwardPvtMsg=SET_AS_NO;
private String forwardPvtMsg=SET_AS_DEFAULT;
@Getter @Setter
private String forwardPvtMsgEmail;
private boolean superUser;
Expand Down Expand Up @@ -442,7 +444,19 @@ public void initializePrivateMessageArea() {
forum=pf;
activatePvtMsg = (Boolean.TRUE.equals(area.getEnabled())) ? SET_AS_YES : SET_AS_NO;
sendToEmail = area.getSendToEmail() + "";
forwardPvtMsg = (Boolean.TRUE.equals(pf.getAutoForward())) ? SET_AS_YES : SET_AS_NO;

switch (pf.getAutoForward()) {
case PrivateForumImpl.AUTO_FOWARD_YES:
forwardPvtMsg = SET_AS_YES;
break;
case PrivateForumImpl.AUTO_FOWARD_NO:
forwardPvtMsg = SET_AS_NO;
break;
default:
forwardPvtMsg = SET_AS_DEFAULT;
break;
}

forwardPvtMsgEmail = pf.getAutoForwardEmail();
hiddenGroups = new ArrayList<>();
if(area != null && area.getHiddenGroups() != null){
Expand Down Expand Up @@ -3301,11 +3315,17 @@ public void processPvtMsgSettingsRevise(ValueChangeEvent event)
log.debug("processPvtMsgSettingsRevise()");

/** block executes when changing value to "no" */
if (SET_AS_YES.equals(forwardPvtMsg)){
setForwardPvtMsgEmail(null);
}
if (SET_AS_NO.equals(forwardPvtMsg)){
setValidEmail(true);

switch (forwardPvtMsg) {
case SET_AS_YES:
setForwardPvtMsgEmail(null);
break;
case SET_AS_NO:
setValidEmail(true);
break;
default:
setValidEmail(true);
break;
}
}

Expand All @@ -3317,7 +3337,7 @@ public String processPvtMsgSettingsSave()
String email= getForwardPvtMsgEmail();
String activate=getActivatePvtMsg() ;
String forward=getForwardPvtMsg() ;
if (email != null && (!SET_AS_NO.equals(forward))
if (email != null && (SET_AS_YES.equals(forward))
&& !EmailValidator.getInstance().isValid(email) ) {
setValidEmail(false);
setErrorMessage(getResourceBundleString(PROVIDE_VALID_EMAIL));
Expand All @@ -3341,9 +3361,19 @@ public String processPvtMsgSettingsSave()
return null;
}

Boolean formAutoForward = (SET_AS_YES.equals(forward)) ? Boolean.TRUE : Boolean.FALSE;
forum.setAutoForward(formAutoForward);
if (Boolean.TRUE.equals(formAutoForward)){
switch (forward) {
case SET_AS_YES:
forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_YES);
break;
case SET_AS_NO:
forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_NO);
break;
default:
forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_DEFAULT);
break;
}

if (SET_AS_YES.equals(forward)){
forum.setAutoForwardEmail(email);
}
else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@
styleClass="checkbox inlineForm">
<f:selectItem itemValue="yes" itemLabel="#{msgs.pvt_yes}" />
<f:selectItem itemValue="no" itemLabel="#{msgs.pvt_no}" />
<f:selectItem itemValue="default" itemLabel="#{msgs.pvt_default}" />
</h:selectOneRadio>
<h:outputLabel for="fwd_email"><h:outputText value="#{msgs.pvt_emailfor}" /></h:outputLabel>
<h:inputText value="#{PrivateMessagesTool.forwardPvtMsgEmail}" id="fwd_email"
disabled="#{PrivateMessagesTool.forwardPvtMsg == 'no'}" />
disabled="#{!('yes'.equals(PrivateMessagesTool.forwardPvtMsg))}" />
</h:panelGroup>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private List getPrivateForums()
pfm1.setTitle("Messages");
pfm1.setTopics((getPrivateTopics()));
// pfm1.setType(new TypeImpl());
pfm1.setAutoForward(Boolean.TRUE);
pfm1.setAutoForward(PrivateForumImpl.AUTO_FOWARD_YES);
pfm1.setAutoForwardEmail("[email protected]");
pfm1.setPreviewPaneEnabled(Boolean.TRUE);
pfm1.setSortIndex(Integer.valueOf(2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ public PrivateForum createPrivateForum(String title, String userId) {
forum.setSortIndex(Integer.valueOf(0));
forum.setShortDescription("short-desc");
forum.setExtendedDescription("ext desc");
forum.setAutoForward(Boolean.FALSE);
forum.setAutoForward(PrivateForumImpl.AUTO_FOWARD_DEFAULT);
forum.setAutoForwardEmail("");
forum.setPreviewPaneEnabled(Boolean.FALSE);
forum.setModified(new Date());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sakaiproject.component.app.messageforums;

import org.sakaiproject.util.ResourceLoader;
import org.sakaiproject.util.UserNotificationPreferencesRegistrationImpl;

public class MsgcntrUserNotificationPreferencesRegistrationImpl extends UserNotificationPreferencesRegistrationImpl {

public ResourceLoader getResourceLoader(String location) {
return new ResourceLoader(location);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,19 @@
import org.sakaiproject.api.app.messageforums.ui.PrivateMessageManager;
import org.sakaiproject.authz.api.SecurityService;
import org.sakaiproject.component.app.messageforums.TestUtil;
import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateForumImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateMessageImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.PrivateMessageRecipientImpl;
import org.sakaiproject.component.cover.ComponentManager;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.content.api.ContentHostingService;
import org.sakaiproject.content.api.ContentResource;
import org.sakaiproject.email.api.EmailService;
import org.sakaiproject.entity.api.EntityPropertyNotDefinedException;
import org.sakaiproject.entity.api.EntityPropertyTypeException;
import org.sakaiproject.entity.api.ResourceProperties;
import org.sakaiproject.event.api.EventTrackingService;
import org.sakaiproject.event.api.NotificationService;
import org.sakaiproject.exception.IdUnusedException;
import org.sakaiproject.id.api.IdManager;
import org.sakaiproject.site.api.Site;
Expand All @@ -76,6 +82,8 @@
import org.sakaiproject.tool.api.SessionManager;
import org.sakaiproject.tool.api.ToolSession;
import org.sakaiproject.tool.api.ToolManager;
import org.sakaiproject.user.api.Preferences;
import org.sakaiproject.user.api.PreferencesService;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.util.ResourceLoader;
Expand All @@ -89,6 +97,8 @@ public class PrivateMessageManagerImpl extends HibernateDaoSupport implements Pr

private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";

private final PreferencesService preferencesService = ComponentManager.get( PreferencesService.class );

private AreaManager areaManager;
private MessageForumsMessageManager messageManager;
private MessageForumsForumManager forumManager;
Expand Down Expand Up @@ -1132,37 +1142,60 @@ public void sendPrivateMessage(PrivateMessage message, Map<User, Boolean> recipi

boolean forwardingEnabled = false;
List<InternetAddress> fAddresses = new ArrayList<InternetAddress>();
//this only needs to be done if the message is not being sent
//this only needs to be done if the message is not being sent
int submitterEmailReceiptPref;
for (Iterator<Entry<User, Boolean>> i = recipients.entrySet().iterator(); i.hasNext();)
{
Entry<User, Boolean> entrySet = (Entry<User, Boolean>) i.next();
User u = (User) entrySet.getKey();
Boolean bcc = (Boolean) entrySet.getValue();
String userId = u.getId();
String mailAFoward = u.getEmail();



//boolean forwardingEnabled = false;
//String forwardAddress = null;

submitterEmailReceiptPref = 0;
submitterEmailReceiptPref = ServerConfigurationService.getInt("prefs.msg.notification", submitterEmailReceiptPref);
Preferences submitterPrefs = preferencesService.getPreferences( userId );
ResourceProperties props = submitterPrefs.getProperties( NotificationService.PREFS_TYPE + "sakai:messageforums" );

try {
submitterEmailReceiptPref = (int) props.getLongProperty("2");
} catch (EntityPropertyNotDefinedException | EntityPropertyTypeException ex) {
/* User hasn't changed preference */
}

PrivateForum pf = null;
if (pfMap.containsKey(userId))
pf = pfMap.get(userId);

if (pf != null && pf.getAutoForward().booleanValue() && pf.getAutoForwardEmail() != null){
if (pf != null && (pf.getAutoForward()==PrivateForumImpl.AUTO_FOWARD_YES) && pf.getAutoForwardEmail() != null){
forwardingEnabled = true;
fAddresses.add(new InternetAddress(pf.getAutoForwardEmail()));
//forwardAddress = pf.getAutoForwardEmail();
}
if (pf != null && (pf.getAutoForward()==PrivateForumImpl.AUTO_FOWARD_DEFAULT) && submitterEmailReceiptPref==PrivateForumImpl.AUTO_FOWARD_YES){
pf.setAutoForwardEmail(mailAFoward);
forwardingEnabled = true;
fAddresses.add(new InternetAddress(pf.getAutoForwardEmail()));
}
if( pf == null)
{
//only check for default settings if the pf is null
PrivateForum oldPf = forumManager.getPrivateForumByOwnerAreaNull(userId);
if (oldPf != null && oldPf.getAutoForward().booleanValue() && oldPf.getAutoForwardEmail() != null) {
if (oldPf != null && (oldPf.getAutoForward()==PrivateForumImpl.AUTO_FOWARD_YES) && oldPf.getAutoForwardEmail() != null) {
//forwardAddress = oldPf.getAutoForwardEmail();
forwardingEnabled = true;
fAddresses.add(new InternetAddress(oldPf.getAutoForwardEmail()));
}
if (oldPf != null && (oldPf.getAutoForward()==PrivateForumImpl.AUTO_FOWARD_DEFAULT) && submitterEmailReceiptPref==PrivateForumImpl.AUTO_FOWARD_YES) {
oldPf.setAutoForwardEmail(mailAFoward);
forwardingEnabled = true;
fAddresses.add(new InternetAddress(oldPf.getAutoForwardEmail()));
}

}

/** determine if current user is equal to recipient */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,29 @@
</list>
</property>
</bean>

<bean id="org.sakaiproject.messageforums.api.MsgcntrUserNotificationPreferencesRegistration"
parent="org.sakaiproject.user.api.UserNotificationPreferencesRegistration"
class="org.sakaiproject.component.app.messageforums.MsgcntrUserNotificationPreferencesRegistrationImpl"
init-method="init" scope="singleton">
<property name="bundleLocation"><value>org.sakaiproject.api.app.messagecenter.bundle.Messages</value></property>
<property name="sectionTitleBundleKey"><value>prefs_title</value></property>
<property name="sectionDescriptionBundleKey"><value>prefs_description</value></property>
<property name="overrideSectionTitleBundleKey"><value>prefs_title_override</value></property>
<property name="defaultValue"><value>1</value></property>
<property name="type"><value>sakai:messageforums</value></property>
<property name="prefix"><value>messageforums</value></property>
<!-- property name="toolId"><value>sakai.synoptic.messagecenter</value></property -->
<property name="toolId"><value>sakai.messages</value></property>
<property name="rawOptions">
<map>
<entry key="1"><value>prefs_opt1</value></entry>
<entry key="2"><value>prefs_opt2</value></entry>
</map>
</property>
<property name="overrideBySite"><value>false</value></property>
<property name="expandByDefault"><value>true</value></property>
</bean>

<bean id="org.sakaiproject.api.app.messageforums.DiscussionForumService"
class="org.sakaiproject.component.app.messageforums.DiscussionForumServiceImpl" init-method="init">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,23 @@
public class PrivateForumImpl extends BaseForumImpl implements PrivateForum {

private String owner;
private Boolean autoForward;
private Integer autoForward;
private String autoForwardEmail;
private Boolean previewPaneEnabled;


//Declaracion constantes foward
public static final int AUTO_FOWARD_NO = 0;
public static final int AUTO_FOWARD_YES = 1;
public static final int AUTO_FOWARD_DEFAULT = 2;
// indecies for hibernate
//private int areaindex;

public Boolean getAutoForward() {
public Integer getAutoForward() {
return autoForward;
}

public void setAutoForward(Boolean autoForward) {
public void setAutoForward(Integer autoForward) {
this.autoForward = autoForward;
}

Expand Down

0 comments on commit 2847ea2

Please sign in to comment.