Index: lams_central/src/java/org/lamsfoundation/lams/authoring/template/web/LdTemplateController.java =================================================================== diff -u -rf32bc3c30b8ea0463d84b4dbdc112f77a400297a -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/authoring/template/web/LdTemplateController.java (.../LdTemplateController.java) (revision f32bc3c30b8ea0463d84b4dbdc112f77a400297a) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/template/web/LdTemplateController.java (.../LdTemplateController.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1384,11 +1384,11 @@ * Specialised call to create a new forum entry. Returns a fragment of HTML * which sets up two new fields - subject and body. Works with both forum.jsp. */ - @RequestMapping - public String createForum(HttpServletRequest request) { - request.setAttribute("topicNumber", request.getParameter("topicNumber")); - return mapping.findForward("forum"); - } +// @RequestMapping +// public String createForum(HttpServletRequest request) { +// request.setAttribute("topicNumber", request.getParameter("topicNumber")); +// return mapping.findForward("forum"); +// } /** * Specialised call to create a new option for a multiple choice question (mcoption.jsp), Survey question @@ -1494,29 +1494,29 @@ return optionDtos; } +// +// /** +// * Specialised call to create a new URL field & title. +// */ +// @RequestMapping("/createResource") +// public ActionForward createResource(HttpServletRequest request) { +// request.setAttribute("urlNumber", request.getParameter("urlNumber")); +// if (request.getParameter("branchNumberUnderscore") != null) { +// request.setAttribute("branchNumberUnderscore", request.getParameter("branchNumberUnderscore")); +// } +// return mapping.findForward("resource"); +// } +// +// /** +// * Specialised call to create a new set of fields for a branch. +// */ +// @RequestMapping("/createBranch") +// public String createBranch(HttpServletRequest request) { +// request.setAttribute("branchNumber", request.getParameter("branchNumber")); +// return mapping.findForward("branch"); +// } /** - * Specialised call to create a new URL field & title. - */ - @RequestMapping("/createResource") - public ActionForward createResource(HttpServletRequest request) { - request.setAttribute("urlNumber", request.getParameter("urlNumber")); - if (request.getParameter("branchNumberUnderscore") != null) { - request.setAttribute("branchNumberUnderscore", request.getParameter("branchNumberUnderscore")); - } - return mapping.findForward("resource"); - } - - /** - * Specialised call to create a new set of fields for a branch. - */ - @RequestMapping("/createBranch") - public String createBranch(HttpServletRequest request) { - request.setAttribute("branchNumber", request.getParameter("branchNumber")); - return mapping.findForward("branch"); - } - - /** * Specialised call to create a new rating criteria for the Peer Review fields. Returns a fragment of HTML * which sets up the new fields. */ Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringController.java =================================================================== diff -u -rf32bc3c30b8ea0463d84b4dbdc112f77a400297a -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringController.java (.../AuthoringController.java) (revision f32bc3c30b8ea0463d84b4dbdc112f77a400297a) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/AuthoringController.java (.../AuthoringController.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -78,7 +78,7 @@ import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; -import org.lamsfoundation.lams.workspace.web.WorkspaceAction; +import org.lamsfoundation.lams.workspace.web.WorkspaceController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Controller; @@ -215,7 +215,7 @@ learningDesignDTO.getWorkspaceFolderID()); while (folder != null) { Integer folderID = folder.getWorkspaceFolderId(); - if (folderID.equals(WorkspaceAction.ROOT_ORG_FOLDER_ID)) { + if (folderID.equals(WorkspaceController.ROOT_ORG_FOLDER_ID)) { // we reached the top folder, finish folder = null; } else { Index: lams_central/src/java/org/lamsfoundation/lams/authoring/web/LamsAuthoringFinishAction.java =================================================================== diff -u -rf32bc3c30b8ea0463d84b4dbdc112f77a400297a -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/authoring/web/LamsAuthoringFinishAction.java (.../LamsAuthoringFinishAction.java) (revision f32bc3c30b8ea0463d84b4dbdc112f77a400297a) +++ lams_central/src/java/org/lamsfoundation/lams/authoring/web/LamsAuthoringFinishAction.java (.../LamsAuthoringFinishAction.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,195 +1,195 @@ -///**************************************************************** -// * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) -// * ============================================================= -// * License Information: http://lamsfoundation.org/licensing/lams/2.0/ -// * -// * This program is free software; you can redistribute it and/or modify -// * it under the terms of the GNU General Public License version 2.0 -// * as published by the Free Software Foundation. -// * -// * This program is distributed in the hope that it will be useful, -// * but WITHOUT ANY WARRANTY; without even the implied warranty of -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// * GNU General Public License for more details. -// * -// * You should have received a copy of the GNU General Public License -// * along with this program; if not, write to the Free Software -// * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 -// * USA -// * -// * http://www.gnu.org/licenses/gpl.txt -// * **************************************************************** -// */ -// -// -//package org.lamsfoundation.lams.authoring.web; -// -//import java.io.IOException; -//import java.net.URLEncoder; -// -//import javax.servlet.ServletException; -//import javax.servlet.http.HttpServletRequest; -//import javax.servlet.http.HttpServletResponse; -//import javax.servlet.http.HttpSession; -// -//import org.apache.commons.lang.StringUtils; -//import org.apache.log4j.Logger; -//import org.apache.struts.action.Action; -//import org.apache.struts.action.ActionForm; -//import org.apache.struts.action.ActionForward; -//import org.apache.struts.action.ActionMapping; -//import org.lamsfoundation.lams.logevent.service.ILogEventService; -//import org.lamsfoundation.lams.tool.IToolVO; -//import org.lamsfoundation.lams.tool.ToolAccessMode; -//import org.lamsfoundation.lams.tool.ToolContentManager; -//import org.lamsfoundation.lams.tool.service.ILamsToolService; -//import org.lamsfoundation.lams.util.Configuration; -//import org.lamsfoundation.lams.util.ConfigurationKeys; -//import org.lamsfoundation.lams.util.WebUtil; -//import org.lamsfoundation.lams.web.util.AttributeNames; -//import org.springframework.beans.factory.NoSuchBeanDefinitionException; -//import org.springframework.web.context.WebApplicationContext; -//import org.springframework.web.context.support.WebApplicationContextUtils; -// -///** -// * This action class does some process when author try to save/cancel/close authoring tool pages. If author try to save -// * tool page, this action will redirct tool page to confirm page and execute clearSession() method. If author try to -// * cancel/close window, this action will execute clearSession(). -// * -// * @author Steve.Ni -// */ -//public abstract class LamsAuthoringFinishAction extends Action { -// private static Logger log = Logger.getLogger(LamsAuthoringFinishAction.class); -// -// private static final String ACTION_NAME = "action"; -// private static final String ACTION_MODE = "mode"; -// private static final String CUSTOMISE_SESSION_ID = "customiseSessionID"; -// private static final String TOOL_SIGNATURE = "signature"; -// -// private static final String CONFIRM_ACTION = "confirm"; -// private static final String CANCEL_ACTION = "cancel"; -// private static final String DEFINE_LATER_ACTION = "defineLater"; -// -// private static final String RE_EDIT_URL = "reEditUrl"; -// -// private static ILogEventService logEventService; -// -// /** -// * Action method, will handle save/cancel action. -// */ -// @Override -// public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, -// HttpServletResponse response) throws IOException, ServletException { -// String action = request.getParameter(ACTION_NAME); -// ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, ACTION_MODE, false); -// String cSessionID = request.getParameter(CUSTOMISE_SESSION_ID); -// String notifyCloseURL = (String) request.getSession().getAttribute(AttributeNames.PARAM_NOTIFY_CLOSE_URL); -// Long toolContentId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); -// -// // clear session according to the ToolAccessMode. -// clearSession(cSessionID, request.getSession(), mode); -// -// //CONFIRM_ACTION got fired only for general authoring and not for define later one -// if (StringUtils.equals(action, CONFIRM_ACTION)) { -// String nextUrl = getLamsUrl() + "authoringConfirm.jsp"; -// String signature = request.getParameter(TOOL_SIGNATURE); -// -// String contentFolderID = "TODO_remove-change_optional_to_false"; -// contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID, true); -// -// // check whether it use on define it later page -// IToolVO tool = getToolService().getToolBySignature(signature); -// -// //add reeditUrl parameter -// String reeditUrl = WebUtil.appendParameterToURL(getLamsUrl() + tool.getAuthorUrl(), -// AttributeNames.PARAM_TOOL_CONTENT_ID, toolContentId.toString()); -// reeditUrl = WebUtil.appendParameterToURL(reeditUrl, AttributeNames.PARAM_CONTENT_FOLDER_ID, -// contentFolderID); -// if ( notifyCloseURL != null && notifyCloseURL.length() > 0 ) -// reeditUrl = WebUtil.appendParameterToURL(reeditUrl, AttributeNames.PARAM_NOTIFY_CLOSE_URL, notifyCloseURL); -// nextUrl = WebUtil.appendParameterToURL(nextUrl, RE_EDIT_URL, URLEncoder.encode(reeditUrl, "UTF-8")); -// -// if (!StringUtils.isBlank(notifyCloseURL)) { -// nextUrl = WebUtil.appendParameterToURL(nextUrl, AttributeNames.PARAM_NOTIFY_CLOSE_URL, notifyCloseURL); -// } -// response.sendRedirect(nextUrl); -// } -// -// //audit log content has been finished being edited -// if (StringUtils.equals(action, DEFINE_LATER_ACTION)) { -// getLogEventService().logFinishEditingActivityInMonitor(toolContentId); -// } -// -// //reset defineLater task -// if (StringUtils.equals(action, CANCEL_ACTION) && mode.isTeacher()) { -// String signature = request.getParameter(TOOL_SIGNATURE); -// -// ToolContentManager contentManager = (ToolContentManager) findToolService(signature); -// contentManager.resetDefineLater(toolContentId); -// -// getLogEventService().logCancelEditingActivityInMonitor(toolContentId); -// } -// -// return null; -// } -// -// /** -// * All subclass will implements this method and execute clear HttpSession action to remove obsolete -// * session values. -// * -// * @param customiseSessionID -// * customised session ID. -// * @param session -// * @param mode -// * ToolAccessMode to decide which role's session will be clear. -// */ -// abstract public void clearSession(String customiseSessionID, HttpSession session, ToolAccessMode mode); -// -// // --------------------------------------------------------------------- -// // Helper Methods -// // --------------------------------------------------------------------- -// -// private String getLamsUrl() { -// String serverURL = Configuration.get(ConfigurationKeys.SERVER_URL); -// -// if (StringUtils.isBlank(serverURL)) { -// log.warn("ServerURLTag unable to write out server URL as it is missing from the configuration file."); -// } -// -// return serverURL; -// } -// -// public ILamsToolService getToolService() { -// WebApplicationContext webContext = WebApplicationContextUtils -// .getRequiredWebApplicationContext(this.getServlet().getServletContext()); -// return (ILamsToolService) webContext.getBean(AuthoringConstants.TOOL_SERVICE_BEAN_NAME); -// } -// -// /** -// * Get LogEventService bean -// */ -// private ILogEventService getLogEventService() { -// if (logEventService == null) { -// WebApplicationContext ctx = WebApplicationContextUtils -// .getRequiredWebApplicationContext(getServlet().getServletContext()); -// logEventService = (ILogEventService) ctx.getBean("logEventService"); -// } -// return logEventService; -// } -// -// /** -// * Find a tool's service registered inside lams. -// * -// * @param signature -// * the tool signature. -// * @return the service object from tool. -// * @throws NoSuchBeanDefinitionException -// * if the tool is not the classpath or the supplied service name is wrong. -// */ -// public Object findToolService(String signature) throws NoSuchBeanDefinitionException { -// IToolVO tool = getToolService().getToolBySignature(signature); -// WebApplicationContext webContext = WebApplicationContextUtils -// .getRequiredWebApplicationContext(this.getServlet().getServletContext()); -// return webContext.getBean(tool.getServiceName()); -// } -//} +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + + +package org.lamsfoundation.lams.authoring.web; + +import java.io.IOException; +import java.net.URLEncoder; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.logevent.service.ILogEventService; +import org.lamsfoundation.lams.tool.IToolVO; +import org.lamsfoundation.lams.tool.ToolAccessMode; +import org.lamsfoundation.lams.tool.ToolContentManager; +import org.lamsfoundation.lams.tool.service.ILamsToolService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * This action class does some process when author try to save/cancel/close authoring tool pages. If author try to save + * tool page, this action will redirct tool page to confirm page and execute clearSession() method. If author try to + * cancel/close window, this action will execute clearSession(). + * + * @author Steve.Ni + */ +public abstract class LamsAuthoringFinishAction extends Action { + private static Logger log = Logger.getLogger(LamsAuthoringFinishAction.class); + + private static final String ACTION_NAME = "action"; + private static final String ACTION_MODE = "mode"; + private static final String CUSTOMISE_SESSION_ID = "customiseSessionID"; + private static final String TOOL_SIGNATURE = "signature"; + + private static final String CONFIRM_ACTION = "confirm"; + private static final String CANCEL_ACTION = "cancel"; + private static final String DEFINE_LATER_ACTION = "defineLater"; + + private static final String RE_EDIT_URL = "reEditUrl"; + + private static ILogEventService logEventService; + + /** + * Action method, will handle save/cancel action. + */ + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException, ServletException { + String action = request.getParameter(ACTION_NAME); + ToolAccessMode mode = WebUtil.readToolAccessModeParam(request, ACTION_MODE, false); + String cSessionID = request.getParameter(CUSTOMISE_SESSION_ID); + String notifyCloseURL = (String) request.getSession().getAttribute(AttributeNames.PARAM_NOTIFY_CLOSE_URL); + Long toolContentId = new Long(WebUtil.readLongParam(request, AttributeNames.PARAM_TOOL_CONTENT_ID)); + + // clear session according to the ToolAccessMode. + clearSession(cSessionID, request.getSession(), mode); + + //CONFIRM_ACTION got fired only for general authoring and not for define later one + if (StringUtils.equals(action, CONFIRM_ACTION)) { + String nextUrl = getLamsUrl() + "authoringConfirm.jsp"; + String signature = request.getParameter(TOOL_SIGNATURE); + + String contentFolderID = "TODO_remove-change_optional_to_false"; + contentFolderID = WebUtil.readStrParam(request, AttributeNames.PARAM_CONTENT_FOLDER_ID, true); + + // check whether it use on define it later page + IToolVO tool = getToolService().getToolBySignature(signature); + + //add reeditUrl parameter + String reeditUrl = WebUtil.appendParameterToURL(getLamsUrl() + tool.getAuthorUrl(), + AttributeNames.PARAM_TOOL_CONTENT_ID, toolContentId.toString()); + reeditUrl = WebUtil.appendParameterToURL(reeditUrl, AttributeNames.PARAM_CONTENT_FOLDER_ID, + contentFolderID); + if ( notifyCloseURL != null && notifyCloseURL.length() > 0 ) + reeditUrl = WebUtil.appendParameterToURL(reeditUrl, AttributeNames.PARAM_NOTIFY_CLOSE_URL, notifyCloseURL); + nextUrl = WebUtil.appendParameterToURL(nextUrl, RE_EDIT_URL, URLEncoder.encode(reeditUrl, "UTF-8")); + + if (!StringUtils.isBlank(notifyCloseURL)) { + nextUrl = WebUtil.appendParameterToURL(nextUrl, AttributeNames.PARAM_NOTIFY_CLOSE_URL, notifyCloseURL); + } + response.sendRedirect(nextUrl); + } + + //audit log content has been finished being edited + if (StringUtils.equals(action, DEFINE_LATER_ACTION)) { + getLogEventService().logFinishEditingActivityInMonitor(toolContentId); + } + + //reset defineLater task + if (StringUtils.equals(action, CANCEL_ACTION) && mode.isTeacher()) { + String signature = request.getParameter(TOOL_SIGNATURE); + + ToolContentManager contentManager = (ToolContentManager) findToolService(signature); + contentManager.resetDefineLater(toolContentId); + + getLogEventService().logCancelEditingActivityInMonitor(toolContentId); + } + + return null; + } + + /** + * All subclass will implements this method and execute clear HttpSession action to remove obsolete + * session values. + * + * @param customiseSessionID + * customised session ID. + * @param session + * @param mode + * ToolAccessMode to decide which role's session will be clear. + */ + abstract public void clearSession(String customiseSessionID, HttpSession session, ToolAccessMode mode); + + // --------------------------------------------------------------------- + // Helper Methods + // --------------------------------------------------------------------- + + private String getLamsUrl() { + String serverURL = Configuration.get(ConfigurationKeys.SERVER_URL); + + if (StringUtils.isBlank(serverURL)) { + log.warn("ServerURLTag unable to write out server URL as it is missing from the configuration file."); + } + + return serverURL; + } + + public ILamsToolService getToolService() { + WebApplicationContext webContext = WebApplicationContextUtils + .getRequiredWebApplicationContext(this.getServlet().getServletContext()); + return (ILamsToolService) webContext.getBean(AuthoringConstants.TOOL_SERVICE_BEAN_NAME); + } + + /** + * Get LogEventService bean + */ + private ILogEventService getLogEventService() { + if (logEventService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + logEventService = (ILogEventService) ctx.getBean("logEventService"); + } + return logEventService; + } + + /** + * Find a tool's service registered inside lams. + * + * @param signature + * the tool signature. + * @return the service object from tool. + * @throws NoSuchBeanDefinitionException + * if the tool is not the classpath or the supplied service name is wrong. + */ + public Object findToolService(String signature) throws NoSuchBeanDefinitionException { + IToolVO tool = getToolService().getToolBySignature(signature); + WebApplicationContext webContext = WebApplicationContextUtils + .getRequiredWebApplicationContext(this.getServlet().getServletContext()); + return webContext.getBean(tool.getServiceName()); + } +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/DisplayGroupAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/DisplayGroupController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/DisplayGroupController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/DisplayGroupController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,320 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import javax.naming.NamingException; + +import org.lamsfoundation.lams.index.IndexLessonBean; +import org.lamsfoundation.lams.index.IndexLinkBean; +import org.lamsfoundation.lams.index.IndexOrgBean; +import org.lamsfoundation.lams.learning.kumalive.model.Kumalive; +import org.lamsfoundation.lams.learning.kumalive.service.IKumaliveService; +import org.lamsfoundation.lams.learningdesign.service.ILearningDesignService; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.service.LessonService; +import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationState; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.UserOrganisationRole; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.IndexUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author jliew + */ +@Controller +@RequestMapping("/displayGroup") +public class DisplayGroupController { + @Autowired + @Qualifier("userManagementService") + private IUserManagementService userService; + @Autowired + @Qualifier("lessonService") + private LessonService lessonService; + @Autowired + @Qualifier("learningDesignService") + private ILearningDesignService learningDesignService; + @Autowired + @Qualifier("securityService") + private ISecurityService securityService; + @Autowired + @Qualifier("kumaliveService") + private IKumaliveService kumaliveService; + + private IndexOrgBean createOrgBean(Organisation org, List roles, String username, boolean isSysAdmin) + throws SQLException, NamingException { + Integer organisationId = org.getOrganisationId(); + IndexOrgBean orgBean = new IndexOrgBean(organisationId, org.getName(), + org.getOrganisationType().getOrganisationTypeId()); + + // populate group contents + orgBean = populateContentsOrgBean(orgBean, org, roles, username, isSysAdmin); + + // First, populate header part + List links = new ArrayList<>(); + List moreLinks = new ArrayList<>(); + if (isSysAdmin) { + if (orgBean.getType().equals(OrganisationType.COURSE_TYPE)) { + moreLinks.add(new IndexLinkBean("index.classman", + "javascript:openOrgManagement(" + organisationId + ")", "fa fa-fw fa-users", null)); + } + } + + if (org.getEnableGradebookForLearners() && roles.contains(Role.ROLE_LEARNER)) { + String link = "javascript:showGradebookLearnerDialog(" + organisationId + ")"; + links.add(new IndexLinkBean("index.coursegradebook.learner", link, "fa fa-fw fa-list-ol", null)); + } + + if (roles.contains(Role.ROLE_GROUP_ADMIN) || roles.contains(Role.ROLE_GROUP_MANAGER) + || roles.contains(Role.ROLE_MONITOR)) { + if (orgBean.getType().equals(OrganisationType.COURSE_TYPE)) { + if ((!isSysAdmin) + && (roles.contains(Role.ROLE_GROUP_ADMIN) || roles.contains(Role.ROLE_GROUP_MANAGER))) { + moreLinks.add(new IndexLinkBean("index.classman", + "javascript:openOrgManagement(" + organisationId + ")", "fa fa-fw fa-ellipsis-v", null)); + } + if ((roles.contains(Role.ROLE_GROUP_ADMIN) || roles.contains(Role.ROLE_GROUP_MANAGER) + || roles.contains(Role.ROLE_AUTHOR) || roles.contains(Role.ROLE_MONITOR))) { + moreLinks.add(new IndexLinkBean("index.orggroup", + "javascript:showOrgGroupingDialog(" + organisationId + ")", "fa fa-fw fa-users", null)); + } + + if (roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_MONITOR)) { + String name = org.getEnableSingleActivityLessons() ? "index.addlesson.single" : "index.addlesson"; + links.add(new IndexLinkBean(name, "javascript:showAddLessonDialog(" + organisationId + ")", + "fa fa-fw fa-plus", null)); + } + moreLinks.add(new IndexLinkBean("index.searchlesson", + "javascript:showSearchLessonDialog(" + organisationId + ")", "fa fa-fw fa-search", + "index.searchlesson.tooltip")); + + // Adding course notifications links if enabled + if (org.getEnableCourseNotifications() + && (roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_MONITOR))) { + moreLinks.add(new IndexLinkBean("index.emailnotifications", + "javascript:showNotificationsDialog(" + organisationId + ",null)", "fa fa-fw fa-bullhorn", + "index.emailnotifications.tooltip")); + } + + // Adding lesson sorting link + if (roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_MONITOR)) { + + // make sure the group or any of its subgroups has at least one lesson + boolean hasLesson = !orgBean.getLessons().isEmpty(); + for (IndexOrgBean childOrgBean : orgBean.getChildIndexOrgBeans()) { + hasLesson |= (childOrgBean.getLessons() != null) && !childOrgBean.getLessons().isEmpty(); + } + + if (hasLesson) { + moreLinks.add(new IndexLinkBean("label.enable.lesson.sorting", "javascript:makeOrgSortable()", + "fa fa-fw fa-sort sorting tour-sorting", "label.enable.lesson.sorting")); + } + } + + // Adding gradebook course monitor links if enabled + if (roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_GROUP_ADMIN)) { + String link = "javascript:showGradebookCourseDialog(" + organisationId + ")"; + moreLinks.add(new IndexLinkBean("index.coursegradebook", link, "fa fa-fw fa-list-ol", + "index.coursegradebook.tooltip")); + } + + } else {// CLASS_TYPE + if (roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_MONITOR)) { + String name = org.getParentOrganisation().getEnableSingleActivityLessons() + ? "index.addlesson.single" + : "index.addlesson"; + links.add(new IndexLinkBean(name, "javascript:showAddLessonDialog(" + organisationId + ")", + "fa fa-fw fa-plus", null)); + } + + // Adding gradebook course monitor links if enabled + if (roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_GROUP_ADMIN)) { + String link = "javascript:showGradebookCourseDialog(" + organisationId + ")"; + moreLinks.add( + new IndexLinkBean("index.coursegradebook.subgroup", link, "fa fa-fw fa-list-ol", null)); + } + } + } + + if (Configuration.getAsBoolean(ConfigurationKeys.ALLOW_KUMALIVE) && org.getEnableKumalive() + && (roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_MONITOR) + || roles.contains(Role.ROLE_LEARNER))) { + Kumalive kumalive = kumaliveService.getKumaliveByOrganisation(organisationId); + boolean isMonitor = roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_MONITOR); + boolean disabled = !isMonitor && (kumalive == null || kumalive.getFinished()); + links.add(new IndexLinkBean(isMonitor ? "index.kumalive.teacher" : "index.kumalive", + "javascript:openKumalive(" + organisationId + ")", + "fa fa-fw fa-bolt" + (disabled ? " disabled" : ""), "index.kumalive.tooltip")); + } + + orgBean.setLinks(links); + orgBean.setMoreLinks(moreLinks); + + return orgBean; + } + + @SuppressWarnings("unchecked") + private IndexOrgBean populateContentsOrgBean(IndexOrgBean orgBean, Organisation org, List roles, + String username, boolean isSysAdmin) throws SQLException, NamingException { + // set lesson beans + Map map = populateLessonBeans(getUser(username).getUserId(), org.getOrganisationId(), + roles); + List lessonBeans = IndexUtils.sortLessonBeans(org.getOrderedLessonIds(), map); + orgBean.setLessons(lessonBeans); + + // create subgroup beans + if (orgBean.getType().equals(OrganisationType.COURSE_TYPE)) { + Set children = org.getChildOrganisations(); + + List childOrgBeans = new ArrayList<>(); + for (Organisation organisation : children) { + if (OrganisationState.ACTIVE.equals(organisation.getOrganisationState().getOrganisationStateId())) { + List classRoles = new ArrayList<>(); + List userOrganisationRoles = userService + .getUserOrganisationRoles(organisation.getOrganisationId(), username); + // don't list the subgroup if user is not a member, and not a group admin/manager + if (((userOrganisationRoles == null) || userOrganisationRoles.isEmpty()) && !isSysAdmin + && !roles.contains(Role.ROLE_GROUP_ADMIN) && !roles.contains(Role.ROLE_GROUP_MANAGER)) { + continue; + } + + for (UserOrganisationRole userOrganisationRole : userOrganisationRoles) { + classRoles.add(userOrganisationRole.getRole().getRoleId()); + } + if (roles.contains(Role.ROLE_GROUP_MANAGER)) { + classRoles.add(Role.ROLE_GROUP_MANAGER); + } + IndexOrgBean childOrgBean = createOrgBean(organisation, classRoles, username, isSysAdmin); + childOrgBeans.add(childOrgBean); + } + } + Collections.sort(childOrgBeans); + orgBean.setChildIndexOrgBeans(childOrgBeans); + } + return orgBean; + } + + // create lesson beans + private Map populateLessonBeans(Integer userId, Integer orgId, List roles) + throws SQLException, NamingException { + + // iterate through user's lessons where they are learner + Map map = lessonService.getLessonsByOrgAndUserWithCompletedFlag(userId, orgId, + Role.ROLE_LEARNER); + // remove lessons which do not have preceding lessons completed + Iterator> lessonIter = map.entrySet().iterator(); + while (lessonIter.hasNext()) { + Entry entry = lessonIter.next(); + if (entry.getValue().isDependent() && !lessonService.checkLessonReleaseConditions(entry.getKey(), userId)) { + lessonIter.remove(); + } + } + + for (IndexLessonBean bean : map.values()) { + LinkedList lessonLinks = new LinkedList<>(); + String url = null; + Integer lessonStateId = bean.getState(); + if (roles.contains(Role.ROLE_LEARNER) + && (lessonStateId.equals(Lesson.STARTED_STATE) || lessonStateId.equals(Lesson.FINISHED_STATE))) { + url = "javascript:openLearner(" + bean.getId() + ")"; + } + + if ((lessonLinks.size() > 0) || (url != null)) { + bean.setUrl(url); + bean.setLinks(lessonLinks); + } + } + + // iterate through user's lessons where they are staff (or simply through all lessons in case of Group_Manager), + // and add staff links to the beans in the map. + Integer userRole = (roles.contains(Role.ROLE_GROUP_MANAGER)) ? Role.ROLE_GROUP_MANAGER : Role.ROLE_MONITOR; + Map staffMap = lessonService.getLessonsByOrgAndUserWithCompletedFlag(userId, orgId, + userRole); + boolean isGroupManagerOrMonitor = roles.contains(Role.ROLE_GROUP_MANAGER) || roles.contains(Role.ROLE_MONITOR); + for (IndexLessonBean bean : staffMap.values()) { + if (map.containsKey(bean.getId())) { + bean = map.get(bean.getId()); + } + LinkedList lessonLinks = (LinkedList) bean.getLinks(); + if (lessonLinks == null) { + lessonLinks = new LinkedList<>(); + } + + if (isGroupManagerOrMonitor) { + lessonLinks.addFirst(new IndexLinkBean("index.monitor", + "javascript:showMonitorLessonDialog(" + bean.getId() + ")", "fa fa-fw fa-heartbeat", null)); + } + + // Adding lesson notifications links if enabled + if (isGroupManagerOrMonitor && bean.isEnableLessonNotifications()) { + lessonLinks.addFirst(new IndexLinkBean("index.emailnotifications", + "javascript:showNotificationsDialog(null," + bean.getId() + ")", "fa fa-fw fa-bullhorn", + "index.emailnotifications.tooltip")); + } + + // Add lesson conditions + if (isGroupManagerOrMonitor) { + String conditionsLink = "javascript:showConditionsDialog(" + bean.getId() + ")"; + lessonLinks.addFirst(new IndexLinkBean("index.conditions", conditionsLink, "fa fa-fw fa-code-fork", + "index.conditions.tooltip")); + } + + // Add delete lesson option + if (isGroupManagerOrMonitor) { + String removeLessonLink = "javascript:removeLesson(" + bean.getId() + ")"; + lessonLinks.addFirst(new IndexLinkBean("index.remove.lesson", removeLessonLink, "fa fa-fw fa-trash-o", + "index.remove.lesson.tooltip")); + } + + if (lessonLinks.size() > 0) { + bean.setLinks(lessonLinks); + } + map.put(bean.getId(), bean); + } + + return map; + } + + private User getUser(String login) { + return (User) userService.findByProperty(User.class, "login", login).get(0); + } +} Index: lams_central/src/java/org/lamsfoundation/lams/web/EmailForm.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/web/EmailForm.java (.../EmailForm.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/src/java/org/lamsfoundation/lams/web/EmailForm.java (.../EmailForm.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -20,11 +20,8 @@ * **************************************************************** */ - package org.lamsfoundation.lams.web; -import org.apache.struts.action.ActionForm; - /** * * Form for email composing @@ -33,7 +30,7 @@ * * */ -public class EmailForm extends ActionForm { +public class EmailForm { private static final long serialVersionUID = 7775887425863041037L; private Long userId; Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/EmailUserAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/EmailUserController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/EmailUserController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/EmailUserController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,167 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.validator.EmailValidator; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.events.IEventNotificationService; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Emailer; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.ValidationUtil; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author Andrey Balan, Marcin Cieslak + * + * + * + * + */ +@Controller +@RequestMapping("/emailUser") +public class EmailUserController { + + private static Logger log = Logger.getLogger(EmailUserController.class); + private static final EmailValidator emailValidator = EmailValidator.getInstance(); + @Autowired + @Qualifier("userManagementService") + private IUserManagementService userManagementService; + @Autowired + @Qualifier("eventNotificationService") + private IEventNotificationService eventNotificationService; + @Autowired + private MessageService messageService; + + @RequestMapping("/composeMail") + public String composeMail(HttpServletRequest request) throws Exception { + UserDTO currentUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + + if (canSend(request, currentUser)) { + Integer userId = WebUtil.readIntParam(request, AttributeNames.PARAM_USER_ID); + User user = (User) userManagementService.findById(User.class, userId); + request.setAttribute(AttributeNames.USER, user); + if (!EmailUserController.emailValidator.isValid(user.getEmail())) { + EmailUserController.log.error("Recipient " + user.getLogin() + " does not have a valid email"); + saveError(request, "error.valid.email.required", true); + } + } else { + EmailUserController.log.error("User " + currentUser.getLogin() + " is not allowed to send email"); + saveError(request, "error.authorisation", true); + } + + return "emailuser"; + } + + @ResponseBody + @RequestMapping("/send") + public void send(@ModelAttribute EmailForm emailForm, HttpServletRequest request, HttpServletResponse response) + throws Exception { + UserDTO currentUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + + if (!canSend(request, currentUser)) { + EmailUserController.log.error("User " + currentUser.getLogin() + " is not allowed to send email"); + response.setContentType("text/plain;charset=utf-8"); + response.getWriter().write(messageService.getMessage("error.authorisation")); + } + + Long userId = emailForm.getUserId(); + + String subject = emailForm.getSubject(); + String body = WebUtil.removeHTMLtags(emailForm.getBody()); + + if (EmailUserController.log.isDebugEnabled()) { + EmailUserController.log.debug("User " + currentUser.getLogin() + " (" + currentUser.getEmail() + ") " + + " sent email to user ID " + userId + ": \n[subject] " + subject + "\n[message] " + body); + } + + boolean IS_HTML_FORMAT = false; + eventNotificationService.sendMessage(currentUser.getUserID(), userId.intValue(), + IEventNotificationService.DELIVERY_METHOD_MAIL, subject, body, IS_HTML_FORMAT); + + String ccEmail = emailForm.getCcEmail(); + if (StringUtils.isNotBlank(ccEmail) && ValidationUtil.isEmailValid(ccEmail, false)) { + Emailer.sendFromSupportEmail(subject, ccEmail, body, IS_HTML_FORMAT); + + if (EmailUserController.log.isDebugEnabled()) { + EmailUserController.log.debug("User " + currentUser.getLogin() + " (" + currentUser.getEmail() + ") " + + " sent email to user ID " + userId + ": \n[subject] " + subject + "\n[message] " + body); + } + } + + } + + private void saveError(HttpServletRequest request, String error, boolean sendDisabled) { + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + errorMap.add("GLOBAL", messageService.getMessage(error)); + request.setAttribute("errorMap", errorMap); + ; + request.setAttribute("errorsPresent", true); + request.setAttribute("sendDisabled", sendDisabled); + } + + private boolean canSend(HttpServletRequest request, UserDTO currentUser) { + if (currentUser == null) { + currentUser = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + } + + boolean result = request.isUserInRole(Role.SYSADMIN) || userManagementService.isUserGlobalGroupAdmin(); + if (!result) { + String orgId = request.getParameter(AttributeNames.PARAM_ORGANISATION_ID); + if (StringUtils.isBlank(orgId)) { + String lessonId = request.getParameter(AttributeNames.PARAM_LESSON_ID); + if (!StringUtils.isBlank(lessonId)) { + Lesson lesson = (Lesson) userManagementService.findById(Lesson.class, new Long(lessonId)); + if (lesson != null) { + orgId = lesson.getOrganisation().getOrganisationId().toString(); + } + } + } + if (!StringUtils.isBlank(orgId)) { + result = userManagementService.isUserInRole(currentUser.getUserID(), new Integer(orgId), Role.MONITOR) + || userManagementService.isUserInRole(currentUser.getUserID(), new Integer(orgId), + Role.GROUP_MANAGER); + } + } + + return result; + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/FindUserLessonsAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/FindUserLessonsController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/FindUserLessonsController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/FindUserLessonsController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,137 @@ +package org.lamsfoundation.lams.web; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.dto.LessonDTO; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * + * @author asukkar + * + * + * + * + */ +@Controller +@RequestMapping("/findUserLessons") +public class FindUserLessonsController { + @Autowired + @Qualifier("userManagementService") + private IUserManagementService userManagementService; + @Autowired + @Qualifier("lessonService") + private ILessonService lessonService; + @Autowired + @Qualifier("securityServicesecurityService") + private ISecurityService securityService; + + @RequestMapping("/getResults") + public String getResults(HttpServletRequest request, HttpServletResponse response) throws Exception { + Integer courseID = WebUtil.readIntParam(request, "courseID"); + + User viewer = (User) userManagementService.findById(User.class, getUserId()); + if (!securityService.isGroupMonitor(courseID, viewer.getUserId(), "find user lessons", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the organisation"); + return null; + } + + String query = null; + List users = new LinkedList<>(); + Organisation group = (Organisation) userManagementService.findById(Organisation.class, courseID); + // if an exact user was chosen from autocomplete list, display lessons just for him + Integer userID = WebUtil.readIntParam(request, "userID", true); + if (userID != null) { + User user = (User) userManagementService.findById(User.class, userID); + users.add(user); + query = user.getFirstName() + " " + user.getLastName(); + } else { + // if a generic query was entered, look for all users who match the query + query = WebUtil.readStrParam(request, "query", true); + if (query != null) { + users = userManagementService.findUsers(query, group.getOrganisationId(), true); + } + } + + Map> userLessonsMap = new HashMap<>(); + for (User user : users) { + // get all lessons for 'user' in 'group' and add to lessons map + List lessons = lessonService.getLessonsByGroupAndUser(user.getUserId(), group.getOrganisationId()); + + List lessonDTOs = new ArrayList<>(); + for (Lesson lesson : lessons) { + LessonDTO dto = new LessonDTO(lesson); + // flag to display monitor link only if user is staff member of lesson + dto.setDisplayMonitor(lesson.getLessonClass().isStaffMember(viewer)); + lessonDTOs.add(dto); + } + + userLessonsMap.put(user, lessonDTOs); + } + + request.setAttribute("userLessonsMap", userLessonsMap); + // set attributes + request.setAttribute("courseID", courseID); + request.setAttribute("originalQuery", query); + + return "findUserLessons"; + } + + @ResponseBody + @RequestMapping("/autocomplete") + public String autocomplete(HttpServletRequest request, HttpServletResponse response) throws Exception { + Integer courseID = WebUtil.readIntParam(request, "courseID", true); + if (!securityService.isGroupMonitor(courseID, getUserId(), "autocomplete for find user lessons", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the organisation"); + return null; + } + + String query = WebUtil.readStrParam(request, "term", true); + Organisation rootOrg = (Organisation) userManagementService.findById(Organisation.class, courseID); + + List userSet = userManagementService.findUsers(query, rootOrg.getOrganisationId(), true); + ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode(); + for (User user : userSet) { + ObjectNode jsonObject = JsonNodeFactory.instance.objectNode(); + jsonObject.put("label", user.getFirstName() + " " + user.getLastName()); + jsonObject.put("value", user.getUserId()); + jsonArray.add(jsonObject); + } + + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(jsonArray); + return null; + } + + private Integer getUserId() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user != null ? user.getUserID() : null; + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/HomeAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/HomeController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/HomeController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/HomeController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,383 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Date; +import java.util.Set; +import java.util.TreeSet; +import java.util.Vector; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.io.IOUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.contentrepository.exception.RepositoryCheckedException; +import org.lamsfoundation.lams.learningdesign.GroupUser; +import org.lamsfoundation.lams.learningdesign.dao.IGroupUserDAO; +import org.lamsfoundation.lams.learningdesign.service.ILearningDesignService; +import org.lamsfoundation.lams.learningdesign.service.LearningDesignService; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.dto.LessonDTO; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.lesson.util.LessonDTOComparator; +import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.exception.UserAccessDeniedException; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.CentralConstants; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.FileUtil; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.context.WebApplicationContext; + +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * This is an action where all lams client environments launch. initial configuration of the individual environment + * setting is done here. + */ +@Controller +@RequestMapping("/home") +public class HomeController { + + private static Logger log = Logger.getLogger(HomeController.class); + + @Autowired + @Qualifier("userManagementService") + private static IUserManagementService userManagementService; + @Autowired + @Qualifier("lessonService") + private static ILessonService lessonService; + @Autowired + @Qualifier("learningDesignService") + private static ILearningDesignService learningDesignService; + @Autowired + @Qualifier("learningDesignService") + private static IGroupUserDAO groupUserDAO; + @Autowired + @Qualifier("workspaceManagementService") + private static IWorkspaceManagementService workspaceManagementService; + @Autowired + @Qualifier("securityService") + private static ISecurityService securityService; + @Autowired + WebApplicationContext applicationcontext; + + /** + * request for sysadmin environment + */ + @RequestMapping("/sysadmin") + public String sysadmin(HttpServletRequest req) throws IOException, ServletException { + + try { + HomeController.log.debug("request sysadmin"); + int orgId = new Integer(req.getParameter("orgId")).intValue(); + UserDTO user = getUser(); + if (user == null) { + HomeController.log.error("admin: User missing from session. "); + return "errorContent"; + } else if (userManagementService.isUserInRole(user.getUserID(), orgId, Role.SYSADMIN)) { + HomeController.log.debug("user is sysadmin"); + return "sysadmin"; + } else { + HomeController.log.error("User " + user.getLogin() + + " tried to get sysadmin screen but isn't sysadmin in organisation: " + orgId); + return displayMessage(req, "error.authorisation"); + } + + } catch (Exception e) { + HomeController.log.error("Failed to load sysadmin", e); + return "errorContent"; + } + } + + /** + * request for learner environment + */ + @RequestMapping("/learner") + public String learner(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + try { + Long lessonId = WebUtil.readLongParam(req, AttributeNames.PARAM_LESSON_ID); + UserDTO user = getUser(); + if (user == null) { + HomeController.log.error("learner: User missing from session. "); + return "errorContent"; + } + + if (!securityService.isLessonLearner(lessonId, user.getUserID(), "access lesson", false)) { + res.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a learner in the lesson"); + return null; + } + + String mode = WebUtil.readStrParam(req, AttributeNames.PARAM_MODE, true); + Lesson lesson = lessonId != null ? lessonService.getLesson(lessonId) : null; + if (!lesson.isLessonStarted()) { + return displayMessage(req, "message.lesson.not.started.cannot.participate"); + } + if (!lessonService.checkLessonReleaseConditions(lessonId, user.getUserID())) { + return displayMessage(req, "message.preceding.lessons.not.finished.cannot.participate"); + } + + // check if the lesson is scheduled to be finished to individual users + if (lesson.isScheduledToCloseForIndividuals()) { + GroupUser groupUser = groupUserDAO.getGroupUser(lesson, user.getUserID()); + if ((groupUser != null) && (groupUser.getScheduledLessonEndDate() != null) + && groupUser.getScheduledLessonEndDate().before(new Date())) { + HomeController.log.error("learner: User " + user.getLogin() + + " cannot access the lesson due to lesson end date has passed."); + return displayMessage(req, "error.finish.date.passed"); + } + } + + // check lesson's state if its suitable for learner's access + if (!lesson.isLessonAccessibleForLearner()) { + return displayMessage(req, "error.lesson.not.accessible.for.learners"); + } + + // show lesson intro page if required and it's not been shown already + boolean isLessonIntroWatched = WebUtil.readBooleanParam(req, "isLessonIntroWatched", false); + if (lesson.isEnableLessonIntro() && !isLessonIntroWatched) { + req.setAttribute("learnerURL", "learnerURL"); + req.setAttribute("lesson", lesson); + req.setAttribute("displayDesignImage", lesson.isDisplayDesignImage()); + + // check if we need to create learning design SVG + if (lesson.isDisplayDesignImage()) { + Long learningDesignId = lesson.getLearningDesign().getLearningDesignId(); + req.setAttribute(AttributeNames.PARAM_LEARNINGDESIGN_ID, learningDesignId); + } + return "lessonIntro"; + } + + if (mode != null) { + req.setAttribute(AttributeNames.PARAM_MODE, mode); + } + + // forward to the next (possibly first) activity. + String serverURLContextPath = Configuration.get(ConfigurationKeys.SERVER_URL_CONTEXT_PATH); + serverURLContextPath = serverURLContextPath.startsWith("/") ? serverURLContextPath + : "/" + serverURLContextPath; + serverURLContextPath += serverURLContextPath.endsWith("/") ? "" : "/"; + applicationcontext.getServletContext().getContext(serverURLContextPath + "learning") + .getRequestDispatcher("/welcome.jsp?lessonID=" + lessonId).forward(req, res); + return null; + + } catch (Exception e) { + HomeController.log.error("Failed to load learner", e); + return "errorContent"; + } + } + + /** + * request for author environment + * + * @throws IOException + */ + @RequestMapping("/author") + public String author(HttpServletRequest req, HttpServletResponse res) throws IOException { + String url = Configuration.get(ConfigurationKeys.SERVER_URL) + "authoring/author.do?method=openAuthoring"; + Long learningDesignID = WebUtil.readLongParam(req, "learningDesignID", true); + + if (learningDesignID != null) { + url += "&learningDesignID=" + learningDesignID; + } + + res.sendRedirect(url); + return null; + } + + /** + * Request for Monitor environment. + */ + @RequestMapping("/monitorLesson") + public String monitorLesson(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { + Long lessonId = WebUtil.readLongParam(req, AttributeNames.PARAM_LESSON_ID); + UserDTO user = getUser(); + if (user == null) { + HomeController.log.error("User missing from session. Can not open Lesson Monitor."); + return "errorContent"; + } + + Lesson lesson = lessonId == null ? null : lessonService.getLesson(lessonId); + if (lesson == null) { + HomeController.log.error("Lesson " + lessonId + " does not exist. Can not open Lesson Monitor."); + return "errorContent"; + } + + // security check will be done there + String url = Configuration.get(ConfigurationKeys.SERVER_URL) + + "monitoring/monitoring.do?method=monitorLesson&lessonID=" + lessonId; + res.sendRedirect(url); + return null; + } + + @RequestMapping("/addLesson") + @SuppressWarnings("unchecked") + public String addLesson(HttpServletRequest req, HttpServletResponse res) + throws IOException, UserAccessDeniedException, RepositoryCheckedException { + Integer organisationID = new Integer(WebUtil.readIntParam(req, "organisationID")); + UserDTO userDTO = getUser(); + if (!securityService.isGroupMonitor(organisationID, userDTO.getUserID(), "add lesson", false)) { + res.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the organisation"); + return null; + } + + // get all user accessible folders and LD descriptions as JSON + String folderContentsJSON = workspaceManagementService.getFolderContentsJSON(null, userDTO.getUserID(), false); + req.setAttribute("folderContents", folderContentsJSON); + ObjectNode users = JsonNodeFactory.instance.objectNode(); + + // get learners available for newly created lesson + Vector learners = userManagementService.getUsersFromOrganisationByRole(organisationID, "LEARNER", true); + for (User user : learners) { + ObjectNode userJSON = JsonNodeFactory.instance.objectNode(); + userJSON.put("userID", user.getUserId()); + userJSON.put("firstName", user.getFirstName()); + userJSON.put("lastName", user.getLastName()); + userJSON.put("login", user.getLogin()); + + users.withArray("selectedLearners").add(userJSON); + } + + Vector monitors = userManagementService.getUsersFromOrganisationByRole(organisationID, "MONITOR", true); + for (User user : monitors) { + ObjectNode userJSON = JsonNodeFactory.instance.objectNode(); + userJSON.put("userID", user.getUserId()); + userJSON.put("firstName", user.getFirstName()); + userJSON.put("lastName", user.getLastName()); + userJSON.put("login", user.getLogin()); + + if (userDTO.getUserID().equals(user.getUserId())) { + // creator is always selected + users.withArray("selectedMonitors").add(userJSON); + } else { + users.withArray("unselectedMonitors").add(userJSON); + } + } + + req.setAttribute("users", users.toString()); + + // find lessons which can be set as preceding ones for newly created lesson + Organisation organisation = (Organisation) userManagementService.findById(Organisation.class, organisationID); + Set availableLessons = new TreeSet<>(new LessonDTOComparator()); + for (Lesson availableLesson : (Set) organisation.getLessons()) { + Integer availableLessonState = availableLesson.getLessonStateId(); + if (!Lesson.REMOVED_STATE.equals(availableLessonState) + && !Lesson.FINISHED_STATE.equals(availableLessonState)) { + availableLessons.add(new LessonDTO(availableLesson)); + } + } + req.setAttribute("availablePrecedingLessons", availableLessons); + + return "addLesson"; + } + + /** + * Gets subfolder contents in Add Lesson screen. + */ + @ResponseBody + @RequestMapping("/getFolderContents") + public void getFolderContents(HttpServletRequest req, HttpServletResponse res) + throws UserAccessDeniedException, IOException, RepositoryCheckedException { + Integer folderID = WebUtil.readIntParam(req, "folderID", true); + boolean allowInvalidDesigns = WebUtil.readBooleanParam(req, "allowInvalidDesigns", false); + String folderContentsJSON = workspaceManagementService.getFolderContentsJSON(folderID, getUser().getUserID(), + allowInvalidDesigns); + + res.setContentType("application/json;charset=UTF-8"); + res.getWriter().print(folderContentsJSON); + } + + @ResponseBody + @RequestMapping("/getLearningDesignThumbnail") + public void getLearningDesignThumbnail(HttpServletRequest req, HttpServletResponse res) throws IOException { + Long learningDesignId = WebUtil.readLongParam(req, CentralConstants.PARAM_LEARNING_DESIGN_ID); + String imagePath = LearningDesignService.getLearningDesignSVGPath(learningDesignId); + File imageFile = new File(imagePath); + if (!imageFile.canRead()) { + res.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + boolean download = WebUtil.readBooleanParam(req, "download", false); + // should the image be downloaded or a part of page? + if (download) { + String name = learningDesignService.getLearningDesignDTO(learningDesignId, getUser().getLocaleLanguage()) + .getTitle(); + name += "." + "svg"; + name = FileUtil.encodeFilenameForDownload(req, name); + res.setContentType("application/x-download"); + res.setHeader("Content-Disposition", "attachment;filename=" + name); + } else { + res.setContentType("image/svg+xml"); + } + + FileInputStream input = new FileInputStream(imagePath); + OutputStream output = res.getOutputStream(); + IOUtils.copy(input, output); + IOUtils.closeQuietly(input); + IOUtils.closeQuietly(output); + + } + + @RequestMapping("/logout") + public String logout(HttpServletRequest req) throws IOException, ServletException { + + req.getSession().invalidate(); + return "index"; + } + + private String displayMessage(HttpServletRequest req, String messageKey) { + req.setAttribute("messageKey", messageKey); + return "msgContent"; + } + + private UserDTO getUser() { + HttpSession ss = SessionManager.getSession(); + return (UserDTO) ss.getAttribute(AttributeNames.USER); + } + + private User getRealUser(UserDTO dto) { + return userManagementService.getUserByLogin(dto.getLogin()); + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/IndexController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/IndexController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,297 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +package org.lamsfoundation.lams.web; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.index.IndexLinkBean; +import org.lamsfoundation.lams.integration.service.IIntegrationService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.OrganisationDTO; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.util.HtmlUtils; + +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * + * @author Fei Yang + */ +@Controller +@RequestMapping("/index") +public class IndexController { + + private static final String PATH_PEDAGOGICAL_PLANNER = "pedagogical_planner"; + private static final String PATH_LAMS_CENTRAL = "lams-central.war"; + + private static Logger log = Logger.getLogger(IndexController.class); + @Autowired + @Qualifier("userManagementService") + private static IUserManagementService userManagementService; + @Autowired + @Qualifier("integrationService") + private static IIntegrationService integrationService; + + @RequestMapping("") + @SuppressWarnings("unchecked") + public String unspecified(HttpServletRequest request, HttpServletResponse response) throws Exception { + + IndexController.setHeaderLinks(request); + setAdminLinks(request); + + // check if this is user's first login; some action (like displaying a dialog for disabling tutorials) can be + // taken based on that parameter; immediatelly, the value in DB is updated + HttpSession ss = SessionManager.getSession(); + UserDTO userDTO = (UserDTO) ss.getAttribute(AttributeNames.USER); + if (userDTO.isFirstLogin()) { + request.setAttribute("firstLogin", true); + User user = userManagementService.getUserByLogin(userDTO.getLogin()); + user.setFirstLogin(false); + userManagementService.saveUser(user); + userDTO.setFirstLogin(false); + } + + // check if user is flagged as needing to change their password + User loggedInUser = userManagementService.getUserByLogin(request.getRemoteUser()); + if (loggedInUser.getChangePassword() != null && loggedInUser.getChangePassword()) { + return "redirect:/password.do"; + } + + // check if user needs to get his shared two-factor authorization secret + if (loggedInUser.isTwoFactorAuthenticationEnabled() + && loggedInUser.getTwoFactorAuthenticationSecret() == null) { + return "redirect:/twoFactorAuthentication.do"; + } + + User user = userManagementService.getUserByLogin(userDTO.getLogin()); + request.setAttribute("portraitUuid", user.getPortraitUuid()); + + String method = WebUtil.readStrParam(request, "method", true); + if (StringUtils.equals(method, "profile")) { + return "redirect:/profile/view.do"; + } else if (StringUtils.equals(method, "editprofile")) { + return "redirect:/profile/edit.do"; + } else if (StringUtils.equals(method, "password")) { + return "redirect:/password.do"; + } else if (StringUtils.equals(method, "portrait")) { + return "/portrait.do"; + } else if (StringUtils.equals(method, "lessons")) { + return "/profile/lessons.do"; + } + + // This test also appears in LoginAsAction + Boolean allowDirectAccessIntegrationLearner = Configuration + .getAsBoolean(ConfigurationKeys.ALLOW_DIRECT_ACCESS_FOR_INTEGRATION_LEARNERS); + if (!allowDirectAccessIntegrationLearner) { + boolean isIntegrationUser = integrationService.isIntegrationUser(userDTO.getUserID()); + //prevent integration users with mere learner rights from accessing index.do + if (isIntegrationUser && !request.isUserInRole(Role.AUTHOR) && !request.isUserInRole(Role.MONITOR) + && !request.isUserInRole(Role.GROUP_MANAGER) && !request.isUserInRole(Role.GROUP_ADMIN) + && !request.isUserInRole(Role.SYSADMIN)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, + "Integration users with learner right are not allowed to access this page"); + return null; + } + } + + // only show the growl warning the first time after a user has logged in & if turned on in configuration + Boolean tzWarning = Configuration.getAsBoolean(ConfigurationKeys.SHOW_TIMEZONE_WARNING); + request.setAttribute("showTimezoneWarning", tzWarning); + request.setAttribute("showTimezoneWarningPopup", false); + if (tzWarning) { + Boolean ssWarningShown = (Boolean) ss.getAttribute("timezoneWarningShown"); + if (!Boolean.TRUE.equals(ssWarningShown)) { + ss.setAttribute("timezoneWarningShown", Boolean.TRUE); + request.setAttribute("showTimezoneWarningPopup", true); + } + } + + List favoriteOrganisations = userManagementService + .getFavoriteOrganisationsByUser(userDTO.getUserID()); + request.setAttribute("favoriteOrganisations", favoriteOrganisations); + request.setAttribute("activeOrgId", user.getLastVisitedOrganisationId()); + + boolean isSysadmin = request.isUserInRole(Role.SYSADMIN); + int userCoursesCount = userManagementService.getCountActiveCoursesByUser(userDTO.getUserID(), isSysadmin, null); + request.setAttribute("isCourseSearchOn", userCoursesCount > 10); + + return "main"; + } + + private static void setHeaderLinks(HttpServletRequest request) { + List headerLinks = new ArrayList<>(); + if (request.isUserInRole(Role.AUTHOR)) { + if (IndexController.isPedagogicalPlannerAvailable()) { + headerLinks.add(new IndexLinkBean("index.planner", "javascript:openPedagogicalPlanner()")); + } + headerLinks.add(new IndexLinkBean("index.author", "javascript:showAuthoringDialog()")); + } + + String customTabText = Configuration.get(ConfigurationKeys.CUSTOM_TAB_TITLE); + String customTabLink = Configuration.get(ConfigurationKeys.CUSTOM_TAB_LINK); + if (customTabLink != null && customTabLink.trim().length() > 0) { + headerLinks.add(new IndexLinkBean(customTabText, "javascript:openCustom(\"" + customTabLink + "\")")); + } + + request.setAttribute("headerLinks", headerLinks); + } + + private void setAdminLinks(HttpServletRequest request) { + List adminLinks = new ArrayList<>(); + if (request.isUserInRole(Role.SYSADMIN) || request.isUserInRole(Role.GROUP_ADMIN) + || request.isUserInRole(Role.GROUP_MANAGER)) { + adminLinks.add(new IndexLinkBean("index.courseman", "javascript:openOrgManagement(" + + userManagementService.getRootOrganisation().getOrganisationId() + ')')); + } + if (request.isUserInRole(Role.SYSADMIN) || userManagementService.isUserGlobalGroupAdmin()) { + adminLinks.add(new IndexLinkBean("index.sysadmin", "javascript:openSysadmin()")); + } + request.setAttribute("adminLinks", adminLinks); + } + + /** + * Returns list of organisations for user. Used by offcanvas tablesorter on main.jsp. + */ + @ResponseBody + @RequestMapping("/getOrgs") + public void getOrgs(HttpServletRequest request, HttpServletResponse res) throws IOException, ServletException { + User loggedInUser = userManagementService.getUserByLogin(request.getRemoteUser()); + + Integer userId = loggedInUser.getUserId(); + boolean isSysadmin = request.isUserInRole(Role.SYSADMIN); + String searchString = WebUtil.readStrParam(request, "fcol[1]", true); + + // paging parameters of tablesorter + int size = WebUtil.readIntParam(request, "size"); + int page = WebUtil.readIntParam(request, "page"); +// Integer isSort1 = WebUtil.readIntParam(request, "column[0]", true); +// Integer isSort2 = WebUtil.readIntParam(request, "column[1]", true); +// Integer isSort3 = WebUtil.readIntParam(request, "column[2]", true); +// Integer isSort4 = WebUtil.readIntParam(request, "column[3]", true); +// +// String sortBy = ""; +// String sortOrder = ""; +// if (isSort2 != null) { +// sortBy = "name"; +// sortOrder = isSort2.equals(0) ? "ASC" : "DESC"; +// +// } + + List orgDtos = userManagementService.getActiveCoursesByUser(userId, isSysadmin, page, size, + searchString); + + ObjectNode responcedata = JsonNodeFactory.instance.objectNode(); + responcedata.put("total_rows", + userManagementService.getCountActiveCoursesByUser(userId, isSysadmin, searchString)); + + ArrayNode rows = JsonNodeFactory.instance.arrayNode(); + for (OrganisationDTO orgDto : orgDtos) { + ObjectNode responseRow = JsonNodeFactory.instance.objectNode(); + responseRow.put("id", orgDto.getOrganisationID()); + String orgName = orgDto.getName() == null ? "" : orgDto.getName(); + responseRow.put("name", HtmlUtils.htmlEscape(orgName)); + + rows.add(responseRow); + } + responcedata.set("rows", rows); + res.setContentType("application/json;charset=utf-8"); + res.getWriter().print(new String(responcedata.toString())); + } + + /** + * Toggles whether organisation is marked as favorite. + */ + @RequestMapping("/toggleFavoriteOrganisation") + public String toggleFavoriteOrganisation(HttpServletRequest request) throws IOException, ServletException { + Integer orgId = WebUtil.readIntParam(request, "orgId", false); + Integer userId = getUserId(); + + if (orgId != null) { + userManagementService.toggleOrganisationFavorite(orgId, userId); + } + + List favoriteOrganisations = userManagementService.getFavoriteOrganisationsByUser(userId); + request.setAttribute("favoriteOrganisations", favoriteOrganisations); + + String activeOrgId = request.getParameter("activeOrgId"); + request.setAttribute("activeOrgId", activeOrgId); + + return "favoriteOrganisations"; + } + + /** + * Saves to DB last visited organisation. It's required for displaying some org on main.jsp next time user logs in. + */ + @ResponseBody + @RequestMapping("/storeLastVisitedOrganisation") + public void storeLastVisitedOrganisation(HttpServletRequest request) throws IOException, ServletException { + Integer lastVisitedOrganisationId = WebUtil.readIntParam(request, "orgId", false); + + //saves to DB last visited organisation + if (lastVisitedOrganisationId != null) { + User user = userManagementService.getUserByLogin(request.getRemoteUser()); + user.setLastVisitedOrganisationId(lastVisitedOrganisationId); + userManagementService.saveUser(user); + } + + } + + private Integer getUserId() { + HttpSession ss = SessionManager.getSession(); + UserDTO learner = (UserDTO) ss.getAttribute(AttributeNames.USER); + return learner != null ? learner.getUserID() : null; + } + + private static boolean isPedagogicalPlannerAvailable() { + String lamsEarPath = Configuration.get(ConfigurationKeys.LAMS_EAR_DIR); + String plannerPath = lamsEarPath + File.separator + PATH_LAMS_CENTRAL + File.separator + + PATH_PEDAGOGICAL_PLANNER; + File plannerDir = new File(plannerPath); + return plannerDir.isDirectory(); + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/LessonConditionsController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,318 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.io.IOException; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.index.IndexLessonBean; +import org.lamsfoundation.lams.learningdesign.Group; +import org.lamsfoundation.lams.learningdesign.GroupUser; +import org.lamsfoundation.lams.learningdesign.dao.IGroupUserDAO; +import org.lamsfoundation.lams.lesson.LearnerProgress; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.lesson.util.LessonComparator; +import org.lamsfoundation.lams.monitoring.service.IMonitoringService; +import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.CentralConstants; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * This Action takes care of operations on lesson conditional release based on preceding lesson completion. + * + * @author Marcin Cieslak + * + * + * + */ +@Controller +@RequestMapping("/lessonConditions") +public class LessonConditionsController { + private static final Logger logger = Logger.getLogger(LessonConditionsController.class); + + private static final String FORWARD_INDEX_LESSON_CONDITION = "indexLessonConditions"; + + private static final String PARAM_PRECEDING_LESSONS = "precedingLessons"; + private static final String PARAM_PRECEDING_LESSON_ID = "precedingLessonId"; + private static final String PARAM_AVAILABLE_LESSONS = "availableLessons"; + private static final String PARAM_LESSON_START_DATE = "lessonStartDate"; + private static final String PARAM_LESSON_DAYS_TO_FINISH = "lessonDaysToFinish"; + private static final String PARAM_INDIVIDUAL_FINISH = "lessonIndividualFinish"; + + @Autowired + @Qualifier("lessonService") + private ILessonService lessonService; + @Autowired + @Qualifier("monitoringService") + private IMonitoringService monitoringService; + @Autowired + @Qualifier("groupUserDAO") + private IGroupUserDAO groupUserDAO; + @Autowired + @Qualifier("securityService") + private ISecurityService securityService; + @Autowired + private MessageService messageservice; + + /** + * Prepares data for thickbox displayed on Index page. + * + * @throws IOException + * + * @throws InvalidParameterException + */ + @RequestMapping("/getIndexLessonConditions") + @SuppressWarnings("unchecked") + public String getIndexLessonConditions(HttpServletRequest request, HttpServletResponse response) + throws IOException { + Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); + if (!securityService.isLessonMonitor(lessonId, getUser().getUserID(), "show lesson conditions", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a monitor in the lesson"); + return null; + } + + Lesson lesson = lessonService.getLesson(lessonId); + List precedingLessons = new ArrayList<>(lesson.getPrecedingLessons().size()); + for (Lesson precedingLesson : lesson.getPrecedingLessons()) { + IndexLessonBean precedingLessonBean = new IndexLessonBean(precedingLesson.getLessonId(), + precedingLesson.getLessonName()); + precedingLessons.add(precedingLessonBean); + } + request.setAttribute(CentralConstants.PARAM_LESSON_ID, lesson.getLessonId()); + request.setAttribute(CentralConstants.PARAM_TITLE, lesson.getLessonName()); + request.setAttribute(LessonConditionsController.PARAM_PRECEDING_LESSONS, precedingLessons); + + Set organisationLessons = new TreeSet<>(new LessonComparator()); + organisationLessons.addAll(lesson.getOrganisation().getLessons()); + List availableLessons = new ArrayList<>(organisationLessons.size()); + for (Lesson organisationLesson : organisationLessons) { + if (!lessonId.equals(organisationLesson.getLessonId()) + && !lesson.getPrecedingLessons().contains(organisationLesson) + && !Lesson.REMOVED_STATE.equals(organisationLesson.getLessonStateId()) + && !Lesson.FINISHED_STATE.equals(organisationLesson.getLessonStateId())) { + IndexLessonBean availableLessonBean = new IndexLessonBean(organisationLesson.getLessonId(), + organisationLesson.getLessonName()); + availableLessons.add(availableLessonBean); + } + } + request.setAttribute(LessonConditionsController.PARAM_AVAILABLE_LESSONS, availableLessons); + + Date endDate = lesson.getScheduleEndDate(); + if (endDate == null) { + Integer daysToLessonFinish = lesson.getScheduledNumberDaysToLessonFinish(); + if (daysToLessonFinish != null) { + request.setAttribute(LessonConditionsController.PARAM_LESSON_DAYS_TO_FINISH, daysToLessonFinish); + request.setAttribute(LessonConditionsController.PARAM_INDIVIDUAL_FINISH, true); + } + } else { + Date startDate = (lesson.getStartDateTime() == null) ? lesson.getScheduleStartDate() + : lesson.getStartDateTime(); + long daysToLessonFinish = Duration.between(startDate.toInstant(), endDate.toInstant()).toDays(); + + request.setAttribute(LessonConditionsController.PARAM_LESSON_START_DATE, startDate); + request.setAttribute(LessonConditionsController.PARAM_LESSON_DAYS_TO_FINISH, daysToLessonFinish); + request.setAttribute(LessonConditionsController.PARAM_INDIVIDUAL_FINISH, false); + } + + request.setAttribute(CentralConstants.PARAM_EDIT, lesson.getUser().getUserId().equals(getUser().getUserID())); + + return "indexLessonConditions"; + } + + /** + * Removes given lesson from dependecies and displays updated list in thickbox. + * + * @throws IOException + * + * @throws InvalidParameterException + */ + @RequestMapping("/removeLessonDependency") + public String removeLessonDependency(HttpServletRequest request, HttpServletResponse response) throws IOException { + Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); + if (!securityService.isLessonOwner(lessonId, getUser().getUserID(), "remove lesson dependency", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not the owner of the lesson"); + return null; + } + + Long removedPrecedingLessonId = WebUtil.readLongParam(request, + LessonConditionsController.PARAM_PRECEDING_LESSON_ID, false); + + Lesson lesson = lessonService.getLesson(lessonId); + Iterator precedingLessonIter = lesson.getPrecedingLessons().iterator(); + while (precedingLessonIter.hasNext()) { + if (precedingLessonIter.next().getLessonId().equals(removedPrecedingLessonId)) { + precedingLessonIter.remove(); + break; + } + } + + // after operation, display contents again + return getIndexLessonConditions(request, response); + } + + /** + * Adds given lesson to dependecies and displays updated list in thickbox. + * + * @throws IOException + * + * @throws InvalidParameterException + */ + @RequestMapping("/addLessonDependency") + public String addLessonDependency(HttpServletRequest request, HttpServletResponse response) throws IOException { + Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); + if (!securityService.isLessonOwner(lessonId, getUser().getUserID(), "add lesson dependency", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not the owner of the lesson"); + return null; + } + + Long addedPrecedingLessonId = WebUtil.readLongParam(request, + LessonConditionsController.PARAM_PRECEDING_LESSON_ID, false); + Lesson lesson = lessonService.getLesson(lessonId); + Lesson addedPrecedingLesson = lessonService.getLesson(addedPrecedingLessonId); + if (addedPrecedingLesson == null) { + throw new IllegalArgumentException("Preceding lesson with ID: " + lessonId + " does not exist."); + } + + lesson.getPrecedingLessons().add(addedPrecedingLesson); + + // after operation, display contents again + return getIndexLessonConditions(request, response); + } + + /** + * Sets lesson finish date, either for individuals or lesson as a whole. If days<=0, schedule is removed. + * + * @throws IOException + */ + @RequestMapping("/setDaysToLessonFinish") + public String setDaysToLessonFinish(HttpServletRequest request, HttpServletResponse response) throws IOException { + Long lessonId = WebUtil.readLongParam(request, CentralConstants.PARAM_LESSON_ID, false); + if (!securityService.isLessonOwner(lessonId, getUser().getUserID(), "set days to lesson finish", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not the owner of the lesson"); + return null; + } + + int daysToLessonFinish = WebUtil.readIntParam(request, LessonConditionsController.PARAM_LESSON_DAYS_TO_FINISH, + false); + boolean individualFinish = WebUtil.readBooleanParam(request, LessonConditionsController.PARAM_INDIVIDUAL_FINISH, + false); + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + + Lesson lesson = lessonService.getLesson(lessonId); + HttpSession session = SessionManager.getSession(); + UserDTO currentUser = (UserDTO) session.getAttribute(AttributeNames.USER); + try { + // (re)schedule the lesson or remove it when set for individual finish of daysToLessonFinish=0 + monitoringService.finishLessonOnSchedule(lessonId, individualFinish ? 0 : daysToLessonFinish, + currentUser.getUserID()); + // if finish date is individual, the field below is filled + lesson.setScheduledNumberDaysToLessonFinish( + individualFinish && (daysToLessonFinish > 0) ? daysToLessonFinish : null); + + // iterate through each GroupLearner and set/remove individual lesson finish date, if needed + Group learnerGroup = lesson.getLessonClass().getLearnersGroup(); + if (learnerGroup != null) { + for (User learner : learnerGroup.getUsers()) { + GroupUser groupUser = groupUserDAO.getGroupUser(lesson, learner.getUserId()); + if (groupUser != null) { + + if (individualFinish && (daysToLessonFinish > 0)) { + // set individual finish date based on start date + LearnerProgress learnerProgress = lessonService + .getUserProgressForLesson(learner.getUserId(), lessonId); + if ((learnerProgress == null) || (learnerProgress.getStartDate() == null)) { + if (groupUser.getScheduledLessonEndDate() != null) { + LessonConditionsController.logger.warn("Improper DB value: User with ID " + + learner.getUserId() + + " has scheduledLessonEndDate set but has not started the lesson yet."); + } + } else { + // set new finish date according to moment when user joined the lesson + Calendar calendar = Calendar.getInstance(); + calendar.setTime(learnerProgress.getStartDate()); + calendar.add(Calendar.DATE, daysToLessonFinish); + Date endDate = calendar.getTime(); + groupUser.setScheduledLessonEndDate(endDate); + + if (LessonConditionsController.logger.isDebugEnabled()) { + LessonConditionsController.logger + .debug("Reset time limit for user: " + learner.getLogin() + " in lesson: " + + lesson.getLessonId() + " to " + endDate); + } + } + } else if (groupUser.getScheduledLessonEndDate() != null) { + // remove individual finish date + groupUser.setScheduledLessonEndDate(null); + + if (LessonConditionsController.logger.isDebugEnabled()) { + LessonConditionsController.logger.debug("Remove time limit for user: " + + learner.getLogin() + " in lesson: " + lesson.getLessonId()); + } + } + } + } + } + } catch (Exception e) { + LessonConditionsController.logger.error(e); + errorMap.add("GLOBAL", + messageservice.getMessage("error.conditions.box.finish.date", new Object[] { e.getMessage() })); + } + + if (!errorMap.isEmpty()) { + request.setAttribute("errorMap", errorMap); + ; + } + + // after operation, display contents again + return getIndexLessonConditions(request, response); + } + + private UserDTO getUser() { + HttpSession ss = SessionManager.getSession(); + return (UserDTO) ss.getAttribute(AttributeNames.USER); + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/LoginAsAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/LoginAsController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/LoginAsController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/LoginAsController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,134 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.util.Map; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.integration.security.RandomPasswordGenerator; +import org.lamsfoundation.lams.integration.service.IntegrationService; +import org.lamsfoundation.lams.logevent.LogEvent; +import org.lamsfoundation.lams.logevent.service.ILogEventService; +import org.lamsfoundation.lams.security.UniversalLoginModule; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * @author jliew + * + * + * + */ +@Controller +public class LoginAsController { + + @Autowired + WebApplicationContext applicationContext; + + @RequestMapping("/loginas") + public String execute(HttpServletRequest request) throws Exception { + + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + IUserManagementService service = (IUserManagementService) ctx.getBean("userManagementService"); + MessageService messageService = (MessageService) ctx.getBean("centralMessageService"); + IntegrationService integrationService = (IntegrationService) ctx.getBean("integrationService"); + + String login = WebUtil.readStrParam(request, "login", false); + + if (service.isUserSysAdmin()) { + if ((login != null) && (login.trim().length() > 0)) { + User user = service.getUserByLogin(login); + if (user != null) { + + // If the user is an integration learner and ALLOW_DIRECT_ACCESS_FOR_INTEGRATION_LEARNERS if off do not let syadmin log in + // as they will not be able to access the index page. This test should be the same test as found in IndexAction. + Boolean allowDirectAccessIntegrationLearner = Configuration + .getAsBoolean(ConfigurationKeys.ALLOW_DIRECT_ACCESS_FOR_INTEGRATION_LEARNERS); + if (!allowDirectAccessIntegrationLearner) { + boolean isIntegrationUser = integrationService.isIntegrationUser(user.getUserId()); + if (isIntegrationUser && isOnlyLearner(service, user.getUserId())) { + request.setAttribute("errorName", "Login As"); + request.setAttribute("errorMessage", + messageService.getMessage("error.cannot.login.as.with.not.allow.direct.access")); + return "errorpages/errorWithMessage"; + } + } + + // audit log when loginas + UserDTO sysadmin = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + ILogEventService logEventService = (ILogEventService) ctx.getBean("logEventService"); + String[] args = new String[] { sysadmin.getLogin() + " (" + sysadmin.getUserID() + ")", login }; + String message = messageService.getMessage("audit.admin.loginas", args); + logEventService.logEvent(LogEvent.TYPE_LOGIN_AS, sysadmin.getUserID(), user.getUserId(), null, null, + message); + + // login.jsp knows what to do with these + request.setAttribute("login", login); + String token = "#LAMS" + RandomPasswordGenerator.nextPassword(10); + request.setAttribute("password", token); + // notify the login module that the user has been authenticated correctly + UniversalLoginModule.setAuthenticationToken(token); + // redirect to login page + return "login.jsp?redirectURL=/lams/index"; + } + } + } else { + request.setAttribute("errorName", "Login As"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "errorpages/errorWithMessage"; + } + + return "redirect:/admin/usersearch.do"; + } + + private boolean isOnlyLearner(IUserManagementService service, Integer userId) { + Map> orgRoleSets = service.getRolesForUser(userId); + for (Set orgRoleSet : orgRoleSets.values()) { + for (Integer role : orgRoleSet) { + if (role.equals(Role.ROLE_AUTHOR) || role.equals(Role.ROLE_MONITOR) + || role.equals(Role.ROLE_GROUP_MANAGER) || role.equals(Role.ROLE_GROUP_ADMIN) + || role.equals(Role.ROLE_SYSADMIN)) { + return false; + } + } + } + return true; + } + +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/NotificationAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/NotificationController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/NotificationController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/NotificationController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,106 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.lamsfoundation.lams.events.Event; +import org.lamsfoundation.lams.events.IEventNotificationService; +import org.lamsfoundation.lams.events.Subscription; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Processes notification sent from Tools to users. + * + * + */ +@Controller +@RequestMapping("//notification") +public class NotificationController { + + @Autowired + @Qualifier("eventNotificationService") + private IEventNotificationService eventNotificationService; + + @ResponseBody + @RequestMapping("/getNotificationSubscriptions") + public void getNotificationSubscriptions(HttpServletRequest req, HttpServletResponse res) throws IOException { + Integer limit = WebUtil.readIntParam(req, "limit", true); + Integer offset = WebUtil.readIntParam(req, "offset", true); + List subscriptions = eventNotificationService.getNotificationSubscriptions(null, + getUser().getUserID(), false, limit, offset); + ArrayNode responseJSON = JsonNodeFactory.instance.arrayNode(); + for (Subscription subscription : subscriptions) { + Event event = subscription.getEvent(); + ObjectNode subscriptionJSON = JsonNodeFactory.instance.objectNode(); + subscriptionJSON.put("subscriptionUid", subscription.getUid()); + subscriptionJSON.put("message", event.getMessage()); + subscriptionJSON.put("pending", subscription.getLastOperationMessage() == null); + responseJSON.add(subscriptionJSON); + } + + if (responseJSON.size() > 0) { + res.setContentType("application/json;charset=UTF-8"); + res.getWriter().print(responseJSON.toString()); + } + } + + @ResponseBody + @RequestMapping("/markNotificationAsRead") + public void markNotificationAsRead(HttpServletRequest req) { + long subscriptionUid = WebUtil.readLongParam(req, "subscriptionUid"); + // trigger means send, i.e. mark as "seen" + eventNotificationService.triggerForSingleUser(subscriptionUid, null, null); + } + + @ResponseBody + @RequestMapping("/getPendingNotificationCount") + public void getPendingNotificationCount(HttpServletRequest req, HttpServletResponse res) throws IOException { + long count = eventNotificationService.getNotificationPendingCount(null, getUser().getUserID()); + res.setContentType("text/plain;charset=UTF-8"); + res.getWriter().print(count); + } + + private UserDTO getUser() { + HttpSession ss = SessionManager.getSession(); + return (UserDTO) ss.getAttribute(AttributeNames.USER); + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,645 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.contentrepository.exception.InvalidParameterException; +import org.lamsfoundation.lams.integration.dto.ExtGroupDTO; +import org.lamsfoundation.lams.integration.service.IIntegrationService; +import org.lamsfoundation.lams.learning.service.ICoreLearnerService; +import org.lamsfoundation.lams.learningdesign.Activity; +import org.lamsfoundation.lams.learningdesign.BranchingActivity; +import org.lamsfoundation.lams.learningdesign.Group; +import org.lamsfoundation.lams.learningdesign.GroupComparator; +import org.lamsfoundation.lams.learningdesign.Grouping; +import org.lamsfoundation.lams.learningdesign.GroupingActivity; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.monitoring.web.GroupingAJAXAction; +import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationGroup; +import org.lamsfoundation.lams.usermanagement.OrganisationGrouping; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.OrganisationGroupingDTO; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.AlphanumComparator; +import org.lamsfoundation.lams.util.JsonUtil; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +@Controller +@RequestMapping("/OrganisationGroup") +public class OrganisationGroupController { + + private static Logger log = Logger.getLogger(OrganisationGroupController.class); + + @Autowired + @Qualifier("userManagementService") + private IUserManagementService userManagementService; + @Autowired + @Qualifier("learnerService") + private ICoreLearnerService learnerService; + @Autowired + @Qualifier("lessonService") + private ILessonService lessonService; + @Autowired + @Qualifier("securityService") + private ISecurityService securityService; + @Autowired + @Qualifier("integrationService") + private IIntegrationService integrationService; + + private static final String MAPPING_VIEW_GROUPINGS = "viewGroupings"; + private static final String MAPPING_VIEW_GROUPS = "viewGroups"; + private static final String MAPPING_VIEW_EXT_GROUPS = "viewExtGroups"; + + /** + * Shows course grouping list or redirects to groups if a grouping was already chosen. + * + * @throws Exception + */ + @RequestMapping("/viewGroupings") + @SuppressWarnings("unchecked") + public String viewGroupings(HttpServletRequest request, HttpServletResponse response) throws Exception { + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); + + Integer userId = getUserDTO().getUserID(); + Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); + Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); + Organisation organisation = null; + if (organisationId == null) { + organisation = ((Lesson) userManagementService.findById(Lesson.class, lessonId)).getOrganisation(); + // read organisation ID from lesson + organisationId = organisation.getOrganisationId(); + } + if (organisation == null) { + organisation = (Organisation) userManagementService.findById(Organisation.class, organisationId); + } + // get course groupings from top-leve course + if (OrganisationType.CLASS_TYPE.equals(organisation.getOrganisationType().getOrganisationTypeId())) { + organisation = organisation.getParentOrganisation(); + organisationId = organisation.getOrganisationId(); + } + + // check if user is allowed to view and edit groupings + if (!securityService.hasOrgRole(organisationId, userId, + new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER, Role.MONITOR, Role.AUTHOR }, + "view organisation groupings", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a participant in the organisation"); + return null; + } + + List orgGroupings = userManagementService.findByProperty(OrganisationGrouping.class, + "organisationId", organisationId); + Grouping grouping = getLessonGrouping(activityID); + + // show groups page if this is a lesson mode and user have already chosen a grouping or there is no organisation + // groupings available + boolean lessonGroupsExist = (grouping != null) && (grouping.getGroups() != null) + && !grouping.getGroups().isEmpty() && !isDefaultChosenGrouping(grouping); + if (lessonGroupsExist || (activityID != null && orgGroupings.isEmpty())) { + return viewGroups(request, response); + } + + // if this grouping is used for branching then it should use groups set in authoring. It will be possible to + // remove users from the groups, but not delete groups due to the branching relationships. + boolean isUsedForBranching = (grouping != null) && grouping.isUsedForBranching(); + request.setAttribute(GroupingAJAXAction.PARAM_USED_FOR_BRANCHING, isUsedForBranching); + + if (OrganisationGroupController.log.isDebugEnabled()) { + OrganisationGroupController.log + .debug("Displaying course groupings for user " + userId + " and organisation " + organisationId); + } + request.setAttribute(AttributeNames.PARAM_ORGANISATION_ID, organisationId); + + // if it's not a group-based branching and lesson is created using integrations - show groups received from LMS instead of actual LAMS ones + if (!isUsedForBranching && integrationService.isIntegratedServerGroupFetchingAvailable(lessonId)) { + + if (lessonId == null) { + //it's when a learner clicks back button on groups page + Activity activity = learnerService.getActivity(activityID); + lessonId = learnerService.getLessonByActivity(activity).getLessonId(); + request.setAttribute("lessonID", lessonId); + } + + List extGroups = integrationService.getExtGroups(lessonId, null); + request.setAttribute("extGroups", extGroups); + // TODO ? show only with user number >0 + return "extGroups"; + } + + boolean isGroupSuperuser = userManagementService.isUserInRole(userId, organisationId, Role.GROUP_ADMIN) + || userManagementService.isUserInRole(userId, organisationId, Role.GROUP_MANAGER); + request.setAttribute("canEdit", isGroupSuperuser || (activityID != null)); + + Set orgGroupingDTOs = new TreeSet<>(); + for (OrganisationGrouping orgGrouping : orgGroupings) { + orgGroupingDTOs.add(new OrganisationGroupingDTO(orgGrouping)); + } + request.setAttribute("groupings", orgGroupingDTOs); + + return "orgGrouping"; + } + + /** + * View groups of the given grouping. + * + * @throws Exception + */ + @RequestMapping("/viewGroups") + @SuppressWarnings("unchecked") + public String viewGroups(HttpServletRequest request, HttpServletResponse response) throws Exception { + Integer userId = getUserDTO().getUserID(); + Integer organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); + Long lessonId = WebUtil.readLongParam(request, AttributeNames.PARAM_LESSON_ID, true); + Lesson lesson = null; + if (organisationId == null) { + // read organisation ID from lesson + lesson = (Lesson) userManagementService.findById(Lesson.class, lessonId); + organisationId = lesson.getOrganisation().getOrganisationId(); + } + request.setAttribute(AttributeNames.PARAM_LESSON_ID, lessonId); // Needed for the download spreadsheet call. + + // check if user is allowed to view and edit groups + if (!securityService.hasOrgRole(organisationId, userId, + new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER, Role.MONITOR, Role.AUTHOR }, + "view organisation groups", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a participant in the organisation"); + return null; + } + + boolean isGroupSuperuser = userManagementService.isUserInRole(userId, organisationId, Role.GROUP_ADMIN) + || userManagementService.isUserInRole(userId, organisationId, Role.GROUP_MANAGER); + + if (OrganisationGroupController.log.isDebugEnabled()) { + OrganisationGroupController.log + .debug("Displaying course groups for user " + userId + " and organisation " + organisationId); + } + Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); + request.setAttribute("canEdit", isGroupSuperuser || (activityId != null)); + + ObjectNode orgGroupingJSON = JsonNodeFactory.instance.objectNode(); + orgGroupingJSON.put("organisationId", organisationId); + + Long orgGroupingId = WebUtil.readLongParam(request, "groupingId", true); + OrganisationGrouping orgGrouping = null; + // check if course grouping already exists or it is a new one + if (orgGroupingId != null) { + orgGrouping = (OrganisationGrouping) userManagementService.findById(OrganisationGrouping.class, + orgGroupingId); + if (orgGrouping != null) { + orgGroupingJSON.put("groupingId", orgGroupingId); + orgGroupingJSON.put("name", orgGrouping.getName()); + } + } + + //selected groups from integrated server + String[] extGroupIds = request.getParameterValues("extGroupIds"); + boolean isExternalGroupsSelected = extGroupIds != null && extGroupIds.length > 0; + + // check if any groups already exist in this grouping + Grouping lessonGrouping = getLessonGrouping(activityId); + Set lessonGroups = lessonGrouping == null ? null : lessonGrouping.getGroups(); + if ((activityId != null) && (lessonGrouping != null) && (isExternalGroupsSelected || (orgGroupingId != null)) + && isDefaultChosenGrouping(lessonGrouping)) { + if (OrganisationGroupController.log.isDebugEnabled()) { + OrganisationGroupController.log.debug("Removing default groups for grouping " + orgGroupingId); + } + + Set groupIDs = new HashSet<>(lessonGroups.size()); + for (Group group : lessonGroups) { + groupIDs.add(group.getGroupId()); + } + for (Long groupId : groupIDs) { + lessonService.removeGroup(lessonGrouping, groupId); + } + + lessonGroups = null; + } + + // if this grouping is used for branching then it should use groups set in authoring. It will be possible to + // remove users from the groups, but not delete groups due to the branching relationships. + boolean isUsedForBranching = (lessonGrouping != null) && lessonGrouping.isUsedForBranching(); + request.setAttribute(GroupingAJAXAction.PARAM_USED_FOR_BRANCHING, isUsedForBranching); + + ArrayNode orgGroupsJSON = JsonNodeFactory.instance.arrayNode(); + Collection learners = null; + + // if teacher selected groups from integrated server - show them + if (isExternalGroupsSelected) { + + if (lesson == null) { + lesson = (Lesson) userManagementService.findById(Lesson.class, lessonId); + } + learners = lesson.getLessonClass().getLearners(); + + //request all users from selected groups from integrated server + List extGroups = integrationService.getExtGroups(lessonId, extGroupIds); + + // serialize database group objects into JSON + if (extGroups != null) { + + //if there are duplicate users - put them into unassigned column + List allDuplicates = new ArrayList<>(); + for (ExtGroupDTO groupA : extGroups) { + for (ExtGroupDTO groupB : extGroups) { + List usersA = groupA.getUsers(); + List usersB = groupB.getUsers(); + + //proceed for non empty and different groups + if ((usersA != null) && (usersB != null) && !groupA.getGroupId().equals(groupB.getGroupId())) { + + Collection duplicates = CollectionUtils.intersection(usersA, usersB); + allDuplicates.addAll(duplicates); + + usersA.removeAll(duplicates); + usersB.removeAll(duplicates); + } + + } + } + + // sort groups by their name + Collections.sort(extGroups); + for (ExtGroupDTO extGroup : extGroups) { + ObjectNode groupJSON = JsonNodeFactory.instance.objectNode(); + groupJSON.put("name", extGroup.getGroupName()); + groupJSON.put("groupId", extGroup.getGroupId()); + if (extGroup.getUsers() != null) { + for (User groupUser : (List) extGroup.getUsers()) { + ObjectNode groupUserJSON = WebUtil.userToJSON(groupUser); + groupJSON.withArray("users").add(groupUserJSON); + + // remove the user who is already assigned to a group + learners.remove(groupUser); + } + } + orgGroupsJSON.add(groupJSON); + } + } + + // if groups haven't been selected yet - show all available groups in organisation + } else if ((lessonGroups == null) || lessonGroups.isEmpty()) { + + learners = userManagementService.getUsersFromOrganisationByRole(organisationId, Role.LEARNER, true); + Set orgGroups = orgGrouping == null ? null : orgGrouping.getGroups(); + orgGroupsJSON = getOrgGroupsDetails(orgGroups, learners); + + // show already selected groups + } else { + + if (lesson == null) { + lesson = (Lesson) userManagementService.findById(Lesson.class, lessonId); + } + learners = lesson.getLessonClass().getLearners(); + orgGroupsJSON = getLessonGroupsDetails(lessonGroups, learners); + request.setAttribute("skipInitialAssigning", true); + } + orgGroupingJSON.set("groups", orgGroupsJSON); + request.setAttribute("grouping", orgGroupingJSON); + + // all the remaining users are unassigned to any group + ArrayNode unassignedUsersJSON = JsonNodeFactory.instance.arrayNode(); + for (User unassignedUser : learners) { + ObjectNode unassignedUserJSON = WebUtil.userToJSON(unassignedUser); + unassignedUsersJSON.add(unassignedUserJSON); + } + request.setAttribute("unassignedUsers", unassignedUsersJSON); + + return "orgGroup"; + } + + /** + * Saves a course grouping. + */ + @ResponseBody + @RequestMapping(path = "/save", method = RequestMethod.POST) + public void save(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) + throws InvalidParameterException, IOException { + // check if user is allowed to edit groups + Integer userId = getUserDTO().getUserID(); + int organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); + // check if user is allowed to save grouping + if (!securityService.hasOrgRole(organisationId, userId, new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER }, + "save organisation grouping", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a manager or admin in the organisation"); + } + + if (OrganisationGroupController.log.isDebugEnabled()) { + OrganisationGroupController.log + .debug("Saving course groups for user " + userId + " and organisation " + organisationId); + } + + // deserialize grouping + ObjectNode orgGroupingJSON = new ObjectMapper().readValue(request.getParameter("grouping"), ObjectNode.class); + // check if already exists + Long orgGroupingId = orgGroupingJSON.get("groupingId").asLong(); + if (orgGroupingId == 0L) { + orgGroupingId = null; + } + + // iterate over groups + List orgGroups = new LinkedList<>(); + ArrayNode orgGroupsJSON = JsonUtil.optArray(orgGroupingJSON, "groups"); + if (orgGroupsJSON != null) { + for (JsonNode orgGroupNode : orgGroupsJSON) { + // just overwrite existing groups; they will be updated if already exist + Set users = new HashSet<>(); + ObjectNode orgGroupJSON = (ObjectNode) orgGroupNode; + ArrayNode usersJSON = JsonUtil.optArray(orgGroupJSON, "users"); + if (usersJSON != null) { + // find user objects based on delivered IDs + for (JsonNode learnerId : usersJSON) { + User user = (User) userManagementService.findById(User.class, learnerId.asInt()); + users.add(user); + } + } + + OrganisationGroup orgGroup = new OrganisationGroup(); + Long orgGroupId = JsonUtil.optLong(orgGroupJSON, "groupId"); + if (orgGroupId > 0) { + orgGroup.setGroupId(orgGroupId); + orgGroup.setGroupingId(orgGroupingId); + } + orgGroup.setName(JsonUtil.optString(orgGroupJSON, "name")); + orgGroup.setUsers(users); + + orgGroups.add(orgGroup); + } + } + + OrganisationGrouping orgGrouping = null; + if (orgGroupingId != null) { + orgGrouping = (OrganisationGrouping) userManagementService.findById(OrganisationGrouping.class, + orgGroupingId); + } + if (orgGrouping == null) { + orgGrouping = new OrganisationGrouping(); + orgGrouping.setOrganisationId(organisationId); + } + // update grouping name + String orgGroupingName = JsonUtil.optString(orgGroupingJSON, "name"); + orgGrouping.setName(orgGroupingName); + + userManagementService.saveOrganisationGrouping(orgGrouping, orgGroups); + } + + /** + * Deletes course grouping with the given ID. + * + * @throws Exception + */ + @RequestMapping("/removeGrouping") + public String removeGrouping(HttpServletRequest request, HttpServletResponse response) throws Exception { + // check if user is allowed to edit groups + Integer userId = getUserDTO().getUserID(); + int organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); + if (!securityService.hasOrgRole(organisationId, userId, new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER }, + "remove organisation grouping", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a manager or admin in the organisation"); + return null; + } + + Long groupingId = WebUtil.readLongParam(request, "groupingId"); + if (OrganisationGroupController.log.isDebugEnabled()) { + OrganisationGroupController.log.debug( + "Removing grouping " + groupingId + " for user " + userId + " and organisation " + organisationId); + } + userManagementService.deleteById(OrganisationGrouping.class, groupingId); + + return viewGroupings(request, response); + } + + /** + * Fetches course and branching so they can get matched by user. + */ + @ResponseBody + @RequestMapping("/getGroupsForMapping") + public void getGroupsForMapping(HttpServletRequest request, HttpServletResponse response) throws IOException { + Long orgGroupingId = WebUtil.readLongParam(request, "groupingId"); + Long activityID = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID); + + OrganisationGrouping orgGrouping = (OrganisationGrouping) userManagementService + .findById(OrganisationGrouping.class, orgGroupingId); + ArrayNode groupsJSON = JsonNodeFactory.instance.arrayNode(); + SortedSet orgGroups = new TreeSet<>(orgGrouping.getGroups()); + for (OrganisationGroup group : orgGroups) { + ObjectNode groupJSON = JsonNodeFactory.instance.objectNode(); + groupJSON.put("id", group.getGroupId()); + groupJSON.put("name", group.getName()); + groupsJSON.add(groupJSON); + } + Activity activity = (Activity) userManagementService.findById(Activity.class, activityID); + Grouping grouping = activity.isGroupingActivity() ? ((GroupingActivity) activity).getCreateGrouping() + : ((BranchingActivity) activity).getGrouping(); + + ArrayNode branchesJSON = JsonNodeFactory.instance.arrayNode(); + SortedSet groups = new TreeSet<>(grouping.getGroups()); + for (Group group : groups) { + ObjectNode groupJSON = JsonNodeFactory.instance.objectNode(); + groupJSON.put("id", group.getGroupId()); + groupJSON.put("name", group.getGroupName()); + branchesJSON.add(groupJSON); + } + + ObjectNode responseJSON = JsonNodeFactory.instance.objectNode(); + responseJSON.set("branches", branchesJSON); + responseJSON.set("groups", groupsJSON); + + response.setContentType("application/json;charset=utf-8"); + response.getWriter().write(responseJSON.toString()); + } + + /** + * Stores course groups to branching groups mapping. + */ + @ResponseBody + @RequestMapping(path = "/save", method = RequestMethod.POST) + public void saveGroupMappings(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws IOException { + ArrayNode groupMapping = JsonUtil.readArray(request.getParameter("mapping")); + for (JsonNode entryNode : groupMapping) { + ObjectNode entry = (ObjectNode) entryNode; + Long orgGroupID = JsonUtil.optLong(entry, "groupID"); + Long branchingGroupID = JsonUtil.optLong(entry, "branchID"); + OrganisationGroup orgGroup = (OrganisationGroup) userManagementService.findById(OrganisationGroup.class, + orgGroupID); + Group branchingGroup = (Group) userManagementService.findById(Group.class, branchingGroupID); + // put all users from course group to mapped branching group + branchingGroup.getUsers().addAll(orgGroup.getUsers()); + userManagementService.save(branchingGroup); + } + response.setContentType("text/plain;charset=utf-8"); + // Javascript waits for this response + response.getWriter().write("OK"); + } + + /** + * Build JSON objects based on existing lesson-level groups. + */ + private ArrayNode getLessonGroupsDetails(Set groups, Collection learners) { + // serialize database group objects into JSON + ArrayNode groupsJSON = JsonNodeFactory.instance.arrayNode(); + if (groups != null) { + // sort groups by their name + List groupList = new LinkedList<>(groups); + Collections.sort(groupList, new GroupComparator()); + for (Group group : groupList) { + ObjectNode groupJSON = JsonNodeFactory.instance.objectNode(); + groupJSON.put("name", group.getGroupName()); + groupJSON.put("groupId", group.getGroupId()); + groupJSON.put("locked", !group.mayBeDeleted()); + if (group.getUsers() != null) { + for (User groupUser : group.getUsers()) { + ObjectNode groupUserJSON = WebUtil.userToJSON(groupUser); + groupJSON.withArray("users").add(groupUserJSON); + + // remove the user who is already assigned to a group + learners.remove(groupUser); + } + } + groupsJSON.add(groupJSON); + } + } + + return groupsJSON; + } + + /** + * Build JSON objects based on existing course-level groups. + */ + private ArrayNode getOrgGroupsDetails(Set groups, Collection learners) { + + final Comparator ORG_GROUP_COMPARATOR = new Comparator() { + @Override + public int compare(OrganisationGroup o1, OrganisationGroup o2) { + String grp1Name = o1 != null ? o1.getName() : ""; + String grp2Name = o2 != null ? o2.getName() : ""; + + AlphanumComparator comparator = new AlphanumComparator(); + return comparator.compare(grp1Name, grp2Name); + } + }; + + // serialize database group objects into JSON + ArrayNode groupsJSON = JsonNodeFactory.instance.arrayNode(); + if (groups != null) { + // sort groups by their name + List groupList = new LinkedList<>(groups); + Collections.sort(groupList, ORG_GROUP_COMPARATOR); + + for (OrganisationGroup group : groupList) { + ObjectNode groupJSON = JsonNodeFactory.instance.objectNode(); + groupJSON.put("name", group.getName()); + groupJSON.put("groupId", group.getGroupId()); + for (User groupUser : group.getUsers()) { + ObjectNode groupUserJSON = WebUtil.userToJSON(groupUser); + groupJSON.withArray("users").add(groupUserJSON); + + // remove the user who is already assigned to a group + learners.remove(groupUser); + } + + groupsJSON.add(groupJSON); + } + } + + return groupsJSON; + } + + /** + * Checks if lesson-level groups exist for the given activity. + */ + private Grouping getLessonGrouping(Long activityID) { + if (activityID != null) { + // we need to fetch real objects instead of stubs/proxies + Activity activity = (Activity) userManagementService.findById(Activity.class, activityID); + Grouping grouping = activity.isChosenBranchingActivity() ? activity.getGrouping() + : ((GroupingActivity) userManagementService.findById(GroupingActivity.class, activityID)) + .getCreateGrouping(); + + return grouping; + } + + return null; + } + + /** + * Check if the given groups are default for chosen grouping. There is actually no good way to detect this, but even + * if a custom grouping is mistaken for the default one, it should bring little harm. + */ + private boolean isDefaultChosenGrouping(Grouping grouping) { + Set groups = grouping.getGroups(); + for (Group group : groups) { + if (!group.getUsers().isEmpty()) { + return false; + } + } + if (groups == null || (grouping.getMaxNumberOfGroups() != null + && !grouping.getMaxNumberOfGroups().equals(groups.size()))) { + return false; + } + return true; + } + + private UserDTO getUserDTO() { + HttpSession ss = SessionManager.getSession(); + return (UserDTO) ss.getAttribute(AttributeNames.USER); + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/PasswordAction.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/PasswordChangeAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/PasswordChangeActionForm.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/web/PasswordChangeActionForm.java (.../PasswordChangeActionForm.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/src/java/org/lamsfoundation/lams/web/PasswordChangeActionForm.java (.../PasswordChangeActionForm.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -26,8 +26,6 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.StringUtils; -import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionMapping; /** * @author fmalikoff @@ -37,10 +35,10 @@ * * */ -public class PasswordChangeActionForm extends ActionForm { +public class PasswordChangeActionForm { public static final String formName = "PasswordChangeActionForm"; // must match name in @struts:action section above - + private String redirectURL; private String oldPassword; @@ -125,13 +123,13 @@ public void setOldPassword(String oldPassword) { this.oldPassword = StringUtils.trimToEmpty(oldPassword); } - + public String getRedirectURL() { - return redirectURL; + return redirectURL; } public void setRedirectURL(String redirectURL) { - this.redirectURL = redirectURL; + this.redirectURL = redirectURL; } /** @@ -142,8 +140,8 @@ * @param request * The servlet request we are processing */ - @Override - public void reset(ActionMapping mapping, HttpServletRequest request) { + + public void reset(HttpServletRequest request) { setOldPassword(null); setPassword(null); setPasswordConfirm(null); Index: lams_central/src/java/org/lamsfoundation/lams/web/PasswordChangeController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/PasswordChangeController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/PasswordChangeController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,156 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; +import org.apache.struts.Globals; +import org.lamsfoundation.lams.logevent.LogEvent; +import org.lamsfoundation.lams.logevent.service.ILogEventService; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.UserManagementService; +import org.lamsfoundation.lams.util.HashUtil; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.ValidationUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * @author Fei Yang + */ +@Controller +public class PasswordChangeController { + + private static Logger log = Logger.getLogger(PasswordChangeController.class); + + @Autowired + MessageService messageService; + @Autowired + WebApplicationContext applicationContext; + + /** + * @param mapping + * The ActionMapping used to select this instance + * @param actionForm + * The optional ActionForm bean for this request (if any) + * @param request + * The HTTP request we are processing + * @param response + * The HTTP response we are creating + * + */ + @RequestMapping("/passwordChanged") + public String execute(@ModelAttribute PasswordChangeActionForm passwordChangeForm, HttpServletRequest request) + throws Exception { + // -- isCancelled? + if (request.getAttribute(Globals.CANCEL_KEY) != null) { + request.getSession().removeAttribute(PasswordChangeActionForm.formName); + return "redirect:/index/profile.do"; + } + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + + if (errorMap.isEmpty()) { + try { + + String loggedInUser = request.getRemoteUser(); + String login = passwordChangeForm.getLogin(); + String oldPassword = passwordChangeForm.getOldPassword(); + String password = passwordChangeForm.getPassword(); + String passwordConfirm = passwordChangeForm.getPasswordConfirm(); + + if ((loggedInUser == null) || !loggedInUser.equals(login)) { + errorMap.add("GLOBAL", messageService.getMessage("error.authorisation")); + } else { + // WebApplicationContext ctx = + // WebApplicationContextUtils.getWebApplicationContext(request.getSession(true).getServletContext()); + WebApplicationContext ctx = WebApplicationContextUtils + .getWebApplicationContext(applicationContext.getServletContext()); + UserManagementService service = (UserManagementService) ctx.getBean("userManagementService"); + + User user = service.getUserByLogin(login); + String passwordHash = user.getPassword().length() == HashUtil.SHA1_HEX_LENGTH + ? HashUtil.sha1(oldPassword) + : HashUtil.sha256(oldPassword, user.getSalt()); + + if (!user.getPassword().equals(passwordHash)) { + errorMap.add("oldPassword", messageService.getMessage("error.oldpassword.mismatch")); + PasswordChangeController.log.debug("old pass wrong"); + } + if (!password.equals(passwordConfirm)) { + errorMap.add("password", messageService.getMessage("error.newpassword.mismatch")); + PasswordChangeController.log.debug("new pass wrong"); + } + if ((password == null) || (password.length() == 0)) { + errorMap.add("password", messageService.getMessage("error.password.empty")); + PasswordChangeController.log.debug("new password cannot be empty"); + } + if (!ValidationUtil.isPasswordValueValid(password, passwordConfirm)) { + errorMap.add("password", messageService.getMessage("label.password.restrictions")); + PasswordChangeController.log.debug("Password must follow the restrictions"); + } + + if (errorMap.isEmpty()) { + String salt = HashUtil.salt(); + user.setSalt(salt); + user.setPassword(HashUtil.sha256(password, salt)); + user.setChangePassword(false); + service.saveUser(user); + + // make 'password changed' audit log entry + ILogEventService logEventService = (ILogEventService) ctx.getBean("logEventService"); + MessageService messageService = (MessageService) ctx.getBean("centralMessageService"); + String[] args = new String[1]; + args[0] = user.getLogin() + " (" + user.getUserId() + ")"; + String message = messageService.getMessage("audit.user.password.change", args); + logEventService.logEvent(LogEvent.TYPE_LOGIN_AS, user.getUserId(), user.getUserId(), null, null, + message); + } + } + + } catch (Exception e) { + PasswordChangeController.log.error("Exception occured ", e); + errorMap.add("GLOBAL", messageService.getMessage(e.getMessage())); + } + + } // end if no errors + + // -- Report any errors + if (!errorMap.isEmpty()) { + request.setAttribute("errorMap", errorMap); + passwordChangeForm.reset(request); + return "redirect:/index/password.do"; + } + request.setAttribute("redirectURL", passwordChangeForm.getRedirectURL()); + return "/passwordChangeOkContent"; + + } +} Index: lams_central/src/java/org/lamsfoundation/lams/web/PasswordController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/PasswordController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/PasswordController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,45 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author jliew + */ +@Controller +public class PasswordController { + + @RequestMapping("/password") + public String execute(@ModelAttribute PasswordChangeActionForm passwordChangeForm, HttpServletRequest request) + throws Exception { + + passwordChangeForm.setLogin(request.getRemoteUser()); + return "passwordChangeContent"; + } +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/PortraitAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/PortraitActionForm.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/web/PortraitActionForm.java (.../PortraitActionForm.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/src/java/org/lamsfoundation/lams/web/PortraitActionForm.java (.../PortraitActionForm.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -21,19 +21,17 @@ * **************************************************************** */ - package org.lamsfoundation.lams.web; -import org.apache.struts.action.ActionForm; -import org.apache.struts.upload.FormFile; +import org.springframework.web.multipart.MultipartFile; /** * @author jliew */ -public class PortraitActionForm extends ActionForm { +public class PortraitActionForm { private Long portraitUuid; - private FormFile file; + private MultipartFile file; public Long getPortraitUuid() { return portraitUuid; @@ -43,11 +41,11 @@ this.portraitUuid = uuid; } - public FormFile getFile() { + public MultipartFile getFile() { return file; } - public void setFile(FormFile file) { + public void setFile(MultipartFile file) { this.file = file; } Index: lams_central/src/java/org/lamsfoundation/lams/web/PortraitController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/PortraitController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/PortraitController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,57 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author jliew + */ +@Controller +public class PortraitController { + + private static Logger log = Logger.getLogger(PortraitController.class); + @Autowired + @Qualifier("userManagementService") + private static IUserManagementService service; + + @RequestMapping("/portrait") + public String execute(@ModelAttribute PortraitActionForm portraitForm, HttpServletRequest request) + throws Exception { + + Long portraitUuid = service.getUserByLogin(request.getRemoteUser()).getPortraitUuid(); + log.debug("using portraitUuid=" + portraitUuid); + // if no portrait has been uploaded, set the uuid to 0 + portraitForm.setPortraitUuid(portraitUuid == null ? 0 : portraitUuid); + return "portrait"; + } +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/PortraitSaveController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,229 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.io.IOException; +import java.io.InputStream; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.struts.Globals; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionMapping; +import org.lamsfoundation.lams.contentrepository.NodeKey; +import org.lamsfoundation.lams.logevent.LogEvent; +import org.lamsfoundation.lams.logevent.service.ILogEventService; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.CentralToolContentHandler; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.util.imgscalr.ResizePictureUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; +import org.springframework.web.multipart.MultipartFile; + +/** + * @author jliew + * @author Andrey Balan + */ +@Controller +@RequestMapping("/saveportrait") +public class PortraitSaveController { + + private static Logger log = Logger.getLogger(PortraitSaveController.class); + @Autowired + @Qualifier("userManagementService") + private IUserManagementService service; + @Autowired + @Qualifier("logEventService") + private ILogEventService logEventService; + @Autowired + private MessageService messageService; + @Autowired + WebApplicationContext applicationContext; + private static CentralToolContentHandler centralToolContentHandler; + private static final String PORTRAIT_DELETE_AUDIT_KEY = "audit.delete.portrait"; + + /** + * Upload portrait image. + */ + @RequestMapping("") + public String unspecified(@ModelAttribute PortraitActionForm portraitForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (request.getAttribute(Globals.CANCEL_KEY) != null) { + return "redirect:/index/profile.do"; + } + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + + MultipartFile file = portraitForm.getFile(); + String fileName = file.getName(); + log.debug("got file: " + fileName + " of type: " + file.getContentType() + " with size: " + file.getSize()); + + User user = service.getUserByLogin(request.getRemoteUser()); + + // check if file is an image using the MIME content type + String mediaType = file.getContentType().split("/", 2)[0]; + if (!mediaType.equals("image")) { + errorMap.add("file", messageService.getMessage("error.portrait.not.image")); + request.setAttribute("errorMap", errorMap); + return "redirect:/index/portrait.do"; + } + + // check file exists + InputStream is = file.getInputStream(); + if (is == null) { + errorMap.add("file", messageService.getMessage("error.general.1")); + request.setAttribute("errorMap", errorMap); + return "redirect:/index/portrait.do"; + } + + // write to content repository + NodeKey originalFileNode = null; + if ((file != null) && !StringUtils.isEmpty(fileName)) { + + //Create nice file name. If file name equals to "blob" - it means it was uploaded using webcam + String fileNameWithoutExt; + if (fileName.equals("blob")) { + HttpSession ss = SessionManager.getSession(); + UserDTO userDTO = (UserDTO) ss.getAttribute(AttributeNames.USER); + fileNameWithoutExt = userDTO.getLogin() + "_portrait"; + + } else { + fileNameWithoutExt = fileName.substring(0, fileName.indexOf('.')); + } + + // upload to the content repository + originalFileNode = getCentralToolContentHandler().uploadFile(is, fileNameWithoutExt + "_original.jpg", + "image/jpeg"); + is.close(); + log.debug("saved file with uuid: " + originalFileNode.getUuid() + " and version: " + + originalFileNode.getVersion()); + + //resize to the large size + is = ResizePictureUtil.resize(file.getInputStream(), + IUserManagementService.PORTRAIT_LARGEST_DIMENSION_LARGE); + NodeKey node = getCentralToolContentHandler().updateFile(originalFileNode.getUuid(), is, + fileNameWithoutExt + "_large.jpg", "image/jpeg"); + is.close(); + log.debug("saved file with uuid: " + node.getUuid() + " and version: " + node.getVersion()); + + //resize to the medium size + is = ResizePictureUtil.resize(file.getInputStream(), + IUserManagementService.PORTRAIT_LARGEST_DIMENSION_MEDIUM); + node = getCentralToolContentHandler().updateFile(node.getUuid(), is, fileNameWithoutExt + "_medium.jpg", + "image/jpeg"); + is.close(); + log.debug("saved file with uuid: " + node.getUuid() + " and version: " + node.getVersion()); + + //resize to the small size + is = ResizePictureUtil.resize(file.getInputStream(), + IUserManagementService.PORTRAIT_LARGEST_DIMENSION_SMALL); + node = getCentralToolContentHandler().updateFile(node.getUuid(), is, fileNameWithoutExt + "_small.jpg", + "image/jpeg"); + is.close(); + log.debug("saved file with uuid: " + node.getUuid() + " and version: " + node.getVersion()); + + } + + // delete old portrait file (we only want to keep the user's current portrait) + if (user.getPortraitUuid() != null) { + getCentralToolContentHandler().deleteFile(user.getPortraitUuid()); + } + user.setPortraitUuid(originalFileNode.getUuid()); + service.saveUser(user); + + return "redirect:/index/profile.do"; + } + + /** Called from sysadmin to delete an inappropriate portrait */ + @RequestMapping("/deletePortrait") + public String deletePortrait(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + Integer userId = WebUtil.readIntParam(request, "userId", true); + + // check user is sysadmin + if (!(request.isUserInRole(Role.SYSADMIN))) { + log.error("Attempt to delete a portrait by user that is not sysadmin. User is " + request.getRemoteUser() + + " portrait to be deleted is for user " + userId + "."); + return deleteResponse(response, "error"); + } + + String responseValue = "deleted"; + User userToModify = (User) service.findById(User.class, userId); + if (userToModify != null && userToModify.getPortraitUuid() != null) { + + UserDTO sysadmin = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + Object[] args = new Object[] { userToModify.getFullName(), userToModify.getLogin(), + userToModify.getUserId(), userToModify.getPortraitUuid() }; + String auditMessage = messageService.getMessage(PORTRAIT_DELETE_AUDIT_KEY, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, sysadmin.getUserID(), userId, null, null, + auditMessage); + + try { + getCentralToolContentHandler().deleteFile(userToModify.getPortraitUuid()); + userToModify.setPortraitUuid(null); + service.saveUser(userToModify); + } catch (Exception e) { + log.error("Unable to delete a portrait for user " + userId + ".", e); + return deleteResponse(response, "error"); + } + } + return deleteResponse(response, responseValue); + } + + private String deleteResponse(HttpServletResponse response, String data) throws IOException { + response.setContentType("text/plain;charset=utf-8"); + response.getWriter().write(data); + return null; + } + + private CentralToolContentHandler getCentralToolContentHandler() { + if (centralToolContentHandler == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + centralToolContentHandler = (CentralToolContentHandler) wac.getBean("centralToolContentHandler"); + } + return centralToolContentHandler; + } + +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/ProfileAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/ProfileController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/ProfileController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/ProfileController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,258 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ +package org.lamsfoundation.lams.web; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.TimeZone; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.index.IndexLessonBean; +import org.lamsfoundation.lams.index.IndexOrgBean; +import org.lamsfoundation.lams.learning.service.ICoreLearnerService; +import org.lamsfoundation.lams.lesson.dto.LessonDTO; +import org.lamsfoundation.lams.themes.Theme; +import org.lamsfoundation.lams.themes.service.IThemeService; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; +import org.lamsfoundation.lams.timezone.service.ITimezoneService; +import org.lamsfoundation.lams.timezone.util.TimezoneIDComparator; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.SupportedLocale; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.IndexUtils; +import org.lamsfoundation.lams.util.LanguageUtil; +import org.lamsfoundation.lams.util.MessageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Fei Yang + */ +@Controller +@RequestMapping("/profile") +public class ProfileController { + + private static Logger log = Logger.getLogger(ProfileController.class); + + @Autowired + @Qualifier("userManagementService") + private IUserManagementService service; + + private static List locales; + @Autowired + @Qualifier("learnerService") + private ICoreLearnerService learnerService; + @Autowired + @Qualifier("themeService") + private IThemeService themeService; + @Autowired + @Qualifier("timezoneService") + private ITimezoneService timezoneService; + @Autowired + private MessageService messageService; + + @RequestMapping("/view") + public String view(HttpServletRequest request) throws Exception { + + User requestor = service.getUserByLogin(request.getRemoteUser()); + String fullName = (requestor.getTitle() != null ? requestor.getTitle() + " " : "") + requestor.getFirstName() + + " " + requestor.getLastName(); + String email = requestor.getEmail(); + + request.setAttribute("fullName", fullName); + request.setAttribute("email", (email != null ? email : "")); + request.setAttribute("portraitUuid", requestor.getPortraitUuid()); + + return "profile"; + } + + @RequestMapping("/lessons") + public String lessons(HttpServletRequest request) throws Exception { + + // list all active lessons for this learner (single sql query) + User requestor = service.getUserByLogin(request.getRemoteUser()); + LessonDTO[] lessons = learnerService.getActiveLessonsFor(requestor.getUserId()); + + // make org-sorted beans out of the lessons + HashMap orgBeansMap = new HashMap<>(); + for (LessonDTO lesson : lessons) { + Integer orgId = lesson.getOrganisationID(); + Organisation org = (Organisation) service.findById(Organisation.class, orgId); + Integer orgTypeId = org.getOrganisationType().getOrganisationTypeId(); + IndexLessonBean lessonBean = new IndexLessonBean(lesson.getLessonName(), + "javascript:openLearner(" + lesson.getLessonID() + ")"); + lessonBean.setId(lesson.getLessonID()); + log.debug("Lesson: " + lesson.getLessonName()); + + // insert or update bean if it is a course + if (orgTypeId.equals(OrganisationType.COURSE_TYPE)) { + IndexOrgBean orgBean = (!orgBeansMap.containsKey(orgId)) + ? new IndexOrgBean(org.getOrganisationId(), org.getName(), orgTypeId) + : orgBeansMap.get(orgId); + orgBean.addLesson(lessonBean); + orgBeansMap.put(orgId, orgBean); + } else if (orgTypeId.equals(OrganisationType.CLASS_TYPE)) { + + // if it is a class, find existing or create new parent bean + Organisation parentOrg = org.getParentOrganisation(); + Integer parentOrgId = parentOrg.getOrganisationId(); + IndexOrgBean parentOrgBean = (!orgBeansMap.containsKey(parentOrgId)) ? new IndexOrgBean( + parentOrg.getOrganisationId(), parentOrg.getName(), OrganisationType.COURSE_TYPE) + : orgBeansMap.get(parentOrgId); + // create new bean for class, or use existing bean + IndexOrgBean orgBean = new IndexOrgBean(org.getOrganisationId(), org.getName(), orgTypeId); + List childOrgBeans = parentOrgBean.getChildIndexOrgBeans(); + if (childOrgBeans.contains(orgBean)) { + // use existing org bean + orgBean = getOrgBean(org.getName(), childOrgBeans); + childOrgBeans.remove(orgBean); + orgBean.addLesson(lessonBean); + childOrgBeans.add(orgBean); + parentOrgBean.setChildIndexOrgBeans(childOrgBeans); + } else { + // using new org bean + orgBean.addLesson(lessonBean); + parentOrgBean.addChildOrgBean(orgBean); + } + orgBeansMap.put(parentOrgId, parentOrgBean); + } + } + + // sort group and subgroup names + ArrayList beans = new ArrayList<>(orgBeansMap.values()); + Collections.sort(beans); + for (IndexOrgBean b : beans) { + Collections.sort(b.getChildIndexOrgBeans()); + } + + // sort lessons inside each org bean + for (Object o : beans) { + IndexOrgBean bean = (IndexOrgBean) o; + Organisation org = (Organisation) service.findById(Organisation.class, bean.getId()); + + // put lesson beans into id-indexed map + HashMap map = new HashMap<>(); + for (IndexLessonBean lbean : bean.getLessons()) { + map.put(lbean.getId(), lbean); + } + + bean.setLessons(IndexUtils.sortLessonBeans(org.getOrderedLessonIds(), map)); + } + + request.setAttribute("beans", beans); + + return "lessons"; + } + + private IndexOrgBean getOrgBean(String name, List list) { + for (IndexOrgBean bean : list) { + if (StringUtils.equals(name, bean.getName())) { + return bean; + } + } + return null; + } + + @RequestMapping("/edit") + public String edit(@ModelAttribute UserForm userForm, HttpServletRequest request) throws Exception { + + //some errors may have already been set in ProfileSaveAction + MultiValueMap errorMap = (MultiValueMap) request.getAttribute("errorMap"); + if (errorMap == null) { + errorMap = new LinkedMultiValueMap<>(); + } + + if (!Configuration.getAsBoolean(ConfigurationKeys.PROFILE_EDIT_ENABLE)) { + if (!Configuration.getAsBoolean(ConfigurationKeys.PROFILE_PARTIAL_EDIT_ENABLE)) { + errorMap.add("GLOBAL", messageService.getMessage("error.edit.disabled")); + } else { + errorMap.add("GLOBAL", messageService.getMessage("message.partial.edit.only")); + } + request.setAttribute("errorMap", errorMap); + ; + } + + User requestor = service.getUserByLogin(request.getRemoteUser()); + BeanUtils.copyProperties(userForm, requestor); + SupportedLocale locale = requestor.getLocale(); + if (locale == null) { + locale = LanguageUtil.getDefaultLocale(); + } + userForm.setLocaleId(locale.getLocaleId()); + request.setAttribute("locales", locales); + + // Get all the css themes + List themes = themeService.getAllThemes(); + request.setAttribute("themes", themes); + + // Check the user css theme is still installed + Long userSelectedTheme = null; + if (requestor.getTheme() != null) { + for (Theme theme : themes) { + if (theme.getThemeId() == requestor.getTheme().getThemeId()) { + userSelectedTheme = theme.getThemeId(); + break; + } + } + } + // if still null, use the default + if (userSelectedTheme == null) { + userSelectedTheme = themeService.getDefaultTheme().getThemeId(); + } + userForm.setUserTheme(userSelectedTheme); + + List availableTimeZones = timezoneService.getDefaultTimezones(); + //TreeSet timezoneDtos = new TreeSet(new TimezoneDTOComparator()); + // Comparator to sort timezones by timezone id + TreeSet timezoneDtos = new TreeSet<>(new TimezoneIDComparator()); + + for (Timezone availableTimeZone : availableTimeZones) { + String timezoneId = availableTimeZone.getTimezoneId(); + TimezoneDTO timezoneDto = new TimezoneDTO(); + timezoneDto.setTimeZoneId(timezoneId); + timezoneDto.setDisplayName(TimeZone.getTimeZone(timezoneId).getDisplayName()); + timezoneDtos.add(timezoneDto); + } + request.setAttribute("timezoneDtos", timezoneDtos); + + return "editprofile"; + } + +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/ProfileSaveController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,150 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.struts.Globals; +import org.lamsfoundation.lams.themes.Theme; +import org.lamsfoundation.lams.usermanagement.SupportedLocale; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.ValidationUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; + +/** + * @author jliew + */ +@Controller +public class ProfileSaveController { + + private static Logger log = Logger.getLogger(ProfileSaveController.class); + @Autowired + @Qualifier("userManagementService") + private IUserManagementService service; + @Autowired + private MessageService messageService; + + @RequestMapping(path = "/saveprofile", method = RequestMethod.POST) + public String execute(@ModelAttribute UserForm userForm, HttpServletRequest request) throws Exception { + + if (request.getAttribute(Globals.CANCEL_KEY) != null) { + return "redirect:/index/profile.do?"; + } + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + + if (!Configuration.getAsBoolean(ConfigurationKeys.PROFILE_EDIT_ENABLE)) { + if (!Configuration.getAsBoolean(ConfigurationKeys.PROFILE_PARTIAL_EDIT_ENABLE)) { + return "redirect:/index/editprofile.do"; + } + } + + User requestor = service.getUserByLogin(request.getRemoteUser()); + + // check requestor is same as user being edited + if (!requestor.getLogin().equals(userForm.getLogin())) { + ProfileSaveController.log + .warn(requestor.getLogin() + " tried to edit profile of user " + userForm.getLogin()); + errorMap.add("GLOBAL", messageService.getMessage("error.authorisation")); + request.setAttribute("errorMap", errorMap); + ; + return "redirect:/index/editprofile.do"; + } + + // (dyna)form validation + //first name validation + String firstName = (userForm.getFirstName() == null) ? null : (String) userForm.getFirstName(); + if (StringUtils.isBlank(firstName)) { + errorMap.add("firstName", messageService.getMessage("error.firstname.required")); + } else if (!ValidationUtil.isFirstLastNameValid(firstName)) { + errorMap.add("firstName", messageService.getMessage("error.firstname.invalid.characters")); + } + + //last name validation + String lastName = (userForm.getLastName() == null) ? null : (String) userForm.getLastName(); + if (StringUtils.isBlank(lastName)) { + errorMap.add("lastName", messageService.getMessage("error.lastname.required")); + } else if (!ValidationUtil.isFirstLastNameValid(lastName)) { + errorMap.add("lastName", messageService.getMessage("error.lastname.invalid.characters")); + } + + //user email validation + String userEmail = (userForm.getEmail() == null) ? null : (String) userForm.getEmail(); + if (StringUtils.isBlank(userEmail)) { + errorMap.add("email", messageService.getMessage("error.email.required")); + } else if (!ValidationUtil.isEmailValid(userEmail)) { + errorMap.add("email", messageService.getMessage("error.valid.email.required")); + } + + if (!errorMap.isEmpty()) { + request.setAttribute("errorMap", errorMap); + ; + return "redirect:/index/editprofile.do"; + } + + if (!Configuration.getAsBoolean(ConfigurationKeys.PROFILE_EDIT_ENABLE) + && Configuration.getAsBoolean(ConfigurationKeys.PROFILE_PARTIAL_EDIT_ENABLE)) { + // update only contact fields + requestor.setEmail(userForm.getEmail()); + requestor.setDayPhone(userForm.getDayPhone()); + requestor.setEveningPhone(userForm.getEveningPhone()); + requestor.setMobilePhone(userForm.getMobilePhone()); + requestor.setFax(userForm.getFax()); + } else { + // update all fields + BeanUtils.copyProperties(requestor, userForm); + SupportedLocale locale = (SupportedLocale) service.findById(SupportedLocale.class, userForm.getLocaleId()); + requestor.setLocale(locale); + + Theme cssTheme = (Theme) service.findById(Theme.class, userForm.getUserTheme()); + requestor.setTheme(cssTheme); + } + + service.saveUser(requestor); + + // replace UserDTO in the shared session + HttpSession ss = SessionManager.getSession(); + ss.setAttribute(AttributeNames.USER, requestor.getUserDTO()); + + return "redirect:/index/profile.do"; + } + +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/QuestionsAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/QuestionsController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/QuestionsController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/QuestionsController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,86 @@ +package org.lamsfoundation.lams.web; + +import java.io.InputStream; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload.DiskFileUpload; +import org.apache.commons.fileupload.FileItem; +import org.apache.commons.lang.StringUtils; +import org.apache.struts.Globals; +import org.apache.struts.action.ActionMessage; +import org.apache.struts.action.ActionMessages; +import org.lamsfoundation.lams.questions.Question; +import org.lamsfoundation.lams.questions.QuestionParser; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * Runs extraction of chosen IMS QTI zip file and prepares form for user to manually choose interesting question. + * + * + * + * + */ +@Controller +public class QuestionsController { + @SuppressWarnings("unchecked") + @RequestMapping("/questions") + public String execute(HttpServletRequest request) throws Exception { + // cumberstone way of extracting POSTed form with a file + DiskFileUpload formParser = new DiskFileUpload(); + formParser.setRepositoryPath(Configuration.get(ConfigurationKeys.LAMS_TEMP_DIR)); + List formFields = formParser.parseRequest(request); + + String returnURL = null; + String limitTypeParam = null; + InputStream uploadedFileStream = null; + String packageName = null; + for (FileItem formField : formFields) { + String fieldName = formField.getFieldName(); + if ("returnURL".equals(fieldName)) { + // this can be empty; if so, another method of delivering results is used + returnURL = formField.getString(); + } else if ("limitType".equals(fieldName)) { + limitTypeParam = formField.getString(); + } else if ("file".equals(fieldName) && !StringUtils.isBlank(formField.getName())) { + packageName = formField.getName().toLowerCase(); + uploadedFileStream = formField.getInputStream(); + } + } + + // this parameter is not really used at the moment + request.setAttribute("returnURL", returnURL); + + // show only chosen types of questions + request.setAttribute("limitType", limitTypeParam); + + // user did not choose a file + if ((uploadedFileStream == null) || !(packageName.endsWith(".zip") || packageName.endsWith(".xml"))) { + ActionMessages errors = new ActionMessages(); + errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("label.questions.file.missing")); + request.setAttribute(Globals.ERROR_KEY, errors); + return "questions/questionFile"; + } + + Set limitType = null; + if (!StringUtils.isBlank(limitTypeParam)) { + limitType = new TreeSet<>(); + // comma delimited acceptable question types, for example "mc,fb" + Collections.addAll(limitType, limitTypeParam.split(",")); + } + + Question[] questions = packageName.endsWith(".xml") + ? QuestionParser.parseQTIFile(uploadedFileStream, null, limitType) + : QuestionParser.parseQTIPackage(uploadedFileStream, limitType); + request.setAttribute("questions", questions); + + return "questions/questionChoice"; + } +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/RedirectAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/RedirectController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/RedirectController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/RedirectController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,185 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.codec.binary.Base64; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.tool.ToolSession; +import org.lamsfoundation.lams.tool.service.ILamsToolService; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author lfoxton + * + * This action is used for notification emails. It is designed to enable direct linking to either monitor or + * learner so that links can be sent in the email. This must be done through LAMS central so it correctly + * redirects the user to the login page (if they have no session) before returning them to the correct location. + * + * This action takes one parameter "h" which is a Base64 hash of a comma-separated value (relativeUrlPath, + * toolSessionID, accessMode) where: relativeUrlPath = Relative path to resource eg /tool/lawiki10/learner.do + * toolSessionID = A valid tool session ID for the lesson accessMode = l or t (learner or teacher) + * + * The parameters are hashed to prevent people from identifying the url, and attempting to access content to + * which they are unauthorised, see LDEV-1978 + * + * The toolSessionID and accessMode are used to determine the permissions of this user so it someone forwards + * the email to an unauthorised user, they still cannot access the link unless they are part of the correct + * group. These checks may become unneccessary on the completion of LDEV-1978 + * + * Note that parameter names have been made as short as possible here to attempt to shorten the entire link + * required, and hopefully prevent email clients cutting them off and making a newline which sometimes breaks + * links. + * + * + * + * + * + */ +@Controller +public class RedirectController { + + private static Logger log = Logger.getLogger(RedirectController.class); + + public static final String PARAM_HASH = "h"; + + public static final String ACCESS_MODE_TEACHER = "t"; + public static final String ACCESS_MODE_LEARNER = "l"; + + @Autowired + @Qualifier("lamsToolService") + private ILamsToolService lamsToolService; + @Autowired + @Qualifier("userManagementService") + private IUserManagementService userService; + + @RequestMapping("/r") + public String execute(HttpServletRequest req, HttpServletResponse res) throws Exception { + + try { + String hash = WebUtil.readStrParam(req, RedirectController.PARAM_HASH); + + // Un-hash the string to gain all the paramters + String fullParams = new String(Base64.decodeBase64(hash.getBytes())); + + // Split the CSV parameters + String[] split = fullParams.split(","); + + if (split.length != 3) { + throw new Exception("Hash did not contain correct format (relative path, toolSessionID, toolaccess )"); + } + + // Getting the parameters from the hash + String relativePath = split[0]; + Long toolSessionID = Long.parseLong(split[1]); + String accessMode = split[2]; + + // Get the user + UserDTO user = getUser(); + if (user == null) { + RedirectController.log.error("admin: User missing from session. "); + return "errorContent"; + } + + // Get the tool session + ToolSession toolSession = getToolSession(toolSessionID); + + if (toolSession == null) { + RedirectController.log.error("No ToolSession with ID " + toolSessionID + " found."); + return "errorContent"; + } + + // Get the lesson + Lesson lesson = toolSession.getLesson(); + + // Check the user's permissions, either learner or monitor + if (accessMode.equals(RedirectController.ACCESS_MODE_LEARNER)) { + if ((lesson == null) || !lesson.isLessonStarted()) { + return displayMessage(req, "message.lesson.not.started.cannot.participate"); + } + + // Check the learner is part of the group in question + if (!toolSession.getLearners().contains(getRealUser(user))) { + RedirectController.log.error("learner: User " + user.getLogin() + + " is not a learner in the requested group. Cannot access the lesson."); + return displayMessage(req, "error.authorisation"); + } + + } else if (accessMode.equals(RedirectController.ACCESS_MODE_TEACHER)) { + + // Check this is a monitor for the lesson in question + if ((lesson.getLessonClass() == null) || !lesson.getLessonClass().isStaffMember(getRealUser(user))) { + RedirectController.log.error("learner: User " + user.getLogin() + + " is not a learner in the requested lesson. Cannot access the lesson."); + return displayMessage(req, "error.authorisation"); + } + + } else { + throw new Exception("Mode " + accessMode + " is not allowed."); + } + + // If user has passed all the checks, they will get redirected + res.sendRedirect(Configuration.get(ConfigurationKeys.SERVER_URL) + relativePath); + + return null; + } catch (Exception e) { + RedirectController.log.error("Failed redirect to url", e); + return "errorContent"; + } + } + + private String displayMessage(HttpServletRequest req, String messageKey) { + req.setAttribute("messageKey", messageKey); + return "msgContent"; + } + + private UserDTO getUser() { + HttpSession ss = SessionManager.getSession(); + return (UserDTO) ss.getAttribute(AttributeNames.USER); + } + + private User getRealUser(UserDTO dto) { + return userService.getUserByLogin(dto.getLogin()); + } + + private ToolSession getToolSession(Long toolSessionID) { + return lamsToolService.getToolSession(toolSessionID); + } + +} \ No newline at end of file Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/web/TutorialAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/web/TutorialController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/TutorialController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/TutorialController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,160 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.web; + +import java.io.IOException; +import java.io.PrintWriter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Manages tutorial videos - the ones displayed on top of pages, explaining how to use certain features of LAMS. + * + * + */ +@Controller +@RequestMapping("/tutorial") +public class TutorialController { + private static Logger log = Logger.getLogger(TutorialController.class); + + @Autowired + @Qualifier("userManagementService") + private IUserManagementService service; + + /** + * Invoked when an user chose not to show a certain video again. + * + * @param mapping + * @param form + * @param req + * @param res + * @return + */ + @ResponseBody + @RequestMapping("/disableSingleTutorialVideo") + public void disableSingleTutorialVideo(HttpServletRequest req) { + + String pageString = WebUtil.readStrParam(req, AttributeNames.ATTR_PAGE_STR); + + HttpSession ss = SessionManager.getSession(); + UserDTO userDTO = (UserDTO) ss.getAttribute(AttributeNames.USER); + User user = service.getUserByLogin(userDTO.getLogin()); + + user.getPagesWithDisabledTutorials().add(pageString); + service.saveUser(user); + + ss.setAttribute(AttributeNames.USER, user.getUserDTO()); + + } + + /** + * Invoked when an user asked to show a certain video again. + * + * @param mapping + * @param form + * @param req + * @param res + * @return + */ + @ResponseBody + @RequestMapping("/enableSingleTutorialVideo") + public void enableSingleTutorialVideo(HttpServletRequest req) { + + String pageString = WebUtil.readStrParam(req, AttributeNames.ATTR_PAGE_STR); + + HttpSession ss = SessionManager.getSession(); + UserDTO userDTO = (UserDTO) ss.getAttribute(AttributeNames.USER); + User user = service.getUserByLogin(userDTO.getLogin()); + + user.getPagesWithDisabledTutorials().remove(pageString); + service.saveUser(user); + + ss.setAttribute(AttributeNames.USER, user.getUserDTO()); + } + + /** + * Gets the value for "Do not show again" checkbox for a cerain video. + * + * @param mapping + * @param form + * @param req + * @param res + * @return + * @throws IOException + */ + @ResponseBody + @RequestMapping("/getDoNotShowAgainValue") + public void getDoNotShowAgainValue(HttpServletRequest req, HttpServletResponse res) throws IOException { + + String pageString = WebUtil.readStrParam(req, AttributeNames.ATTR_PAGE_STR); + + HttpSession ss = SessionManager.getSession(); + UserDTO userDTO = (UserDTO) ss.getAttribute(AttributeNames.USER); + + Boolean doNotShowAgain = userDTO.getPagesWithDisabledTutorials() != null + && userDTO.getPagesWithDisabledTutorials().contains(pageString); + res.setContentType("text/plain"); + PrintWriter writer = res.getWriter(); + writer.println(doNotShowAgain.toString()); + } + + /** + * Turns off tutorials. Same as going to user profile and turning them off. Used for dialog displayed after user's + * first login. + * + * @param mapping + * @param form + * @param req + * @param res + * @return + * @throws IOException + */ + @ResponseBody + @RequestMapping("/disableAllTutorialVideos") + public void disableAllTutorialVideos(HttpServletRequest req) throws IOException { + + HttpSession ss = SessionManager.getSession(); + UserDTO userDTO = (UserDTO) ss.getAttribute(AttributeNames.USER); + User user = service.getUserByLogin(userDTO.getLogin()); + + user.setTutorialsDisabled(true); + service.saveUser(user); + + ss.setAttribute(AttributeNames.USER, user.getUserDTO()); + } +} \ No newline at end of file Index: lams_central/src/java/org/lamsfoundation/lams/web/UserForm.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/UserForm.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/UserForm.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,161 @@ +package org.lamsfoundation.lams.web; + +public class UserForm { + + private Integer userId; + private String login; + private String password; + private String title; + private String firstName; + private String lastName; + private String addressLine1; + private String addressLine2; + private String addressLine3; + private String city; + private String state; + private String postcode; + private String country; + private String dayPhone; + private String eveningPhone; + private String mobilePhone; + private String fax; + private String email; + private Integer localeId; + private String timeZone; + private Boolean tutorialsDisabled; + private Long userTheme; + public Integer getUserId() { + return userId; + } + public void setUserId(Integer userId) { + this.userId = userId; + } + public String getLogin() { + return login; + } + public void setLogin(String login) { + this.login = login; + } + public String getPassword() { + return password; + } + public void setPassword(String password) { + this.password = password; + } + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; + } + public String getFirstName() { + return firstName; + } + public void setFirstName(String firstName) { + this.firstName = firstName; + } + public String getLastName() { + return lastName; + } + public void setLastName(String lastName) { + this.lastName = lastName; + } + public String getAddressLine1() { + return addressLine1; + } + public void setAddressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + } + public String getAddressLine2() { + return addressLine2; + } + public void setAddressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + } + public String getAddressLine3() { + return addressLine3; + } + public void setAddressLine3(String addressLine3) { + this.addressLine3 = addressLine3; + } + public String getCity() { + return city; + } + public void setCity(String city) { + this.city = city; + } + public String getState() { + return state; + } + public void setState(String state) { + this.state = state; + } + public String getPostcode() { + return postcode; + } + public void setPostcode(String postcode) { + this.postcode = postcode; + } + public String getCountry() { + return country; + } + public void setCountry(String country) { + this.country = country; + } + public String getDayPhone() { + return dayPhone; + } + public void setDayPhone(String dayPhone) { + this.dayPhone = dayPhone; + } + public String getEveningPhone() { + return eveningPhone; + } + public void setEveningPhone(String eveningPhone) { + this.eveningPhone = eveningPhone; + } + public String getMobilePhone() { + return mobilePhone; + } + public void setMobilePhone(String mobilePhone) { + this.mobilePhone = mobilePhone; + } + public String getFax() { + return fax; + } + public void setFax(String fax) { + this.fax = fax; + } + public String getEmail() { + return email; + } + public void setEmail(String email) { + this.email = email; + } + public Integer getLocaleId() { + return localeId; + } + public void setLocaleId(Integer localeId) { + this.localeId = localeId; + } + public String getTimeZone() { + return timeZone; + } + public void setTimeZone(String timeZone) { + this.timeZone = timeZone; + } + public Boolean getTutorialsDisabled() { + return tutorialsDisabled; + } + public void setTutorialsDisabled(Boolean tutorialsDisabled) { + this.tutorialsDisabled = tutorialsDisabled; + } + public Long getUserTheme() { + return userTheme; + } + public void setUserTheme(Long userTheme) { + this.userTheme = userTheme; + } + + +} Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/webservice/PaintAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/webservice/PaintController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/webservice/PaintController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/PaintController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,114 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.webservice; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.Date; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.util.Base64StringToImageUtil; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author Paul Georges + * + * + * + * + * + * + * + * + * + * Currently this action class is unused, but we will retain it in the source for any future use + * with the Paint FCKEditor plugin. + * + */ +@Controller +@RequestMapping("/Paint") +public class PaintController { + + private static Logger logger = Logger.getLogger(PaintController.class); + + /** + * @deprecated + */ + @Deprecated + @ResponseBody + @RequestMapping(path = "/saveImage", method = RequestMethod.POST) + public void saveImage(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException { + try { + String toolContentId = WebUtil.readStrParam(request, "toolContentId"); + String userId = WebUtil.readStrParam(request, "userId"); + String data = WebUtil.readStrParam(request, "data"); + + Date today = new Date(); + String filename = String.valueOf(today.getTime()); + String dir = File.separator + "lams-www.war" + File.separator + "secure" + File.separator + toolContentId + + File.separator + "Paint" + File.separator + userId + File.separator; + + String absoluteFilePath = dir + filename + ".png"; + + File newPath = new File(dir); + newPath.mkdirs(); + + File newFile = new File(absoluteFilePath); + newFile.createNewFile(); + + boolean success = Base64StringToImageUtil.create(dir, filename, "png", data); + + if (success) { + response.setContentType("text/html;charset=utf-8"); + PrintWriter writer = response.getWriter(); + + if (absoluteFilePath.length() > 0) { + writer.println(absoluteFilePath); + } + } else { + response.setContentType("text/html;charset=utf-8"); + PrintWriter writer = response.getWriter(); + ; + } + + } catch (Exception e) { + response.setContentType("text/html;charset=utf-8"); + PrintWriter writer = response.getWriter(); + + if (e.getMessage().length() > 0) { + writer.println(e.getMessage()); + } + } + + } +} Index: lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java (.../LearningDesignRepositoryServlet.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/src/java/org/lamsfoundation/lams/webservice/xml/LearningDesignRepositoryServlet.java (.../LearningDesignRepositoryServlet.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -44,7 +44,7 @@ import org.lamsfoundation.lams.util.WebUtil; import org.lamsfoundation.lams.workspace.dto.FolderContentDTO; import org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService; -import org.lamsfoundation.lams.workspace.web.WorkspaceAction; +import org.lamsfoundation.lams.workspace.web.WorkspaceController; import org.springframework.web.context.support.WebApplicationContextUtils; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -171,15 +171,15 @@ FolderContentDTO rootFolder = new FolderContentDTO( LearningDesignRepositoryServlet.msgService.getMessage("label.workspace.root_folder"), LearningDesignRepositoryServlet.msgService.getMessage("folder"), null, null, FolderContentDTO.FOLDER, - WorkspaceAction.BOOTSTRAP_FOLDER_ID.longValue(), WorkspaceFolder.READ_ACCESS, null); + WorkspaceController.BOOTSTRAP_FOLDER_ID.longValue(), WorkspaceFolder.READ_ACCESS, null); ContentTreeNode root = new ContentTreeNode(rootFolder); FolderContentDTO userFolder = LearningDesignRepositoryServlet.service.getUserWorkspaceFolder(userId); root.addChild(buildContentTreeNode(userFolder, userId, mode)); FolderContentDTO dummyOrgFolder = new FolderContentDTO( LearningDesignRepositoryServlet.msgService.getMessage("organisations"), LearningDesignRepositoryServlet.msgService.getMessage("folder"), null, null, FolderContentDTO.FOLDER, - new Long(WorkspaceAction.ORG_FOLDER_ID.longValue()), WorkspaceFolder.READ_ACCESS, null); + new Long(WorkspaceController.ORG_FOLDER_ID.longValue()), WorkspaceFolder.READ_ACCESS, null); ContentTreeNode dummyOrgNode = new ContentTreeNode(dummyOrgFolder); // tried using service.getAccessibleOrganisationWorkspaceFolders(userId) // api, Index: lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java (.../WorkspaceManagementService.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/src/java/org/lamsfoundation/lams/workspace/service/WorkspaceManagementService.java (.../WorkspaceManagementService.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -55,7 +55,7 @@ import org.lamsfoundation.lams.util.MessageService; import org.lamsfoundation.lams.workspace.WorkspaceFolderContent; import org.lamsfoundation.lams.workspace.dto.FolderContentDTO; -import org.lamsfoundation.lams.workspace.web.WorkspaceAction; +import org.lamsfoundation.lams.workspace.web.WorkspaceController; import org.springframework.web.util.HtmlUtils; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -368,7 +368,7 @@ FolderContentDTO myGroupsFolder = new FolderContentDTO(messageService.getMessage("organisations"), messageService.getMessage("folder"), null, null, FolderContentDTO.FOLDER, - WorkspaceAction.ORG_FOLDER_ID.longValue(), WorkspaceFolder.READ_ACCESS, null); + WorkspaceController.ORG_FOLDER_ID.longValue(), WorkspaceFolder.READ_ACCESS, null); folderContents.add(myGroupsFolder); @@ -384,14 +384,14 @@ } // else we want to return an empty JSON, which will be done by falling through to the folderContents loop. // special behaviour for organisation folders - } else if (folderID.equals(WorkspaceAction.ORG_FOLDER_ID)) { + } else if (folderID.equals(WorkspaceController.ORG_FOLDER_ID)) { folderContents = getAccessibleOrganisationWorkspaceFolders(userID); Collections.sort(folderContents); if (folderContents.size() == 1) { FolderContentDTO folder = folderContents.firstElement(); - if (folder.getResourceID().equals(WorkspaceAction.ROOT_ORG_FOLDER_ID)) { - return getFolderContentsJSON(WorkspaceAction.ROOT_ORG_FOLDER_ID, userID, allowInvalidDesigns); + if (folder.getResourceID().equals(WorkspaceController.ROOT_ORG_FOLDER_ID)) { + return getFolderContentsJSON(WorkspaceController.ROOT_ORG_FOLDER_ID, userID, allowInvalidDesigns); } } } else { Fisheye: Tag 792f30e164500b758d9eeac2dcf19853be4dfd9f refers to a dead (removed) revision in file `lams_central/src/java/org/lamsfoundation/lams/workspace/web/WorkspaceAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_central/src/java/org/lamsfoundation/lams/workspace/web/WorkspaceController.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/workspace/web/WorkspaceController.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/workspace/web/WorkspaceController.java (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -0,0 +1,216 @@ +/**************************************************************** + * Copyright (C) 2005 LAMS Foundation (http://lamsfoundation.org) + * ============================================================= + * License Information: http://lamsfoundation.org/licensing/lams/2.0/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2.0 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA + * + * http://www.gnu.org/licenses/gpl.txt + * **************************************************************** + */ + +package org.lamsfoundation.lams.workspace.web; + +import java.io.IOException; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.learningdesign.exception.LearningDesignException; +import org.lamsfoundation.lams.usermanagement.WorkspaceFolder; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.exception.UserException; +import org.lamsfoundation.lams.usermanagement.exception.WorkspaceFolderException; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.lamsfoundation.lams.workspace.dto.FolderContentDTO; +import org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * @author Manpreet Minhas + * + * + */ +@Controller +@RequestMapping("/workspace") +public class WorkspaceController { + + protected Logger log = Logger.getLogger(WorkspaceController.class.getName()); + + @Autowired + @Qualifier("IWorkspaceManagementService") + private IWorkspaceManagementService workspaceManagementService; + + public static final String RESOURCE_ID = "resourceID"; + public static final String RESOURCE_TYPE = "resourceType"; + public static final String ROLE_DELIMITER = ","; + /** + * Special value for folderID on getFolderContents(). Triggers getting the dummy value for the organisations (see + * ORG_FOLDER_ID) and the user's private folder. See the method for more details. + */ + public static final Integer BOOTSTRAP_FOLDER_ID = new Integer(-1); + + /** + * Special value for folderID on getFolderContents(). Triggers getting the organisation folders that are available + * to a user. See the method for more details. + */ + public static final Integer ORG_FOLDER_ID = new Integer(-2); + + public static final Integer ROOT_ORG_FOLDER_ID = new Integer(1); + + private Integer getUserId() { + // return new Integer(WebUtil.readIntParam(request,AttributeNames.PARAM_USER_ID)); + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user != null ? user.getUserID() : null; + } + + /** + * Is the folder id one of our special dummy ids? If so, we can't process the normal create, copy, paste, move + * functions on this folder. + */ + private boolean checkResourceDummyValue(Long folderID, String resourceType) throws IOException { + return FolderContentDTO.FOLDER.equals(resourceType) && (WorkspaceController.BOOTSTRAP_FOLDER_ID.equals(folderID) + || WorkspaceController.ORG_FOLDER_ID.equals(folderID)); + } + + /** + * For details please refer to org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService + * + * @param mapping + * @param form + * @param request + * @param response + * @return ActionForward + * @throws ServletException + * @throws IOException + * @throws WorkspaceFolderException + * @throws UserException + */ + @ResponseBody + @RequestMapping("/createFolder") + public void createFolder(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException, UserException, WorkspaceFolderException { + Integer parentFolderID = WebUtil.readIntParam(request, "parentFolderID", false); + String folderName = WebUtil.readStrParam(request, "name", false); + Integer userID = getUserId(); + WorkspaceFolder newFolder = workspaceManagementService.createFolder(parentFolderID, folderName, userID); + response.setContentType("text/plain;charset=utf-8"); + response.getWriter().write(newFolder.getWorkspaceFolderId().toString()); + } + + /** + * For details please refer to org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService + * + * @param mapping + * @param form + * @param request + * @param response + * @return ActionForward + * @throws ServletException + * @throws IOException + */ + @ResponseBody + @RequestMapping("/deleteResource") + public void deleteResource(HttpServletRequest request) throws ServletException, IOException { + Long resourceID = new Long(WebUtil.readLongParam(request, WorkspaceController.RESOURCE_ID)); + String resourceType = WebUtil.readStrParam(request, WorkspaceController.RESOURCE_TYPE); + + boolean isDummyValue = checkResourceDummyValue(resourceID, FolderContentDTO.FOLDER); + if (isDummyValue) { + throw new IOException("Can not remove this resource."); + } + + workspaceManagementService.deleteResource(resourceID, resourceType, getUserId()); + } + + /** + * For details please refer to org.lamsfoundation.lams.workspace.service.IWorkspaceManagementService + * + * @param mapping + * @param form + * @param request + * @param response + * @return ActionForward + * @throws ServletException + * @throws IOException + * @throws WorkspaceFolderException + * @throws UserException + * @throws LearningDesignException + */ + @ResponseBody + @RequestMapping("/copyResource") + public void copyResource(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException, LearningDesignException, UserException, WorkspaceFolderException { + Long resourceID = WebUtil.readLongParam(request, WorkspaceController.RESOURCE_ID, false); + String resourceType = WebUtil.readStrParam(request, WorkspaceController.RESOURCE_TYPE, false); + Integer targetFolderID = WebUtil.readIntParam(request, "targetFolderID", false); + + if (targetFolderID == null) { + log.error("Can not copy resource, missing target folder ID"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing target folder ID"); + } + + Integer copyType = WebUtil.readIntParam(request, "copyType", true); + Integer userID = getUserId(); + workspaceManagementService.copyResource(resourceID, resourceType, copyType, targetFolderID, userID); + } + + @ResponseBody + @RequestMapping("/moveResource") + public void moveResource(HttpServletRequest request, HttpServletResponse response) throws IOException { + Long resourceID = WebUtil.readLongParam(request, WorkspaceController.RESOURCE_ID, false); + String resourceType = WebUtil.readStrParam(request, WorkspaceController.RESOURCE_TYPE, false); + Integer targetFolderID = WebUtil.readIntParam(request, "targetFolderID", false); + + if (targetFolderID == null) { + log.error("Can not move resource, missing target folder ID"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing target folder ID"); + } + + try { + workspaceManagementService.moveResource(resourceID, resourceType, targetFolderID); + } catch (WorkspaceFolderException e) { + log.error("Error while moving a resource", e); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Error while moving a resource"); + } + } + + @ResponseBody + @RequestMapping("/renameResource") + public void renameResource(HttpServletRequest request, HttpServletResponse response) + throws IOException, ServletException, UserException, WorkspaceFolderException { + Integer userID = getUserId(); + Long resourceID = new Long(WebUtil.readLongParam(request, WorkspaceController.RESOURCE_ID)); + String resourceType = WebUtil.readStrParam(request, WorkspaceController.RESOURCE_TYPE); + + boolean isDummyValue = checkResourceDummyValue(resourceID, FolderContentDTO.FOLDER); + if (isDummyValue) { + throw new IOException("Can not rename this resource"); + } + String name = WebUtil.readStrParam(request, "name"); + workspaceManagementService.renameResource(resourceID, resourceType, name, userID); + + } +} \ No newline at end of file Index: lams_central/web/comments/msgview.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/comments/msgview.jsp (.../msgview.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/comments/msgview.jsp (.../msgview.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -124,12 +124,12 @@ comments/hide.do?sessionMapID=${sessionMapID}&commentUid=${commentDto.comment.uid}&hideFlag=false - + comments/hide.do?sessionMapID=${sessionMapID}&commentUid=${commentDto.comment.uid}&hideFlag=true - + · Index: lams_central/web/errorContent.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/errorContent.jsp (.../errorContent.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/errorContent.jsp (.../errorContent.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,5 +1,25 @@ +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> + + +<%@ taglib uri="tags-lams" prefix="lams" %> <%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> + + + + + <fmt:message key="heading.general.error" /> + + + + + + + + + +
@@ -11,3 +31,10 @@
+ +
+ +
+ + + Index: lams_central/web/msgContent.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/msgContent.jsp (.../msgContent.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/msgContent.jsp (.../msgContent.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,5 +1,25 @@ +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> + + +<%@ taglib uri="tags-lams" prefix="lams" %> <%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> + + + + + <fmt:message key ="heading.general.error" /> + + + + + + + + + +
@@ -10,3 +30,8 @@
+
+ +
+ + Index: lams_central/web/passwordChangeContent.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/passwordChangeContent.jsp (.../passwordChangeContent.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/passwordChangeContent.jsp (.../passwordChangeContent.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,9 +1,7 @@ <%@ page contentType="text/html; charset=utf-8" language="java"%> -<%@ taglib uri="tags-html" prefix="html"%> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <%@ taglib uri="tags-core" prefix="c"%> -<%@ taglib uri="tags-bean" prefix="bean"%> -<%@ taglib uri="tags-logic" prefix="logic"%> <%@ taglib uri="tags-fmt" prefix="fmt"%> <%@ taglib uri="tags-lams" prefix="lams"%> <%@ page import="org.apache.struts.action.ActionMessages" @@ -97,7 +95,7 @@ -
+
@@ -109,11 +107,14 @@
+ +

- + +
-
@@ -155,9 +156,9 @@
" formnovalidate="formnovalidate" onclick="bCancel=true;" id="cancelButton" class="btn btn-sm btn-default voffset5"/>    - +
@@ -166,6 +167,6 @@
- +
Index: lams_central/web/portrait.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/portrait.jsp (.../portrait.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/portrait.jsp (.../portrait.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,12 +1,10 @@ <%@ page contentType="text/html; charset=utf-8" language="java"%> -<%@ taglib uri="tags-html" prefix="html"%> <%@ taglib uri="tags-core" prefix="c"%> -<%@ taglib uri="tags-bean" prefix="bean"%> -<%@ taglib uri="tags-logic" prefix="logic"%> <%@ taglib uri="tags-fmt" prefix="fmt"%> <%@ taglib uri="tags-lams" prefix="lams"%> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> @@ -126,8 +124,8 @@ - - + +
@@ -231,6 +229,6 @@
-
+
Index: lams_central/web/questions/questionFile.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/questions/questionFile.jsp (.../questionFile.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/questions/questionFile.jsp (.../questionFile.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -58,15 +58,17 @@ + + + + + +
+
+
+
+ - - - -
-
-
-
-
Index: lams_central/web/signup/loginTab.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/signup/loginTab.jsp (.../loginTab.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/signup/loginTab.jsp (.../loginTab.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,10 +1,10 @@ - + - - - - + + + +
: - - + + + + + +
+
+
+
: - + + + + +
+
+
+
+
: - +
- +
- +
Index: lams_central/web/signup/signup.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/signup/signup.jsp (.../signup.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/signup/signup.jsp (.../signup.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,9 +1,8 @@ <%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%> -<%@ taglib uri="tags-html" prefix="html"%> <%@ taglib uri="tags-lams" prefix="lams"%> <%@ taglib uri="tags-fmt" prefix="fmt"%> <%@ taglib uri="tags-core" prefix="c"%> - +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> Index: lams_central/web/signup/singupTab.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/signup/singupTab.jsp (.../singupTab.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/signup/singupTab.jsp (.../singupTab.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,10 +1,7 @@ <%@ page import="org.lamsfoundation.lams.util.Configuration"%> <%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys"%> -<%@ taglib uri="tags-html" prefix="html"%> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <%@ taglib uri="tags-core" prefix="c"%> -<%@ taglib uri="tags-bean" prefix="bean"%> -<%@ taglib uri="tags-logic" prefix="logic"%> -<%@ taglib uri="tags-fmt" prefix="fmt"%> <%@ taglib uri="tags-lams" prefix="lams"%> <%=Configuration.get(ConfigurationKeys.PASSWORD_POLICY_MINIMUM_CHARACTERS)%> Index: lams_central/web/signup/successfulSignup.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/signup/successfulSignup.jsp (.../successfulSignup.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/signup/successfulSignup.jsp (.../successfulSignup.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,9 +1,26 @@ -<%@ taglib uri="tags-lams" prefix="lams"%> -<%@ taglib uri="tags-fmt" prefix="fmt"%> +<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> + + +<%@ taglib uri="tags-lams" prefix="lams" %> +<%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> <%@ taglib uri="tags-core" prefix="c"%> -<%@ taglib uri="tags-html" prefix="html"%> -<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%> + + + + + <fmt:message key="title.lams.signup" /> + + + + + + + + + + @@ -28,6 +45,11 @@

+
+ +
+ + Index: lams_central/web/template.jsp =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_central/web/template.jsp (.../template.jsp) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_central/web/template.jsp (.../template.jsp) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -1,21 +1,21 @@ <%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8" %> -<%@ taglib uri="tags-tiles" prefix="tiles" %> -<%@ taglib uri="tags-html" prefix="html" %> + <%@ taglib uri="tags-lams" prefix="lams" %> <%@ taglib uri="tags-fmt" prefix="fmt" %> +<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %> - + <fmt:message><tiles:getAsString name="titleKey"/></fmt:message> - + - + Index: lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/web/action/ClearSessionAction.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/web/action/ClearSessionAction.java (.../ClearSessionAction.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_tool_assessment/src/java/org/lamsfoundation/lams/tool/assessment/web/action/ClearSessionAction.java (.../ClearSessionAction.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.tool.assessment.web.action; import javax.servlet.http.HttpSession; Index: lams_tool_bbb/src/java/org/lamsfoundation/lams/tool/bbb/web/actions/ClearSessionAction.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_bbb/src/java/org/lamsfoundation/lams/tool/bbb/web/actions/ClearSessionAction.java (.../ClearSessionAction.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_tool_bbb/src/java/org/lamsfoundation/lams/tool/bbb/web/actions/ClearSessionAction.java (.../ClearSessionAction.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.tool.bbb.web.actions; import javax.servlet.http.HttpSession; Index: lams_tool_daco/src/java/org/lamsfoundation/lams/tool/daco/web/controller/ClearSessionController.java =================================================================== diff -u -r5d60e2334cf6775f4e4afe5755a0e56ef78540c0 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_daco/src/java/org/lamsfoundation/lams/tool/daco/web/controller/ClearSessionController.java (.../ClearSessionController.java) (revision 5d60e2334cf6775f4e4afe5755a0e56ef78540c0) +++ lams_tool_daco/src/java/org/lamsfoundation/lams/tool/daco/web/controller/ClearSessionController.java (.../ClearSessionController.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.tool.daco.web.controller; import java.io.IOException; @@ -30,7 +29,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishAction; import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishController; import org.lamsfoundation.lams.tool.ToolAccessMode; import org.springframework.beans.factory.annotation.Autowired; @@ -40,7 +38,7 @@ /** * This class give a chance to clear HttpSession when user save/close authoring page. - * + * * @author Steve.Ni */ @Controller Index: lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/AuthoringController.java =================================================================== diff -u -rf32bc3c30b8ea0463d84b4dbdc112f77a400297a -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/AuthoringController.java (.../AuthoringController.java) (revision f32bc3c30b8ea0463d84b4dbdc112f77a400297a) +++ lams_tool_forum/src/java/org/lamsfoundation/lams/tool/forum/web/controller/AuthoringController.java (.../AuthoringController.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -45,7 +45,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; import org.apache.log4j.Logger; -import org.lamsfoundation.lams.authoring.web.AuthoringController; import org.lamsfoundation.lams.authoring.web.AuthoringConstants; import org.lamsfoundation.lams.learningdesign.TextSearchConditionComparator; import org.lamsfoundation.lams.tool.ToolAccessMode; Index: lams_tool_gmap/src/java/org/lamsfoundation/lams/tool/gmap/web/actions/ClearSessionAction.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_gmap/src/java/org/lamsfoundation/lams/tool/gmap/web/actions/ClearSessionAction.java (.../ClearSessionAction.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_tool_gmap/src/java/org/lamsfoundation/lams/tool/gmap/web/actions/ClearSessionAction.java (.../ClearSessionAction.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.tool.gmap.web.actions; import javax.servlet.http.HttpSession; @@ -31,12 +30,12 @@ /** * This class give a chance to clear HttpSession when user save/close authoring page. - * + * * @author lfoxton * * * - * + * * @version $Revision$ */ public class ClearSessionAction extends LamsAuthoringFinishAction { Index: lams_tool_kaltura/src/java/org/lamsfoundation/lams/tool/kaltura/web/controller/ClearSessionController.java =================================================================== diff -u -rff911101cbe92d6813691c20c292fa04519820b4 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_kaltura/src/java/org/lamsfoundation/lams/tool/kaltura/web/controller/ClearSessionController.java (.../ClearSessionController.java) (revision ff911101cbe92d6813691c20c292fa04519820b4) +++ lams_tool_kaltura/src/java/org/lamsfoundation/lams/tool/kaltura/web/controller/ClearSessionController.java (.../ClearSessionController.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.tool.kaltura.web.controller; import java.io.IOException; @@ -30,7 +29,6 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishAction; import org.lamsfoundation.lams.authoring.web.LamsAuthoringFinishController; import org.lamsfoundation.lams.tool.ToolAccessMode; import org.springframework.beans.factory.annotation.Autowired; Index: lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/web/action/ClearSessionAction.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/web/action/ClearSessionAction.java (.../ClearSessionAction.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_tool_preview/src/java/org/lamsfoundation/lams/tool/peerreview/web/action/ClearSessionAction.java (.../ClearSessionAction.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -21,7 +21,6 @@ * **************************************************************** */ - package org.lamsfoundation.lams.tool.peerreview.web.action; import javax.servlet.http.HttpSession; Index: lams_tool_wiki/src/java/org/lamsfoundation/lams/tool/wiki/web/controller/PedagogicalPlannerController.java =================================================================== diff -u -rf32bc3c30b8ea0463d84b4dbdc112f77a400297a -r792f30e164500b758d9eeac2dcf19853be4dfd9f --- lams_tool_wiki/src/java/org/lamsfoundation/lams/tool/wiki/web/controller/PedagogicalPlannerController.java (.../PedagogicalPlannerController.java) (revision f32bc3c30b8ea0463d84b4dbdc112f77a400297a) +++ lams_tool_wiki/src/java/org/lamsfoundation/lams/tool/wiki/web/controller/PedagogicalPlannerController.java (.../PedagogicalPlannerController.java) (revision 792f30e164500b758d9eeac2dcf19853be4dfd9f) @@ -33,7 +33,6 @@ import org.lamsfoundation.lams.tool.wiki.service.IWikiService; import org.lamsfoundation.lams.tool.wiki.web.forms.WikiPedagogicalPlannerForm; import org.lamsfoundation.lams.util.WebUtil; -import org.lamsfoundation.lams.web.planner.PedagogicalPlannerController; import org.lamsfoundation.lams.web.util.AttributeNames; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier;