Skip to content

Commit

Permalink
SAK-41091: Site Info > new sakai.property for more granular control o…
Browse files Browse the repository at this point in the history
…f site creation notification emails
  • Loading branch information
mhall authored and bjones86 committed Jan 8, 2019
1 parent 135feaa commit ee3efe9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3084,10 +3084,14 @@
# DEFAULT: true
# site.setup.import.addmissingtools=false

# SAK-27580: Ability to disable site creation notification that goes to the site creator
# SAK-27580: Ability to disable site creation notification that goes to the setup.request address
# DEFAULT: true
# site.setup.creation.notification = false

# SAK-41091: Ability to disable site creation notification that goes to the user who created the site
# DEFAULT: true
# site.setup.creation.notification.user = false

# SAK-29525: Open Template list by default when creating site
# DEFAULT: false
# site.setup.creation.expand.template = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ public interface UserNotificationProvider {
* @param courseSite
* @param termTitle
* @param requestEmail
* @param sendToRequestEmail if the email should be sent to requestEmail given.
* @param sendToUser if the email should be sent to the user who created the site
*/
public void notifySiteCreation(Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail);
public void notifySiteCreation(Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail, boolean sendToRequestEmail, boolean sendToUser);

/**
* send course site request information to course authorizer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public void notifyCourseRequestRequester(String requestEmail, String supportEmai
emailTemplateServiceSend(NOTIFY_COURSE_REQUEST_REQUESTER, (new ResourceLoader()).getLocale(), currentUser, from, to, headerTo, replyTo, replacementValues);
}

public void notifySiteCreation(Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail) {
public void notifySiteCreation(Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail, boolean sendToRequestEmail, boolean sendToUser) {
User currentUser = userDirectoryService.getCurrentUser();
String currentUserDisplayName = currentUser!=null?currentUser.getDisplayName():"";
String currentUserDisplayId = currentUser!=null?currentUser.getDisplayId():"";
Expand Down Expand Up @@ -348,16 +348,21 @@ public void notifySiteCreation(Site site, List notifySites, boolean courseSite,
replacementValues.put("numSections", "0");
}
replacementValues.put("sections", buf.toString());

emailTemplateServiceSend(NOTIFY_SITE_CREATION, (new ResourceLoader()).getLocale(), currentUser, from, to, headerTo, replyTo, replacementValues);

// send a confirmation email to site creator
from = requestEmail;
to = currentUserEmail;
headerTo = currentUserEmail;
replyTo = serverConfigurationService.getString("setup.request","no-reply@" + serverConfigurationService.getServerName());
emailTemplateServiceSend(NOTIFY_SITE_CREATION_CONFIRMATION, (new ResourceLoader()).getLocale(), currentUser, from, to, headerTo, replyTo, replacementValues);


if (sendToRequestEmail)
{
emailTemplateServiceSend(NOTIFY_SITE_CREATION, (new ResourceLoader()).getLocale(), currentUser, from, to, headerTo, replyTo, replacementValues);
}

if (sendToUser)
{
// send a confirmation email to site creator
from = requestEmail;
to = currentUserEmail;
headerTo = currentUserEmail;
replyTo = serverConfigurationService.getString("setup.request","no-reply@" + serverConfigurationService.getServerName());
emailTemplateServiceSend(NOTIFY_SITE_CREATION_CONFIRMATION, (new ResourceLoader()).getLocale(), currentUser, from, to, headerTo, replyTo, replacementValues);
}
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@
import java.util.List;
import java.util.Locale;
import java.util.Date;
import java.util.HashMap;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;

import org.sakaiproject.component.api.ServerConfigurationService;
import org.sakaiproject.coursemanagement.api.AcademicSession;
import org.sakaiproject.email.api.EmailService;
import org.sakaiproject.entitybroker.DeveloperHelperService;
import org.sakaiproject.site.api.Site;
import org.sakaiproject.sitemanage.api.UserNotificationProvider;
import org.sakaiproject.user.api.User;
import org.sakaiproject.user.api.UserDirectoryService;
import org.sakaiproject.user.api.UserNotDefinedException;
import org.sakaiproject.util.ResourceLoader;

@Slf4j
Expand Down Expand Up @@ -224,7 +220,7 @@ public void notifyTemplateUse(Site templateSite, User currentUser, Site site) {
/**
* {@inheritDoc}
*/
public void notifySiteCreation(Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail) {
public void notifySiteCreation(Site site, List notifySites, boolean courseSite, String termTitle, String requestEmail, boolean sendToRequestEmail, boolean sendToUser) {
// send emails
String id = site.getId();
String title = site.getTitle();
Expand Down Expand Up @@ -278,17 +274,23 @@ public void notifySiteCreation(Site site, List notifySites, boolean courseSite,
buf.append(rb.getString("java.course2") + " " + course + "\n");
}
}
emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null);

// send a confirmation email to site creator
from = requestEmail;
to = currentUserEmail;
headerTo = currentUserEmail;
replyTo = serverConfigurationService.getString("setup.request","no-reply@" + serverConfigurationService.getServerName());
String content = rb.getFormattedMessage("java.siteCreation.confirmation", new Object[]{title, serverConfigurationService.getServerName()});
content += "\n\n" + buf.toString();
emailService.send(from, to, message_subject, content, headerTo, replyTo, null);


if (sendToRequestEmail)
{
emailService.send(from, to, message_subject, buf.toString(), headerTo, replyTo, null);
}

if (sendToUser)
{
// send a confirmation email to site creator
from = requestEmail;
to = currentUserEmail;
headerTo = currentUserEmail;
replyTo = serverConfigurationService.getString("setup.request","no-reply@" + serverConfigurationService.getServerName());
String content = rb.getFormattedMessage("java.siteCreation.confirmation", new Object[]{title, serverConfigurationService.getServerName()});
content += "\n\n" + buf.toString();
emailService.send(from, to, message_subject, content, headerTo, replyTo, null);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7546,9 +7546,10 @@ private void sendSiteNotification(SessionState state, Site site, List notifySite
String requestEmail = getSetupRequestEmailAddress();
User currentUser = UserDirectoryService.getCurrentUser();
// read from configuration whether to send out site notification emails, which defaults to be true
boolean sendSiteNotificationChoice = ServerConfigurationService.getBoolean("site.setup.creation.notification", true);
if (requestEmail != null && currentUser != null && sendSiteNotificationChoice) {
userNotificationProvider.notifySiteCreation(site, notifySites, courseSite, term_name, requestEmail);
boolean sendToRequestEmail = ServerConfigurationService.getBoolean("site.setup.creation.notification", true);
boolean sendToUser = ServerConfigurationService.getBoolean("site.setup.creation.notification.user", true);
if (requestEmail != null && currentUser != null && (sendToRequestEmail || sendToUser)) {
userNotificationProvider.notifySiteCreation(site, notifySites, courseSite, term_name, requestEmail, sendToRequestEmail, sendToUser);
} // if

// reset locale to user default
Expand Down

0 comments on commit ee3efe9

Please sign in to comment.