Index: lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/EmailNotificationsAction.java =================================================================== diff -u -r2e52631e8d9ec49424ba74b3a003226e2d4302fb -ra5b0c96baff283c90d4e129a33d1cdb034ee10a8 --- lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/EmailNotificationsAction.java (.../EmailNotificationsAction.java) (revision 2e52631e8d9ec49424ba74b3a003226e2d4302fb) +++ lams_monitoring/src/java/org/lamsfoundation/lams/monitoring/web/EmailNotificationsAction.java (.../EmailNotificationsAction.java) (revision a5b0c96baff283c90d4e129a33d1cdb034ee10a8) @@ -40,6 +40,7 @@ import javax.servlet.http.HttpSession; import org.apache.commons.lang.StringEscapeUtils; +import org.apache.commons.lang.StringUtils; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; @@ -86,16 +87,6 @@ *
* * @author Andrey Balan - * - * - * - * - * - * - * - * - * - * */ public class EmailNotificationsAction extends LamsDispatchAction { @@ -121,7 +112,7 @@ public ActionForward getLessonView(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID); - if (!getSecurityService().isLessonMonitor(lessonId, getUser().getUserID(), "show lesson email notifications", + if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(), "show lesson email notifications", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); return null; @@ -149,7 +140,7 @@ public ActionForward getCourseView(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { int orgId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); - if (!getSecurityService().isGroupMonitor(orgId, getUser().getUserID(), "show course email notifications", + if (!getSecurityService().isGroupMonitor(orgId, getCurrentUser().getUserID(), "show course email notifications", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the organisation"); return null; @@ -194,13 +185,13 @@ boolean isLessonNotifications = (lessonId != null); Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); if (isLessonNotifications) { - if (!getSecurityService().isLessonMonitor(lessonId, getUser().getUserID(), + if (!getSecurityService().isLessonMonitor(lessonId, getCurrentUser().getUserID(), "show scheduled lesson email notifications", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the lesson"); return null; } } else { - if (!getSecurityService().isGroupMonitor(organisationId, getUser().getUserID(), + if (!getSecurityService().isGroupMonitor(organisationId, getCurrentUser().getUserID(), "show scheduled course course email notifications", false)) { response.sendError(HttpServletResponse.SC_FORBIDDEN, "The user is not a monitor in the organisation"); return null; @@ -257,7 +248,7 @@ String inputTriggerName = WebUtil.readStrParam(request, "triggerName"); Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); - Integer userId = getUser().getUserID(); + Integer userId = getCurrentUser().getUserID(); boolean isLessonNotifications = (lessonId != null); Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); @@ -331,7 +322,9 @@ String emailBody = WebUtil.readStrParam(request, "emailBody"); Long scheduleDateParameter = WebUtil.readLongParam(request, "scheduleDate", true); - // check if we send email instantly + String scheduleDateStr = ""; + String emailClauseStr = ""; + // check if we need to send email instantly if (scheduleDateParameter == null) { boolean isSuccessfullySent = true; String[] userIdStrs = request.getParameterValues("userId"); @@ -345,15 +338,18 @@ } JSONObject.put("isSuccessfullySent", isSuccessfullySent); + + //prepare data for audit log + scheduleDateStr = "now"; + emailClauseStr = "for users (userIds: " + StringUtils.join(userIdStrs,",") + ")"; + } else { try { Calendar now = Calendar.getInstance(); // calculate scheduleDate Date scheduleDateTeacherTimezone = new Date(scheduleDateParameter); - HttpSession ss = SessionManager.getSession(); - UserDTO teacher = (UserDTO) ss.getAttribute(AttributeNames.USER); - TimeZone teacherTimeZone = teacher.getTimeZone(); + TimeZone teacherTimeZone = getCurrentUser().getTimeZone(); Date scheduleDate = DateUtil.convertFromTimeZoneToDefault(teacherTimeZone, scheduleDateTeacherTimezone); // build job detail based on the bean class @@ -371,14 +367,31 @@ Scheduler scheduler = getScheduler(); scheduler.scheduleJob(emailScheduleMessageJob, startLessonTrigger); JSONObject.put("isSuccessfullyScheduled", true); - LamsDispatchAction.log.debug("Emails have been successfully scheduled to be sent on " + scheduleDate - + " [search type is " + request.getParameter("searchType") + "]"); + + //prepare data for audit log + scheduleDateStr = "on " + scheduleDate; + Object lessonIdObj = emailScheduleMessageJob.getJobDataMap().get(AttributeNames.PARAM_LESSON_ID); + Object lessonIDsObj = emailScheduleMessageJob.getJobDataMap().get("lessonIDs"); + Object organisationIdObj = emailScheduleMessageJob.getJobDataMap().get(AttributeNames.PARAM_ORGANISATION_ID); + if (lessonIdObj != null) { + emailClauseStr = "for lesson (lessonId: " + lessonIdObj + ")"; + } else if (lessonIDsObj != null) { + emailClauseStr = "for lessons (lessonIDs: " + StringUtils.join((String[])lessonIDsObj,",") + ")"; + } else if (organisationIdObj != null) { + emailClauseStr = "for organisation (organisationId: " + organisationIdObj + ")"; + } + } catch (SchedulerException e) { LamsDispatchAction.log.error("Error occurred at " + "[emailScheduleMessage]- fail to email scheduling", e); } } + //audit log + getAuditService().log(MonitoringConstants.MONITORING_MODULE_NAME, + "User " + getCurrentUser().getLogin() + " set a notification "+ emailClauseStr + " " + scheduleDateStr + + " with the following notice: " + emailBody); + response.setContentType("application/json;charset=utf-8"); response.getWriter().print(JSONObject); return null; @@ -389,19 +402,19 @@ */ public ActionForward getUsers(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException, JSONException { - Map map = new HashMap(); + Map