Index: lams_admin/src/java/org/lamsfoundation/lams/admin/service/IImportService.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 --- lams_admin/src/java/org/lamsfoundation/lams/admin/service/IImportService.java (.../IImportService.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/service/IImportService.java (.../IImportService.java) (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -26,7 +26,7 @@ import java.io.IOException; import java.util.List; -import org.apache.struts.upload.FormFile; +import org.springframework.web.multipart.MultipartFile; /** *

@@ -49,65 +49,65 @@ /** * Returns true if spreadsheet contains user data. - * + * * @param fileItem * @return * @throws IOException */ - public boolean isUserSpreadsheet(FormFile fileItem) throws IOException; + public boolean isUserSpreadsheet(MultipartFile fileItem) throws IOException; /** * Returns true if spreadsheet contains userorgrole data. - * + * * @param fileItem * @return * @throws IOException */ - public boolean isRolesSpreadsheet(FormFile fileItem) throws IOException; + public boolean isRolesSpreadsheet(MultipartFile fileItem) throws IOException; /** * Checks first row of spreadsheet and determines whether to parse as * a user or orgrole spreadsheet. - * + * * @param fileItem * @throws IOException */ - public List parseSpreadsheet(FormFile fileItem, String sessionId) throws IOException; + public List parseSpreadsheet(MultipartFile fileItem, String sessionId) throws IOException; /** - * + * * @param fileItem * @return * @throws IOException */ - public List parseGroupSpreadsheet(FormFile fileItem, String sessionId) throws IOException; + public List parseGroupSpreadsheet(MultipartFile fileItem, String sessionId) throws IOException; /** * Returns number of rows found in spreadsheet. - * + * * @param fileItem * @return * @throws IOException */ - public int getNumRows(FormFile fileItem) throws IOException; + public int getNumRows(MultipartFile fileItem) throws IOException; /** * Returns message results from parsing list of users in spreadsheet. - * + * * @param file * @param sessionId * @return * @throws IOException */ - public List parseUserSpreadsheet(FormFile file, String sessionId) throws IOException; + public List parseUserSpreadsheet(MultipartFile file, String sessionId) throws IOException; /** * Returns message results from parsing list of organisation memberships. - * + * * @param file * @param sessionId * @return * @throws IOException */ - public List parseRolesSpreadsheet(FormFile file, String sessionId) throws IOException; + public List parseRolesSpreadsheet(MultipartFile file, String sessionId) throws IOException; } Index: lams_admin/src/java/org/lamsfoundation/lams/admin/service/ImportService.java =================================================================== diff -u -r7475d08afc280b5e2e5ddf04e8bf35e3166aaf80 -re2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 --- lams_admin/src/java/org/lamsfoundation/lams/admin/service/ImportService.java (.../ImportService.java) (revision 7475d08afc280b5e2e5ddf04e8bf35e3166aaf80) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/service/ImportService.java (.../ImportService.java) (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -37,7 +37,6 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.usermodel.Cell; -import org.apache.struts.upload.FormFile; import org.lamsfoundation.lams.logevent.LogEvent; import org.lamsfoundation.lams.logevent.service.ILogEventService; import org.lamsfoundation.lams.themes.Theme; @@ -56,6 +55,7 @@ import org.lamsfoundation.lams.util.ValidationUtil; import org.lamsfoundation.lams.web.session.SessionManager; import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.web.multipart.MultipartFile; /** *

@@ -133,36 +133,36 @@ private static final short ADMIN_CHANGE_STATUS = 7; // class-wide variables - ArrayList results = new ArrayList(); - ArrayList rowResult = new ArrayList(); + ArrayList results = new ArrayList<>(); + ArrayList rowResult = new ArrayList<>(); private boolean emptyRow; private boolean hasError; private Organisation parentOrg; - private HSSFSheet getSheet(FormFile fileItem) throws IOException { + private HSSFSheet getSheet(MultipartFile fileItem) throws IOException { POIFSFileSystem fs = new POIFSFileSystem(fileItem.getInputStream()); HSSFWorkbook wb = new HSSFWorkbook(fs); return wb.getSheetAt(0); } @Override - public boolean isUserSpreadsheet(FormFile fileItem) throws IOException { + public boolean isUserSpreadsheet(MultipartFile fileItem) throws IOException { HSSFSheet sheet = getSheet(fileItem); HSSFRow row = sheet.getRow(sheet.getFirstRowNum()); String string = parseStringCell(row.getCell(ImportService.PASSWORD)); return (StringUtils.equals(string, "* password")) ? true : false; } @Override - public boolean isRolesSpreadsheet(FormFile fileItem) throws IOException { + public boolean isRolesSpreadsheet(MultipartFile fileItem) throws IOException { HSSFSheet sheet = getSheet(fileItem); HSSFRow row = sheet.getRow(sheet.getFirstRowNum()); String string = parseStringCell(row.getCell(ImportService.ORGANISATION)); return (StringUtils.equals(string, "* organisation")) ? true : false; } @Override - public List parseSpreadsheet(FormFile fileItem, String sessionId) throws IOException { + public List parseSpreadsheet(MultipartFile fileItem, String sessionId) throws IOException { if (isUserSpreadsheet(fileItem)) { return parseUserSpreadsheet(fileItem, sessionId); } else if (isRolesSpreadsheet(fileItem)) { @@ -175,8 +175,8 @@ // each item in the list lists the id, name, and parent's id of that org; otherwise // the items in the list are error messages. @Override - public List parseGroupSpreadsheet(FormFile fileItem, String sessionId) throws IOException { - results = new ArrayList(); + public List parseGroupSpreadsheet(MultipartFile fileItem, String sessionId) throws IOException { + results = new ArrayList<>(); parentOrg = service.getRootOrganisation(); HSSFSheet sheet = getSheet(fileItem); int startRow = sheet.getFirstRowNum(); @@ -191,7 +191,7 @@ for (int i = startRow + 1; i < (endRow + 1); i++) { emptyRow = true; hasError = false; - rowResult = new ArrayList(); + rowResult = new ArrayList<>(); row = sheet.getRow(i); if (row != null) { org = parseGroup(row, i); @@ -297,16 +297,16 @@ } @Override - public int getNumRows(FormFile fileItem) throws IOException { + public int getNumRows(MultipartFile fileItem) throws IOException { HSSFSheet sheet = getSheet(fileItem); int startRow = sheet.getFirstRowNum(); int endRow = sheet.getLastRowNum(); return endRow - startRow; } @Override - public List parseUserSpreadsheet(FormFile fileItem, String sessionId) throws IOException { - results = new ArrayList(); + public List parseUserSpreadsheet(MultipartFile fileItem, String sessionId) throws IOException { + results = new ArrayList<>(); HSSFSheet sheet = getSheet(fileItem); int startRow = sheet.getFirstRowNum(); int endRow = sheet.getLastRowNum(); @@ -322,7 +322,7 @@ for (int i = startRow + 1; i < (endRow + 1); i++) { emptyRow = true; hasError = false; - rowResult = new ArrayList(); + rowResult = new ArrayList<>(); row = sheet.getRow(i); user = parseUser(row, i); @@ -376,8 +376,8 @@ } @Override - public List parseRolesSpreadsheet(FormFile fileItem, String sessionId) throws IOException { - results = new ArrayList(); + public List parseRolesSpreadsheet(MultipartFile fileItem, String sessionId) throws IOException { + results = new ArrayList<>(); HSSFSheet sheet = getSheet(fileItem); int startRow = sheet.getFirstRowNum(); int endRow = sheet.getLastRowNum(); @@ -393,7 +393,7 @@ for (int i = startRow + 1; i < (endRow + 1); i++) { emptyRow = true; hasError = false; - rowResult = new ArrayList(); + rowResult = new ArrayList<>(); row = sheet.getRow(i); String login = parseStringCell(row.getCell(ImportService.LOGIN)); @@ -711,7 +711,7 @@ ImportService.log.error("Caught exception when reading roles in spreadsheet: " + e.getMessage()); return null; } - List roles = new ArrayList(); + List roles = new ArrayList<>(); int fromIndex = 0; int index = roleDescription.indexOf(IImportService.SEPARATOR, fromIndex); while (index != -1) { @@ -751,7 +751,7 @@ // return false if a role shouldn't be assigned in given org type private boolean checkValidRoles(List idList, boolean isSysadmin, OrganisationType orgType) { // convert list of id's into list of Roles - List roleList = new ArrayList(); + List roleList = new ArrayList<>(); for (String id : idList) { Role role = (Role) service.findById(Role.class, Integer.parseInt(id)); if (role != null) { Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupTempFilesController.java =================================================================== diff -u -r550e1b37b507779064955267ef47e9085f791357 -re2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupTempFilesController.java (.../CleanupTempFilesController.java) (revision 550e1b37b507779064955267ef47e9085f791357) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CleanupTempFilesController.java (.../CleanupTempFilesController.java) (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -29,7 +29,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.apache.struts.Globals; import org.lamsfoundation.lams.admin.web.form.CleanupForm; import org.lamsfoundation.lams.usermanagement.Role; import org.lamsfoundation.lams.util.FileUtil; @@ -77,7 +76,7 @@ return "error"; } - if (request.getAttribute(Globals.CANCEL_KEY) != null) { + if (request.getAttribute("CANCEL") != null) { return "redirect:/sysadminstart.do"; } Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CloneLessonsController.java =================================================================== diff -u -r550e1b37b507779064955267ef47e9085f791357 -re2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CloneLessonsController.java (.../CloneLessonsController.java) (revision 550e1b37b507779064955267ef47e9085f791357) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/CloneLessonsController.java (.../CloneLessonsController.java) (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -32,8 +32,6 @@ import org.apache.commons.lang.StringUtils; import org.apache.log4j.Logger; -import org.apache.struts.action.ActionForm; -import org.apache.struts.action.ActionMapping; import org.lamsfoundation.lams.admin.service.AdminServiceProxy; import org.lamsfoundation.lams.lesson.Lesson; import org.lamsfoundation.lams.lesson.service.ILessonService; @@ -76,8 +74,7 @@ private WebApplicationContext applicationContext; @RequestMapping("/start") - public String execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, - HttpServletResponse response) throws UserAccessDeniedException { + public String execute(HttpServletRequest request, HttpServletResponse response) throws UserAccessDeniedException { if (!(request.isUserInRole(Role.SYSADMIN))) { throw new UserAccessDeniedException(); Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ConfigAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ConfigController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ConfigController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ConfigController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,140 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.ConfigForm; +import org.lamsfoundation.lams.config.ConfigurationItem; +import org.lamsfoundation.lams.util.Configuration; +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.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * ConfigAction + * + * @author Mitchell Seaton + */ +/** + * + * + * + * + * + */ +@Controller +@RequestMapping("/config") +public class ConfigController { + + private static Configuration configurationService; + + @Autowired + private WebApplicationContext applicationContext; + + @Autowired + @Qualifier("adminMessageService") + private MessageService adminMessageService; + + private Configuration getConfiguration() { + if (configurationService == null) { + configurationService = AdminServiceProxy.getConfiguration(applicationContext.getServletContext()); + } + return configurationService; + } + + @RequestMapping("/start") + public String unspecified(HttpServletRequest request) throws Exception { + + request.setAttribute("config", getConfiguration().arrangeItems(Configuration.ITEMS_NON_LDAP)); + + return "config/editconfig"; + } + + @RequestMapping("/save") + public String save(@ModelAttribute ConfigForm configForm, HttpServletRequest request) throws Exception { + + if (request.getAttribute("CANCEL") != null) { + return "redirect:/sysadminstart.do"; + } + + String[] keys = configForm.getKey(); + String[] values = configForm.getValue(); + + String errorForward = "config"; + + for (int i = 0; i < keys.length; i++) { + ConfigurationItem item = getConfiguration().getConfigItemByKey(keys[i]); + + if (item != null) { + // return to ldap page if that's where we came from + if (StringUtils.contains(item.getHeaderName(), "config.header.ldap")) { + errorForward = "ldap"; + } + + if (item.getRequired()) { + if (!(values[i] != null && values[i].length() > 0)) { + request.setAttribute("error", getRequiredError(item.getDescriptionKey())); + request.setAttribute("config", getConfiguration().arrangeItems(Configuration.ITEMS_NON_LDAP)); + return mapping.findForward(errorForward); + } + } + String format = item.getFormat(); + if (format != null && format.equals(ConfigurationItem.LONG_FORMAT)) { + try { + Long.parseLong(values[i]); + } catch (NumberFormatException e) { + request.setAttribute("error", getNumericError(item.getDescriptionKey())); + request.setAttribute("config", getConfiguration().arrangeItems(Configuration.ITEMS_NON_LDAP)); + return mapping.findForward(errorForward); + } + } + Configuration.updateItem(keys[i], values[i]); + } + } + getConfiguration().persistUpdate(); + + Configuration.refreshCache(); + + return "redirect:/sysadminstart.do"; + } + + private String getRequiredError(String arg) { + String[] args = new String[1]; + args[0] = adminMessageService.getMessage(arg); + return adminMessageService.getMessage("error.required", args); + } + + private String getNumericError(String arg) { + String[] args = new String[1]; + args[0] = adminMessageService.getMessage(arg); + return adminMessageService.getMessage("error.numeric", args); + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/DisabledUserManageAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/DisabledUserManageController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/DisabledUserManageController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/DisabledUserManageController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,79 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +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.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author jliew + * + * + * + * + */ +@Controller +public class DisabledUserManageController { + + private static final Logger log = Logger.getLogger(DisabledUserManageController.class); + + @Autowired + private WebApplicationContext applicationContext; + + @Autowired + @Qualifier("adminMessageService") + private MessageService adminMessageService; + + @RequestMapping("/disabledmanage") + public String execute(HttpServletRequest request) throws Exception { + + IUserManagementService service = AdminServiceProxy.getService(applicationContext.getServletContext()); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "DisabledUserManageAction"); + request.setAttribute("errorMessage", adminMessageService.getMessage("error.need.sysadmin")); + return "error"; + } + + List users = service.findByProperty(User.class, "disabledFlag", true); + log.debug("got " + users.size() + " disabled users"); + request.setAttribute("users", users); + + return "disabledusers"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,59 @@ +/**************************************************************** + * 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.admin.web.controller; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.web.form.ImportExcelForm; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author jliew + * + * + * + * + * + * + * + */ +@Controller +public class ImportExcelController { + + @RequestMapping("/importexcel") + public String execute(@ModelAttribute ImportExcelForm importExcelForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + //if (orgId==null) orgId = (Integer)request.getAttribute("orgId"); + + importExcelForm.setOrgId(orgId); + + return "import/importexcel"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportExcelSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,112 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.service.IImportService; +import org.lamsfoundation.lams.admin.web.form.ImportExcelForm; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.multipart.MultipartFile; + +/** + * @author jliew + * + * + * + * + * + * + * + * + * + * + * + * + */ +@Controller +public class ImportExcelSaveController { + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/importexcelsave") + public String execute(@ModelAttribute ImportExcelForm importExcelForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (request.getAttribute("CANCEL") != null) { + return "redirect:/sysadminstart.do"; + } + + IImportService importService = AdminServiceProxy.getImportService(applicationContext.getServletContext()); + MultipartFile file = importExcelForm.getFile(); + + // validation + if (file == null || file.getSize() <= 0) { + return "forward:/importexcel.do"; + } + + String sessionId = SessionManager.getSession().getId(); + SessionManager.getSession().setAttribute(IImportService.IMPORT_FILE, file); + // use a new thread only if number of users is > threshold + if (importService.getNumRows(file) < IImportService.THRESHOLD) { + List results = importService.parseSpreadsheet(file, sessionId); + SessionManager.getSession(sessionId).setAttribute(IImportService.IMPORT_RESULTS, results); + return "forward:/importuserresult.do"; + } else { + Thread t = new Thread(new ImportExcelThread(sessionId)); + t.start(); + return "import/status"; + } + } + + private class ImportExcelThread implements Runnable { + private String sessionId; + + public ImportExcelThread(String sessionId) { + this.sessionId = sessionId; + } + + @Override + public void run() { + IImportService importService = AdminServiceProxy.getImportService(applicationContext.getServletContext()); + try { + MultipartFile file = (MultipartFile) SessionManager.getSession(sessionId) + .getAttribute(IImportService.IMPORT_FILE); + List results = importService.parseSpreadsheet(file, sessionId); + SessionManager.getSession(sessionId).setAttribute(IImportService.IMPORT_RESULTS, results); + } catch (Exception e) { + } + } + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportGroupsAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportGroupsController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportGroupsController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportGroupsController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,83 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.service.IImportService; +import org.lamsfoundation.lams.admin.web.form.ImportExcelForm; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.multipart.MultipartFile; + +/** + * @author jliew + * + * + * + * + * + * + * + * + * + */ +@Controller +public class ImportGroupsController { + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/importgroups") + public String execute(@ModelAttribute ImportExcelForm importForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (request.getAttribute("CANCEL") != null) { + return "redirect:/sysadminstart.do"; + } + + IImportService importService = AdminServiceProxy.getImportService(applicationContext.getServletContext()); + importForm.setOrgId(0); + MultipartFile file = importForm.getFile(); + + // validation + if (file == null || file.getSize() <= 0) { + return "import/importGroups"; + } + + String sessionId = SessionManager.getSession().getId(); + List results = importService.parseGroupSpreadsheet(file, sessionId); + request.setAttribute("results", results); + + return "import/importGroups"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportUserResultAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportUserResultController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportUserResultController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ImportUserResultController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,94 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.service.IImportService; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.web.session.SessionManager; +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.multipart.MultipartFile; + +/** + * @author jliew + * + * + * + */ +@Controller +public class ImportUserResultController { + + private static Logger log = Logger.getLogger(ImportUserResultController.class); + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/importuserresult") + public String execute(HttpServletRequest request) throws Exception { + + MessageService messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + IImportService importService = AdminServiceProxy.getImportService(applicationContext.getServletContext()); + HttpSession ss = SessionManager.getSession(); + + List results = (List) ss.getAttribute(IImportService.IMPORT_RESULTS); + String successMessageKey = ""; + try { + MultipartFile file = (MultipartFile) ss.getAttribute(IImportService.IMPORT_FILE); + successMessageKey = (importService.isUserSpreadsheet(file) ? "msg.users.created" : "msg.users.added"); + } catch (Exception e) { + log.error("Couldn't check spreadsheet type!", e); + } + + int successful = 0; + for (int i = 0; i < results.size(); i++) { + ArrayList rowResult = (ArrayList) results.get(i); + if (rowResult.isEmpty()) { + successful++; + } + } + String[] args = new String[1]; + args[0] = String.valueOf(successful); + + request.setAttribute("results", results); + request.setAttribute("successful", messageService.getMessage(successMessageKey, args)); + + // remove temporary session vars that allowed status to be displayed + // to user during import + ss.removeAttribute(IImportService.STATUS_IMPORT_TOTAL); + ss.removeAttribute(IImportService.STATUS_IMPORTED); + ss.removeAttribute(IImportService.IMPORT_FILE); + ss.removeAttribute(IImportService.IMPORT_RESULTS); + + return "import/importresult"; + } +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LdapConfigAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LdapConfigController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LdapConfigController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LdapConfigController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,231 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; +import org.lamsfoundation.lams.usermanagement.dto.BulkUpdateResultDTO; +import org.lamsfoundation.lams.usermanagement.service.ILdapService; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.usermanagement.service.LdapService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +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; + +/** + * @author jliew + * + * + * + * + * + */ +@Controller +@RequestMapping("/ldap") +public class LdapConfigController { + + private static Logger log = Logger.getLogger(LdapConfigController.class); + private static IUserManagementService service; + private static LdapService ldapService; + private static MessageService messageService; + private static Configuration configurationService; + + @Autowired + private WebApplicationContext applicationContext; + + private IUserManagementService getService() { + if (service == null) { + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + } + return service; + } + + private LdapService getLdapService() { + if (ldapService == null) { + ldapService = AdminServiceProxy.getLdapService(applicationContext.getServletContext()); + } + return ldapService; + } + + private MessageService getMessageService() { + if (messageService == null) { + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + } + return messageService; + } + + private Configuration getConfiguration() { + if (configurationService == null) { + configurationService = AdminServiceProxy.getConfiguration(applicationContext.getServletContext()); + } + return configurationService; + } + + @RequestMapping("/start") + public String execute(HttpServletRequest request) throws Exception { + + String action = WebUtil.readStrParam(request, "action", true); + if (action != null) { + if (StringUtils.equals(action, "sync")) { + return sync(request); + } + if (StringUtils.equals(action, "waiting")) { + return waiting(request); + } + if (StringUtils.equals(action, "results")) { + return results(request); + } + } + + request.setAttribute("config", getConfiguration().arrangeItems(Configuration.ITEMS_ONLY_LDAP)); + + int numLdapUsers = getNumLdapUsers(); + request.setAttribute("numLdapUsersMsg", getNumLdapUsersMsg(numLdapUsers)); + + return "ldap"; + } + + @RequestMapping("/sync") + public String sync(HttpServletRequest request) throws Exception { + + String sessionId = SessionManager.getSession().getId(); + Thread t = new Thread(new LdapSyncThread(sessionId)); + t.start(); + + request.setAttribute("wait", getMessageService().getMessage("msg.ldap.synchronise.wait")); + + return "ldap"; + } + + @RequestMapping("/waiting") + public String waiting(HttpServletRequest request) throws Exception { + + request.setAttribute("wait", getMessageService().getMessage("msg.ldap.synchronise.wait")); + + return "ldap"; + } + + @RequestMapping("/results") + public String results(HttpServletRequest request) throws Exception { + + HttpSession ss = SessionManager.getSession(); + Object o = ss.getAttribute(ILdapService.SYNC_RESULTS); + if (o instanceof BulkUpdateResultDTO) { + BulkUpdateResultDTO dto = (BulkUpdateResultDTO) o; + + int numLdapUsers = getNumLdapUsers(); + request.setAttribute("numLdapUsersMsg", getNumLdapUsersMsg(numLdapUsers)); + + request.setAttribute("numSearchResults", getNumSearchResultsUsersMsg(dto.getNumSearchResults())); + request.setAttribute("numLdapUsersCreated", getNumCreatedUsersMsg(dto.getNumUsersCreated())); + request.setAttribute("numLdapUsersUpdated", getNumUpdatedUsersMsg(dto.getNumUsersUpdated())); + request.setAttribute("numLdapUsersDisabled", getNumDisabledUsersMsg(dto.getNumUsersDisabled())); + request.setAttribute("messages", dto.getMessages()); + request.setAttribute("done", getMessageService().getMessage("msg.done")); + } else { + ArrayList list = new ArrayList<>(); + list.add((String) o); + request.setAttribute("messages", list); + request.setAttribute("done", getMessageService().getMessage("msg.done")); + } + + // remove session variable that flags bulk update as done + ss.removeAttribute(ILdapService.SYNC_RESULTS); + + return "ldap"; + } + + private int getNumLdapUsers() { + Integer count = getService().getCountUsers(AuthenticationMethod.LDAP); + return (count != null ? count.intValue() : -1); + } + + private String getNumLdapUsersMsg(int numLdapUsers) { + String[] args = new String[1]; + args[0] = String.valueOf(numLdapUsers); + return getMessageService().getMessage("msg.num.ldap.users", args); + } + + private String getNumSearchResultsUsersMsg(int searchResults) { + String[] args = new String[1]; + args[0] = String.valueOf(searchResults); + return getMessageService().getMessage("msg.num.search.results.users", args); + } + + private String getNumCreatedUsersMsg(int created) { + String[] args = new String[1]; + args[0] = String.valueOf(created); + return getMessageService().getMessage("msg.num.created.users", args); + } + + private String getNumUpdatedUsersMsg(int updated) { + String[] args = new String[1]; + args[0] = String.valueOf(updated); + return getMessageService().getMessage("msg.num.updated.users", args); + } + + private String getNumDisabledUsersMsg(int disabled) { + String[] args = new String[1]; + args[0] = String.valueOf(disabled); + return getMessageService().getMessage("msg.num.disabled.users", args); + } + + private class LdapSyncThread implements Runnable { + private String sessionId; + + private Logger log = Logger.getLogger(LdapSyncThread.class); + + public LdapSyncThread(String sessionId) { + this.sessionId = sessionId; + } + + @Override + public void run() { + this.log.info("=== Beginning LDAP user sync ==="); + long start = System.currentTimeMillis(); + try { + BulkUpdateResultDTO dto = getLdapService().bulkUpdate(); + long end = System.currentTimeMillis(); + this.log.info("=== Finished LDAP user sync ==="); + this.log.info("Bulk update took " + (end - start) / 1000 + " seconds."); + SessionManager.getSession(sessionId).setAttribute(ILdapService.SYNC_RESULTS, dto); + } catch (Exception e) { + String message = e.getMessage() != null ? e.getMessage() : e.getClass().getName(); + SessionManager.getSession(sessionId).setAttribute(ILdapService.SYNC_RESULTS, message); + e.printStackTrace(); + } + } + } +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LogEventAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LogEventController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LogEventController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LogEventController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,211 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.logevent.LogEvent; +import org.lamsfoundation.lams.logevent.LogEventType; +import org.lamsfoundation.lams.logevent.dto.LogEventTypeDTO; +import org.lamsfoundation.lams.logevent.service.ILogEventService; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.util.JsonUtil; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.beans.factory.annotation.Autowired; +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 org.springframework.web.context.support.WebApplicationContextUtils; + +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * Report on events in the log event table. Used for auditing. + */ +@Controller +@RequestMapping("/logevent") +public class LogEventController { + + private static ILogEventService logEventService; + private MessageService messageService; + private static SimpleDateFormat START_DATE_FORMAT = new SimpleDateFormat("YYYY-MM-dd"); + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/start") + public String unspecified(HttpServletRequest request) throws Exception { + + // check permission + if (!request.isUserInRole(Role.SYSADMIN)) { + request.setAttribute("errorName", "EventLogAdmin"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.authorisation")); + return "error"; + } + + logEventService = getLogEventService(); + + if (messageService == null) { + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + } + + // get the log type data and return display for user selection. Also get the start and stop dates from the log. + // TODO check conversion the dates to the user's timezone + List types = logEventService.getEventTypes(); + List convertedTypes = new ArrayList<>(types.size()); + for (LogEventType type : types) { + convertedTypes.add(new LogEventTypeDTO(type, messageService.getMessage(type.getDescriptionI18NKey()), + messageService.getMessage(type.getAreaI18NKey()))); + } + request.setAttribute("eventLogTypes", convertedTypes); + + // jsp page expects date of the first audit log entry as YYYY-DD-MM. + Date oldestDate = logEventService.getOldestEventDate(); +// oldestDate = DateUtil.convertToTimeZoneFromDefault(userTimeZone, oldestDate); + request.setAttribute("startDate", START_DATE_FORMAT.format(oldestDate != null ? oldestDate : new Date())); + return "logevent"; + } + + /** + * The initial method for monitoring. List all users according to given Content ID. + */ + @RequestMapping("/getEventLog") + @ResponseBody + public String getEventLog(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + + // check permission + if (!request.isUserInRole(Role.SYSADMIN)) { + request.setAttribute("errorName", "EventLogAdmin"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.authorisation")); + return "error"; + } + + logEventService = getLogEventService(); + + // paging parameters of tablesorter + int size = WebUtil.readIntParam(request, "size"); + int page = WebUtil.readIntParam(request, "page"); + Integer isSort1 = WebUtil.readIntParam(request, "column[0]", true); +// String searchString = request.getParameter("fcol[0]"); + + int sorting = ILogEventService.SORT_BY_DATE_ASC; + if ((isSort1 != null) && isSort1.equals(1)) { + sorting = ILogEventService.SORT_BY_DATE_DESC; + } + + Long dateParameter = WebUtil.readLongParam(request, "startDate", true); + Date startDate = null; + if (dateParameter != null) { + startDate = new Date(dateParameter); + // TODO if using time zones then convert to server timezone +// HttpSession ss = SessionManager.getSession(); +// org.lamsfoundation.lams.usermanagement.dto.UserDTO teacher = (org.lamsfoundation.lams.usermanagement.dto.UserDTO) ss +// .getAttribute(AttributeNames.USER); +// TimeZone teacherTimeZone = teacher.getTimeZone(); +// tzSubmissionDeadline = DateUtil.convertFromTimeZoneToDefault(teacherTimeZone, submissionDeadline); + } + + dateParameter = WebUtil.readLongParam(request, "endDate", true); + Date endDate = null; + if (dateParameter != null) { + endDate = new Date(dateParameter); + } + + String area = WebUtil.readStrParam(request, "area", true); + Integer typeId = WebUtil.readIntParam(request, "typeId", true); + List events = logEventService.getEventsForTablesorter(page, size, sorting, null, startDate, endDate, + area, typeId); + + ArrayNode rows = JsonNodeFactory.instance.arrayNode(); + ObjectNode responsedata = JsonNodeFactory.instance.objectNode(); + responsedata.put("total_rows", + logEventService.countEventsWithRestrictions(null, startDate, endDate, area, typeId)); + + for (Object[] eventDetails : events) { + if (eventDetails.length > 0) { + LogEvent event = (LogEvent) eventDetails[0]; + ObjectNode responseRow = JsonNodeFactory.instance.objectNode(); + + responseRow.put("dateOccurred", JsonUtil.toString(event.getOccurredDateTime())); + responseRow.put("typeId", event.getLogEventTypeId()); + responseRow.put("description", event.getDescription()); + if (event.getLessonId() != null) { + responseRow.put("lessonId", event.getLessonId()); + } + if (event.getActivityId() != null) { + responseRow.put("activityId", event.getActivityId()); + } + + User user = event.getUser(); + if (user != null) { + responseRow.put("userPortraitId", user.getPortraitUuid()); + responseRow.put("userId", user.getUserId()); + responseRow.put("userName", user.getLogin()); + } + User targetUser = event.getTargetUser(); + if (targetUser != null) { + responseRow.put("targetUserPortraitId", targetUser.getPortraitUuid()); + responseRow.put("targetUserId", targetUser.getUserId()); + responseRow.put("targetUserName", targetUser.getLogin()); + } + if (eventDetails.length > 1 && eventDetails[1] != null) { + responseRow.put("lessonName", JsonUtil.toString(eventDetails[1])); + } + if (eventDetails.length > 2 && eventDetails[2] != null) { + responseRow.put("activityName", JsonUtil.toString(eventDetails[2])); + } + rows.add(responseRow); + } + } + responsedata.set("rows", rows); + response.setContentType("application/json;charset=utf-8"); + return responsedata.toString(); + } + + private ILogEventService getLogEventService() throws ServletException { + if (logEventService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + logEventService = (ILogEventService) ctx.getBean("logEventService"); + } + return logEventService; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginMaintainAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginMaintainController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginMaintainController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginMaintainController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,92 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.Charset; + +import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.admin.web.form.LoginMaintainForm; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + *

+ * View Source + *

+ * + * @author Fei Yang + */ + +/** + * + * + * + * + * + * + */ +@Controller +public class LoginMaintainController { + + private static final String NEWS_PAGE_PATH_SUFFIX = File.separatorChar + "lams-www.war" + File.separatorChar + + "news.html"; + + @RequestMapping("/loginmaintain") + public String execute(@ModelAttribute LoginMaintainForm loginMaintainForm, HttpServletRequest request) + throws Exception { + + loginMaintainForm.setNews(loadNews()); + return "loginmaintain"; + } + + private String loadNews() throws IOException { + BufferedReader bReader = null; + try { + InputStreamReader ir = new InputStreamReader( + new FileInputStream(Configuration.get(ConfigurationKeys.LAMS_EAR_DIR) + NEWS_PAGE_PATH_SUFFIX), + Charset.forName("UTF-8")); + bReader = new BufferedReader(ir); + StringBuilder news = new StringBuilder(); + String line = bReader.readLine(); + while (line != null) { + news.append(line).append('\n'); + line = bReader.readLine(); + } + return news.toString(); + } finally { + if (bReader != null) { + bReader.close(); + } + } + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LoginSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,80 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileOutputStream; +import java.io.OutputStreamWriter; +import java.nio.charset.Charset; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.web.form.LoginMaintainForm; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * Use DispatchAction for future extension convenience, e.g. add preview feature + * + * @author Fei Yang + */ +@Controller +public class LoginSaveController { + + private static final String NEWS_PAGE_PATH_SUFFIX = File.separatorChar + "lams-www.war" + File.separatorChar + + "news.html"; + + @RequestMapping("/loginsave") + @ResponseBody + public String save(@ModelAttribute LoginMaintainForm loginMaintainForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (request.getAttribute("CANCEL") != null) { + return "redirect:/sysadminstart.do"; + } + + BufferedWriter bWriter = null; + try { + OutputStreamWriter ow = new OutputStreamWriter( + new FileOutputStream(Configuration.get(ConfigurationKeys.LAMS_EAR_DIR) + NEWS_PAGE_PATH_SUFFIX), + Charset.forName("UTF-8")); + bWriter = new BufferedWriter(ow); + bWriter.write(loginMaintainForm.getNews()); + bWriter.flush(); + } finally { + if (bWriter != null) { + bWriter.close(); + } + } + + return "redirect:/sysadminstart.do"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LtiConsumerManagementAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LtiConsumerManagementController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LtiConsumerManagementController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/LtiConsumerManagementController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,193 @@ +package org.lamsfoundation.lams.admin.web.controller; + +import java.util.Collections; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.struts.action.ActionMessage; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.ExtServerForm; +import org.lamsfoundation.lams.admin.web.form.LtiConsumerForm; +import org.lamsfoundation.lams.integration.ExtServer; +import org.lamsfoundation.lams.integration.service.IIntegrationService; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +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.bind.annotation.RequestMethod; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author Andrey Balan + */ +@Controller +@RequestMapping("/ltiConsumerManagement") +public class LtiConsumerManagementController { + + private static Logger log = Logger.getLogger(LtiConsumerManagementController.class); + private IUserManagementService userManagementService; + private MessageService messageService; + private IIntegrationService integrationService; + + @Autowired + private WebApplicationContext applicationContext; + + private void initServices() { + if (userManagementService == null) { + userManagementService = AdminServiceProxy.getService(applicationContext.getServletContext()); + } + if (messageService == null) { + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + } + if (integrationService == null) { + integrationService = AdminServiceProxy.getIntegrationService(applicationContext.getServletContext()); + } + } + + /** + * Shows all available LTI tool consumers + */ + @RequestMapping("/start") + public String unspecified(HttpServletRequest request) { + initServices(); + + List ltiConsumers = integrationService.getAllToolConsumers(); + Collections.sort(ltiConsumers); + request.setAttribute("ltiConsumers", ltiConsumers); + + return "lti/ltiConsumerList"; + } + + /** + * Edits specified LTI tool consumer + */ + @RequestMapping("/edit") + public String edit(@ModelAttribute LtiConsumerForm ltiConsumerForm, HttpServletRequest request) throws Exception { + + initServices(); + + Integer sid = WebUtil.readIntParam(request, "sid", true); + + // editing a tool consumer + if (sid != null) { + ExtServer ltiConsumer = integrationService.getExtServer(sid); + BeanUtils.copyProperties(ltiConsumerForm, ltiConsumer); + String lessonFinishUrl = ltiConsumer.getLessonFinishUrl() == null ? "-" : ltiConsumer.getLessonFinishUrl(); + request.setAttribute("lessonFinishUrl", lessonFinishUrl); + + // create a tool consumer + } else { + //do nothing + } + + return "lti/ltiConsumer"; + } + + /** + * Disables or enables (depending on "disable" parameter) specified LTI tool consumer + */ + @RequestMapping("/disable") + public String disable(HttpServletRequest request) throws Exception { + + initServices(); + + Integer sid = WebUtil.readIntParam(request, "sid", true); + boolean disable = WebUtil.readBooleanParam(request, "disable"); + ExtServer ltiConsumer = integrationService.getExtServer(sid); + ltiConsumer.setDisabled(disable); + integrationService.saveExtServer(ltiConsumer); + + return unspecified(request); + } + + /** + * Removes specified LTI tool consumer + */ + @RequestMapping(path = "/delete", method = RequestMethod.POST) + public String delete(HttpServletRequest request) throws Exception { + + initServices(); + + Integer sid = WebUtil.readIntParam(request, "sid", true); + userManagementService.deleteById(ExtServer.class, sid); + + return unspecified(request); + } + + /** + * Stores in the DB a new or edited LTI tool consumer + */ + @RequestMapping(path = "/save", method = RequestMethod.POST) + public String save(@ModelAttribute ExtServerForm extServerForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + initServices(); + + if (request.getAttribute("CANCEL") != null) { + //show LTI consumer list page + return unspecified(request); + } + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + String[] requiredFields = { "serverid", "serverkey", "servername", "prefix" }; + for (String requiredField : requiredFields) { + if (StringUtils.trimToNull(extServerForm.getString(requiredField)) == null) { + errorMap.add(requiredField, + new ActionMessage("error.required", messageService.getMessage("sysadmin." + requiredField))); + } + } + + Integer sid = extServerForm.getSid(); + //check duplication + if (errorMap.isEmpty()) { + String[] uniqueFields = { "serverid", "prefix" }; + for (String uniqueField : uniqueFields) { + List list = userManagementService.findByProperty(ExtServer.class, uniqueField, + extServerForm.get(uniqueField)); + if (list != null && list.size() > 0) { + if (sid.equals(0)) {//new map + errorMap.add(uniqueField, new ActionMessage("error.not.unique", + messageService.getMessage("sysadmin." + uniqueField))); + } else { + ExtServer ltiConsumer = list.get(0); + if (!ltiConsumer.getSid().equals(sid)) { + errorMap.add(uniqueField, new ActionMessage("error.not.unique", + messageService.getMessage("sysadmin." + uniqueField))); + } + } + + } + } + } + if (errorMap.isEmpty()) { + ExtServer ltiConsumer = null; + if (sid.equals(0)) { + ltiConsumer = new ExtServer(); + BeanUtils.copyProperties(ltiConsumer, extServerForm); + ltiConsumer.setSid(null); + ltiConsumer.setServerTypeId(ExtServer.LTI_CONSUMER_SERVER_TYPE); + ltiConsumer.setUserinfoUrl("blank"); + } else { + ltiConsumer = integrationService.getExtServer(sid); + BeanUtils.copyProperties(ltiConsumer, extServerForm); + } + integrationService.saveExtServer(ltiConsumer); + return unspecified(request); + + } else { + request.setAttribute("errorMap", errorMap); + return "lti/ltiConsumer"; + } + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgManageAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgManageController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgManageController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgManageController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,239 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.OrgManageForm; +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.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.usermanagement.service.UserManagementService; +import org.lamsfoundation.lams.util.FileUtil; +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.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; +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; + +/** + *

+ * View Source + *

+ * + * @author Fei Yang + */ +@Controller +@RequestMapping("/orgmanage") +public class OrgManageController { + + private static IUserManagementService userManagementService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/start") + public String unspecified(@ModelAttribute OrgManageForm orgManageForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + initServices(); + + // Get organisation whose child organisations we will populate the OrgManageForm with + Integer orgId = WebUtil.readIntParam(request, "org", true); + if (orgId == null) { + orgId = (Integer) request.getAttribute("org"); + } + if ((orgId == null) || (orgId == 0)) { + response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Missing organisation ID"); + return null; + } + + // get logged in user's id + Integer userId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); + ISecurityService securityService = AdminServiceProxy.getSecurityService(applicationContext.getServletContext()); + + Organisation org = null; + boolean isRootOrganisation = false; + Organisation rootOrganisation = userManagementService.getRootOrganisation(); + if (orgId.equals(rootOrganisation.getOrganisationId())) { + org = rootOrganisation; + isRootOrganisation = true; + } else { + org = (Organisation) userManagementService.findById(Organisation.class, orgId); + } + + // check if user is allowed to view and edit groups + if (!request.isUserInRole(Role.SYSADMIN) && !(isRootOrganisation + ? request.isUserInRole(Role.GROUP_ADMIN) || request.isUserInRole(Role.GROUP_MANAGER) + : securityService.hasOrgRole(orgId, userId, new String[] { Role.GROUP_ADMIN, Role.GROUP_MANAGER }, + "manage courses", false))) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a manager or admin in the organisation"); + return null; + } + + // get number of users figure + // TODO use hql that does a count instead of getting whole objects + int numUsers = org == rootOrganisation ? userManagementService.getCountUsers() + : userManagementService.getUsersFromOrganisation(orgId).size(); + String key = org == rootOrganisation ? "label.users.in.system" : "label.users.in.group"; + MessageService messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + request.setAttribute("numUsers", messageService.getMessage(key, new String[] { String.valueOf(numUsers) })); + + // Set OrgManageForm + if (orgManageForm == null) { + orgManageForm = new OrgManageForm(); + orgManageForm.setStateId(OrganisationState.ACTIVE); + } else if (orgManageForm.getStateId() == null) { + orgManageForm.setStateId(OrganisationState.ACTIVE); + } + orgManageForm.setParentId(orgId); + orgManageForm.setParentName(org.getName()); + orgManageForm.setType(org.getOrganisationType().getOrganisationTypeId()); + + // Get list of child organisations depending on requestor's role and the organisation's type + if (orgManageForm.getType().equals(OrganisationType.CLASS_TYPE)) { + // display class info, with parent group's 'courseAdminCan...' permissions. + // note the org is not saved, properties set only for passing to view component. + Organisation pOrg = org.getParentOrganisation(); + org.setCourseAdminCanAddNewUsers(pOrg.getCourseAdminCanAddNewUsers()); + org.setCourseAdminCanBrowseAllUsers(pOrg.getCourseAdminCanBrowseAllUsers()); + org.setCourseAdminCanChangeStatusOfCourse(pOrg.getCourseAdminCanChangeStatusOfCourse()); + request.setAttribute("org", org); + + // display parent org breadcrumb link + request.setAttribute("parentGroupName", pOrg.getName()); + request.setAttribute("parentGroupId", pOrg.getOrganisationId()); + } else { + request.setAttribute("OrgManageForm", orgManageForm); + + // display org info + request.setAttribute("org", org); + } + + // let the jsp know whether to display links + request.setAttribute("createGroup", + request.isUserInRole(Role.SYSADMIN) || userManagementService.isUserGlobalGroupAdmin()); + request.setAttribute("editGroup", true); + request.setAttribute("manageGlobalRoles", request.isUserInRole(Role.SYSADMIN)); + return "organisation/list"; + } + + /** + * Returns list of organisations for . + */ + @RequestMapping("/getOrgs") + @ResponseBody + public String getOrgs(HttpServletRequest request, HttpServletResponse res) throws IOException, ServletException { + initServices(); + + Integer parentOrgId = WebUtil.readIntParam(request, "parentOrgId"); + Integer stateId = WebUtil.readIntParam(request, "stateId"); + Integer typeIdParam = WebUtil.readIntParam(request, "type"); + // the organisation type of the children + Integer typeId = (typeIdParam.equals(OrganisationType.ROOT_TYPE) ? OrganisationType.COURSE_TYPE + : OrganisationType.CLASS_TYPE); + 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 (isSort1 != null) { + sortBy = "id"; + sortOrder = isSort1.equals(0) ? "ASC" : "DESC"; + + } else if (isSort2 != null) { + sortBy = "name"; + sortOrder = isSort2.equals(0) ? "ASC" : "DESC"; + + } else if (isSort3 != null) { + sortBy = "code"; + sortOrder = isSort3.equals(0) ? "ASC" : "DESC"; + + } else if (isSort4 != null) { + sortBy = "createDate"; + sortOrder = isSort4.equals(0) ? "ASC" : "DESC"; + + } + + List organisations = userManagementService.getPagedCourses(parentOrgId, typeId, stateId, page, + size, sortBy, sortOrder, searchString); + + ObjectNode responseJSON = JsonNodeFactory.instance.objectNode(); + responseJSON.put("total_rows", userManagementService.getCountCoursesByParentCourseAndTypeAndState(parentOrgId, + typeId, stateId, searchString)); + + ArrayNode rows = JsonNodeFactory.instance.arrayNode(); + for (Organisation organisation : organisations) { + ObjectNode responseRow = JsonNodeFactory.instance.objectNode(); + responseRow.put("id", organisation.getOrganisationId()); + String orgName = organisation.getName() == null ? "" : organisation.getName(); + responseRow.put("name", HtmlUtils.htmlEscape(orgName)); + String orgCode = organisation.getCode() == null ? "" : organisation.getCode(); + responseRow.put("code", HtmlUtils.htmlEscape(orgCode)); + String orgCreateDate = organisation.getCreateDate() == null ? "" + : FileUtil.EXPORT_TO_SPREADSHEET_TITLE_DATE_FORMAT.format(organisation.getCreateDate()); + responseRow.put("createDate", orgCreateDate); + + rows.add(responseRow); + } + + responseJSON.set("rows", rows); + res.setContentType("application/json;charset=utf-8"); + return responseJSON.toString(); + } + + private void initServices() { + if (userManagementService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getWebApplicationContext(applicationContext.getServletContext()); + userManagementService = (UserManagementService) ctx.getBean("userManagementService"); + } + } +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgPasswordChangeAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgPasswordChangeController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgPasswordChangeController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgPasswordChangeController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,337 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.io.IOException; +import java.security.InvalidParameterException; +import java.util.Collection; +import java.util.HashSet; +import java.util.LinkedList; +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.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.AdminConstants; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.OrgPasswordChangeForm; +import org.lamsfoundation.lams.events.IEventNotificationService; +import org.lamsfoundation.lams.integration.security.RandomPasswordGenerator; +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.service.IUserManagementService; +import org.lamsfoundation.lams.util.HashUtil; +import org.lamsfoundation.lams.util.JsonUtil; +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.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +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.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +@Controller +@RequestMapping("/orgPasswordChange") +public class OrgPasswordChangeController { + + private static Logger log = Logger.getLogger(OrgPasswordChangeController.class); + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/start") + public String unspecified(@ModelAttribute OrgPasswordChangeForm orgPasswordChangeForm, HttpServletRequest request) { + Integer organisationID = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); + orgPasswordChangeForm.setOrganisationID(organisationID); + IUserManagementService userManagementService = AdminServiceProxy + .getService(applicationContext.getServletContext()); + Organisation organisation = (Organisation) userManagementService.findById(Organisation.class, organisationID); + orgPasswordChangeForm.setOrgName(organisation.getName()); + orgPasswordChangeForm.setStaffChange(true); + orgPasswordChangeForm.setLearnerChange(true); + orgPasswordChangeForm.setStaffPass(RandomPasswordGenerator.nextPasswordValidated()); + orgPasswordChangeForm.setLearnerPass(RandomPasswordGenerator.nextPasswordValidated()); + + return "orgPasswordChange"; + } + + @RequestMapping("/generatePassword") + @ResponseBody + public String generatePassword(HttpServletRequest request, HttpServletResponse response) throws IOException { + response.setContentType("text/plain;charset=utf-8"); + response.getWriter().print(RandomPasswordGenerator.nextPasswordValidated()); + return null; + } + + @RequestMapping("/getGridUsers") + @ResponseBody + public String getGridUsers(HttpServletRequest request, HttpServletResponse response) throws IOException { + Integer organisationID = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); + String role = WebUtil.readStrParam(request, AttributeNames.PARAM_ROLE); + + UserDTO userDTO = getUserDTO(); + Integer currentUserId = userDTO.getUserID(); + if (!AdminServiceProxy.getSecurityService(applicationContext.getServletContext()).isSysadmin(currentUserId, + "get grid users for org password change", false)) { + String warning = "User " + currentUserId + " is not a sysadmin"; + log.warn(warning); + response.sendError(HttpServletResponse.SC_FORBIDDEN, warning); + return null; + } + + int page = WebUtil.readIntParam(request, AdminConstants.PARAM_PAGE); + int rowLimit = WebUtil.readIntParam(request, AdminConstants.PARAM_ROWS); + String sortOrder = WebUtil.readStrParam(request, AdminConstants.PARAM_SORD); + String sortColumn = WebUtil.readStrParam(request, AdminConstants.PARAM_SIDX, true); + + // fetch staff or learners + List users = getUsersByRole(organisationID, role.equalsIgnoreCase("staff"), sortColumn, sortOrder); + + // paging + int totalPages = 1; + int totalUsers = users.size(); + if (rowLimit < users.size()) { + totalPages = new Double( + Math.ceil(new Integer(users.size()).doubleValue() / new Integer(rowLimit).doubleValue())) + .intValue(); + int firstRow = (page - 1) * rowLimit; + int lastRow = firstRow + rowLimit; + + if (lastRow > users.size()) { + users = users.subList(firstRow, users.size()); + } else { + users = users.subList(firstRow, lastRow); + } + } + + ObjectNode resultJSON = JsonNodeFactory.instance.objectNode(); + resultJSON.put(AdminConstants.ELEMENT_PAGE, page); + resultJSON.put(AdminConstants.ELEMENT_TOTAL, totalPages); + resultJSON.put(AdminConstants.ELEMENT_RECORDS, totalUsers); + + ArrayNode rowsJSON = JsonNodeFactory.instance.arrayNode(); + // build rows for grid + for (UserDTO user : users) { + ObjectNode rowJSON = JsonNodeFactory.instance.objectNode(); + rowJSON.put(AdminConstants.ELEMENT_ID, user.getUserID()); + + ArrayNode cellJSON = JsonNodeFactory.instance.arrayNode(); + cellJSON.add(user.getFirstName() + " " + user.getLastName()); + cellJSON.add(user.getLogin()); + cellJSON.add(user.getEmail()); + + rowJSON.set(AdminConstants.ELEMENT_CELL, cellJSON); + rowsJSON.add(rowJSON); + } + + resultJSON.set(AdminConstants.ELEMENT_ROWS, rowsJSON); + + response.setContentType("application/json;charset=utf-8"); + return resultJSON.toString(); + } + + @RequestMapping("/changePassword") + public String changePassword(@ModelAttribute OrgPasswordChangeForm orgPasswordChangeForm, + HttpServletRequest request, HttpServletResponse response) throws IOException { + UserDTO userDTO = getUserDTO(); + Integer currentUserId = userDTO.getUserID(); + // security check + if (!AdminServiceProxy.getSecurityService(applicationContext.getServletContext()).isSysadmin(currentUserId, + "org password change", false)) { + String warning = "User " + currentUserId + " is not a sysadmin"; + log.warn(warning); + response.sendError(HttpServletResponse.SC_FORBIDDEN, warning); + return null; + } + + Integer organisationID = orgPasswordChangeForm.getOrganisationID(); + Boolean email = orgPasswordChangeForm.isEmail(); + Boolean force = orgPasswordChangeForm.isForce(); + + Boolean isStaffChange = orgPasswordChangeForm.isStaffChange(); + Boolean isLearnerChange = orgPasswordChangeForm.isLearnerChange(); + // get data needed for each group + if (isStaffChange) { + String staffString = orgPasswordChangeForm.getExcludedStaff(); + ArrayNode excludedStaff = StringUtils.isBlank(staffString) ? null : JsonUtil.readArray(staffString); + staffString = orgPasswordChangeForm.getIncludedStaff(); + ArrayNode includedStaff = StringUtils.isBlank(staffString) ? null : JsonUtil.readArray(staffString); + + String staffPass = orgPasswordChangeForm.getStaffPass(); + Collection users = getUsersByRole(organisationID, true); + Collection changedUserIDs = changePassword(staffPass, users, includedStaff, excludedStaff, force); + if (email && !changedUserIDs.isEmpty()) { + notifyOnPasswordChange(changedUserIDs, staffPass); + } + } + if (isLearnerChange) { + String learnersString = orgPasswordChangeForm.getExcludedLearners(); + ArrayNode excludedLearners = StringUtils.isBlank(learnersString) ? null + : JsonUtil.readArray(learnersString); + learnersString = orgPasswordChangeForm.getIncludedLearners(); + ArrayNode includedLearners = StringUtils.isBlank(learnersString) ? null + : JsonUtil.readArray(learnersString); + + String learnerPass = orgPasswordChangeForm.getLearnerPass(); + Collection users = getUsersByRole(organisationID, false); + Collection changedUserIDs = changePassword(learnerPass, users, includedLearners, excludedLearners, + force); + if (email && !changedUserIDs.isEmpty()) { + notifyOnPasswordChange(changedUserIDs, learnerPass); + } + } + + request.setAttribute("success", true); + return "orgPasswordChange"; + } + + private void notifyOnPasswordChange(Collection userIDs, String password) { + MessageService messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + AdminServiceProxy.getEventNotificationService(applicationContext.getServletContext()).sendMessage(null, + userIDs.toArray(new Integer[] {}), IEventNotificationService.DELIVERY_METHOD_MAIL, + messageService.getMessage("admin.org.password.change.email.subject"), + messageService.getMessage("admin.org.password.change.email.body", new String[] { password }), false); + } + + private Set changePassword(String password, Collection users, ArrayNode includedUsers, + ArrayNode excludedUsers, boolean force) { + if (!ValidationUtil.isPasswordValueValid(password, password)) { + // this should have been picked up by JS validator on the page! + throw new InvalidParameterException("Password does not pass validation"); + } + if (includedUsers != null && excludedUsers != null) { + throw new IllegalArgumentException("Both included and excluded users arrays must not be passed together"); + } + Set changedUserIDs = new TreeSet<>(); + IUserManagementService userManagementService = AdminServiceProxy + .getService(applicationContext.getServletContext()); + UserDTO currentUserDTO = getUserDTO(); + User currentUser = (User) userManagementService.findById(User.class, currentUserDTO.getUserID()); + for (User user : users) { + // either we work with white list or black list + if (includedUsers == null) { + boolean excluded = false; + // skip excluded (unchecked on the page) users + for (int index = 0; index < excludedUsers.size(); index++) { + Integer excludedUserID = excludedUsers.get(index).asInt(); + if (user.getUserId().equals(excludedUserID)) { + excluded = true; + break; + } + } + if (excluded) { + continue; + } + } else { + boolean included = false; + for (int index = 0; index < includedUsers.size(); index++) { + Integer includedUserID = includedUsers.get(index).asInt(); + if (user.getUserId().equals(includedUserID)) { + included = true; + break; + } + } + if (!included) { + continue; + } + } + + // change password + String salt = HashUtil.salt(); + user.setSalt(salt); + user.setPassword(HashUtil.sha256(password, salt)); + if (force) { + user.setChangePassword(true); + } + userManagementService.saveUser(user); + log.info("Changed password for user ID " + user.getUserId()); + userManagementService.logPasswordChanged(user, currentUser); + changedUserIDs.add(user.getUserId()); + } + return changedUserIDs; + } + + /** + * Get unsorted users for password change + */ + @SuppressWarnings("unchecked") + private List getUsersByRole(Integer organisationID, boolean isStaff) { + IUserManagementService userManagementService = AdminServiceProxy + .getService(applicationContext.getServletContext()); + Set staff = new HashSet<>(); + staff.addAll(userManagementService.getUsersFromOrganisationByRole(organisationID, Role.AUTHOR, true)); + staff.addAll(userManagementService.getUsersFromOrganisationByRole(organisationID, Role.MONITOR, true)); + + Set users = null; + if (isStaff) { + users = staff; + } else { + users = new HashSet<>(); + users.addAll(userManagementService.getUsersFromOrganisationByRole(organisationID, Role.LEARNER, true)); + users.removeAll(staff); + } + return new LinkedList<>(users); + } + + /** + * Gets sorted users for grids + */ + private List getUsersByRole(Integer organisationID, boolean isStaff, String sortBy, String sortOrder) { + IUserManagementService userManagementService = AdminServiceProxy + .getService(applicationContext.getServletContext()); + List staff = userManagementService.getAllUsers(organisationID, + new String[] { Role.AUTHOR, Role.MONITOR }, null, null, sortBy, sortOrder, null); + + List users = null; + if (isStaff) { + users = staff; + } else { + users = new LinkedList<>(); + users.addAll(userManagementService.getAllUsers(organisationID, new String[] { Role.LEARNER }, null, null, + sortBy, sortOrder, null)); + users.removeAll(staff); + } + return users; + } + + private UserDTO getUserDTO() { + HttpSession ss = SessionManager.getSession(); + return (UserDTO) ss.getAttribute(AttributeNames.USER); + } +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrgSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,275 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.OrganisationForm; +import org.lamsfoundation.lams.logevent.LogEvent; +import org.lamsfoundation.lams.logevent.service.ILogEventService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationState; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.SupportedLocale; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +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.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; + +/** + * @version + * + *

+ * View Source + *

+ * + * @author Fei Yang + * + * Created at 16:42:53 on 2006-6-7 + */ + +/** + * + * + * + * + * + * + * + * + * + * + */ + +@Controller +public class OrgSaveController { + + private static Logger log = Logger.getLogger(OrgSaveController.class); + private static IUserManagementService service; + private MessageService messageService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/orgsave") + public String execute(@ModelAttribute OrganisationForm organisationForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (service == null) { + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + } + if (messageService == null) { + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + } + + Integer orgId = organisationForm.getOrgId(); + Organisation org; + + if (request.getAttribute("CANCEL") != null) { + if (orgId != 0) { + request.setAttribute("org", orgId); + org = (Organisation) service.findById(Organisation.class, orgId); + if (org.getOrganisationType().getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) { + return "forward:/usermanage.do"; + } + } else { + request.setAttribute("org", organisationForm.getParentId()); + } + return "forward:/orgmanage.do"; + } + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + + //organisation name validation + String orgName = (organisationForm.getName() == null) ? null : organisationForm.getName(); + if (StringUtils.isBlank(orgName)) { + errorMap.add("name", messageService.getMessage("error.name.required")); + } else if (!ValidationUtil.isOrgNameValid(orgName)) { + errorMap.add("name", messageService.getMessage("error.name.invalid.characters")); + } + + if (errorMap.isEmpty()) { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + SupportedLocale locale = (SupportedLocale) service.findById(SupportedLocale.class, + organisationForm.getLocaleId()); + OrganisationState state = (OrganisationState) service.findById(OrganisationState.class, + organisationForm.getStateId()); + + if (orgId != 0) { + if (service.canEditGroup(user.getUserID(), orgId)) { + org = (Organisation) service.findById(Organisation.class, orgId); + // set archived date only when it first changes to become archived + if (state.getOrganisationStateId().equals(OrganisationState.ARCHIVED) && !org.getOrganisationState() + .getOrganisationStateId().equals(OrganisationState.ARCHIVED)) { + org.setArchivedDate(new Date()); + } + writeAuditLog(user, org, organisationForm, state, locale); + BeanUtils.copyProperties(org, organisationForm); + } else { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + } else { + org = new Organisation(); + BeanUtils.copyProperties(org, organisationForm); + org.setParentOrganisation( + (Organisation) service.findById(Organisation.class, organisationForm.getParentId())); + org.setOrganisationType( + (OrganisationType) service.findById(OrganisationType.class, organisationForm.getOrgId())); + writeAuditLog(user, org, organisationForm, org.getOrganisationState(), org.getLocale()); + } + org.setLocale(locale); + org.setOrganisationState(state); + if (log.isDebugEnabled()) { + log.debug("orgId: " + org.getOrganisationId() + " create date: " + org.getCreateDate()); + } + org = service.saveOrganisation(org, user.getUserID()); + + request.setAttribute("org", organisationForm.getParentId()); + return "forward:/orgmanage.do"; + } else { + request.setAttribute("errorMap", errorMap); + return "forward:/organisation/edit.do"; + } + } + + private void writeAuditLog(UserDTO user, Organisation org, OrganisationForm orgForm, OrganisationState newState, + SupportedLocale newLocale) { + + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + ILogEventService logEventService = (ILogEventService) ctx.getBean("logEventService"); + MessageService messageService = (MessageService) ctx.getBean("adminMessageService"); + + String message; + + // audit log entries for organisation attribute changes + if (orgForm.getOrgId() != 0) { + final String key = "audit.organisation.change"; + String[] args = new String[4]; + args[1] = org.getName() + "(" + org.getOrganisationId() + ")"; + if (!org.getOrganisationState().getOrganisationStateId().equals(orgForm.getStateId())) { + args[0] = "state"; + args[2] = org.getOrganisationState().getDescription(); + args[3] = newState.getDescription(); + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + if (!StringUtils.equals(org.getName(), orgForm.getName())) { + args[0] = "name"; + args[2] = org.getName(); + args[3] = orgForm.getName(); + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + if (!StringUtils.equals(org.getCode(), orgForm.getCode())) { + args[0] = "code"; + args[2] = org.getCode(); + args[3] = orgForm.getCode(); + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + if (!StringUtils.equals(org.getDescription(), orgForm.getDescription())) { + args[0] = "description"; + args[2] = org.getDescription(); + args[3] = orgForm.getDescription(); + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + if (!org.getCourseAdminCanAddNewUsers().equals(orgForm.isCourseAdminCanAddNewUsers())) { + args[0] = "courseAdminCanAddNewUsers"; + args[2] = org.getCourseAdminCanAddNewUsers() ? "true" : "false"; + args[3] = orgForm.isCourseAdminCanAddNewUsers() ? "true" : "false"; + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + if (!org.getCourseAdminCanBrowseAllUsers().equals(orgForm.isCourseAdminCanAddNewUsers())) { + args[0] = "courseAdminCanBrowseAllUsers"; + args[2] = org.getCourseAdminCanBrowseAllUsers() ? "true" : "false"; + args[3] = orgForm.isCourseAdminCanBrowseAllUsers() ? "true" : "false"; + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + if (!org.getCourseAdminCanChangeStatusOfCourse().equals(orgForm.isCourseAdminCanChangeStatusOfCourse())) { + args[0] = "courseAdminCanChangeStatusOfCourse"; + args[2] = org.getCourseAdminCanChangeStatusOfCourse() ? "true" : "false"; + args[3] = orgForm.isCourseAdminCanChangeStatusOfCourse() ? "true" : "false"; + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + /* + * this field not set yet + * if(!org.getCourseAdminCanCreateGuestAccounts().equals(isCourseAdminCanCreateGuestAccounts())) { + * args[0] = "courseAdminCanCreateGuestAccounts"; + * args[2] = org.getCourseAdminCanCreateGuestAccounts() ? "true" : "false"; + * args[3] = orgForm.isCourseAdminCanCreateGuestAccounts() ? "true" : "false"; + * message = messageService.getMessage(key, args); + * auditService.log(AdminConstants.MODULE_NAME, message); + * } + */ + if (!org.getLocale().getLocaleId().equals(orgForm.getLocaleId())) { + args[0] = "locale"; + args[2] = org.getLocale().getDescription(); + args[3] = newLocale.getDescription(); + message = messageService.getMessage(key, args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, + null, null, message); + } + } else { + String[] args = new String[2]; + args[0] = org.getName() + "(" + org.getOrganisationId() + ")"; + args[1] = org.getOrganisationType().getName(); + message = messageService.getMessage("audit.organisation.create", args); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, user != null ? user.getUserID() : null, null, null, + null, message); + } + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrganisationAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrganisationController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrganisationController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/OrganisationController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,251 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.io.IOException; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.OrganisationForm; +import org.lamsfoundation.lams.lesson.Lesson; +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.SupportedLocale; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +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.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author Fei Yang + */ +@Controller +@RequestMapping("/organisation") +public class OrganisationController { + + private static IUserManagementService service; + private static MessageService messageService; + private static List locales; + private static List status; + + private static Logger log = Logger.getLogger(OrganisationController.class); + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping(path = "/edit", method = RequestMethod.POST) + public String edit(@ModelAttribute OrganisationForm organisationForm, HttpServletRequest request) throws Exception { + + OrganisationController.service = AdminServiceProxy.getService(applicationContext.getServletContext()); + initLocalesAndStatus(); + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + + HttpSession session = SessionManager.getSession(); + if (session != null) { + UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); + if (userDto != null) { + Integer userId = userDto.getUserID(); + // sysadmin, global group admin, group manager, group admin can edit group + if (OrganisationController.service.canEditGroup(userId, orgId)) { + // edit existing organisation + if (orgId != null) { + Organisation org = (Organisation) OrganisationController.service.findById(Organisation.class, + orgId); + BeanUtils.copyProperties(organisationForm, org); + organisationForm.setParentId(org.getParentOrganisation().getOrganisationId()); + organisationForm.setParentName(org.getParentOrganisation().getName()); + organisationForm.setOrgId(org.getOrganisationType().getOrganisationTypeId()); + organisationForm.setStateId(org.getOrganisationState().getOrganisationStateId()); + SupportedLocale locale = org.getLocale(); + organisationForm.setLocaleId(locale != null ? locale.getLocaleId() : null); + ; + + // find a course or subcourse with any lessons, so we warn user when he tries to delete the course + Integer courseToDeleteLessons = org.getLessons().size() > 0 ? orgId : null; + if (courseToDeleteLessons == null) { + for (Organisation subcourse : (Set) org.getChildOrganisations()) { + if (subcourse.getLessons().size() > 0) { + courseToDeleteLessons = subcourse.getOrganisationId(); + break; + } + } + } + request.setAttribute("courseToDeleteLessons", courseToDeleteLessons); + } + request.getSession().setAttribute("locales", OrganisationController.locales); + request.getSession().setAttribute("status", OrganisationController.status); + if (OrganisationController.service.isUserSysAdmin() + || OrganisationController.service.isUserGlobalGroupAdmin()) { + return "organisation/createOrEdit"; + } else { + return "organisation/courseAdminEdit"; + } + } + } + } + + return error(request); + } + + @RequestMapping(path = "/create", method = RequestMethod.POST) + public String create(@ModelAttribute OrganisationForm organisationForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + OrganisationController.service = AdminServiceProxy.getService(applicationContext.getServletContext()); + initLocalesAndStatus(); + + if (!(request.isUserInRole(Role.SYSADMIN) || OrganisationController.service.isUserGlobalGroupAdmin())) { + // only sysadmins and global group admins can create groups + if (((organisationForm.getOrgId() != null) + && organisationForm.getOrgId().equals(OrganisationType.COURSE_TYPE)) + || (organisationForm.getOrgId() == null)) { + return error(request); + } + } + + // creating new organisation + organisationForm.setOrgId(null); + ; + Integer parentId = WebUtil.readIntParam(request, "parentId", true); + if (parentId != null) { + Organisation parentOrg = (Organisation) OrganisationController.service.findById(Organisation.class, + parentId); + organisationForm.setParentName(parentOrg.getName()); + } + request.getSession().setAttribute("locales", OrganisationController.locales); + request.getSession().setAttribute("status", OrganisationController.status); + return "organisation/createOrEdit"; + } + + /** + * Looks up course ID by its name. Used mainly by TestHarness. + */ + @RequestMapping("/getOrganisationIdByName") + @ResponseBody + public String getOrganisationIdByName(HttpServletRequest request, HttpServletResponse response) throws IOException { + String organisationName = WebUtil.readStrParam(request, "name"); + OrganisationController.service = AdminServiceProxy.getService(applicationContext.getServletContext()); + List organisations = service.findByProperty(Organisation.class, "name", organisationName); + if (!organisations.isEmpty()) { + response.setContentType("text/plain;charset=utf-8"); + response.getWriter().print(organisations.get(0).getOrganisationId()); + } + return null; + } + + @RequestMapping("/deleteAllLessonsInit") + public String deleteAllLessonsInit(HttpServletRequest request, HttpServletResponse response) throws IOException { + if (!AdminServiceProxy.getSecurityService(applicationContext.getServletContext()).isSysadmin(getUserID(), + "display cleanup preview lessons", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a sysadmin"); + return null; + } + + if (!(request.isUserInRole(Role.SYSADMIN))) { + request.setAttribute("errorName", "OrganisationAction"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.need.sysadmin")); + return "error"; + } + + Integer organisationId = WebUtil.readIntParam(request, "orgId"); + Organisation organisation = (Organisation) AdminServiceProxy.getService(applicationContext.getServletContext()) + .findById(Organisation.class, organisationId); + int lessonCount = organisation.getLessons().size(); + request.setAttribute("lessonCount", lessonCount); + request.setAttribute("courseName", organisation.getName()); + + return "organisation/deleteAllLessons"; + } + + @RequestMapping(path = "/deleteAllLessons", method = RequestMethod.POST) + public String deleteAllLessons(HttpServletRequest request, HttpServletResponse response) throws IOException { + Integer userID = getUserID(); + Integer limit = WebUtil.readIntParam(request, "limit", true); + Integer organisationId = WebUtil.readIntParam(request, "orgId"); + Organisation organisation = (Organisation) AdminServiceProxy.getService(applicationContext.getServletContext()) + .findById(Organisation.class, organisationId); + for (Lesson lesson : (Set) organisation.getLessons()) { + log.info("Deleting lesson: " + lesson.getLessonId()); + // role is checked in this method + AdminServiceProxy.getMonitoringService(applicationContext.getServletContext()) + .removeLessonPermanently(lesson.getLessonId(), userID); + if (limit != null) { + limit--; + if (limit == 0) { + break; + } + } + } + + organisation = (Organisation) AdminServiceProxy.getService(applicationContext.getServletContext()) + .findById(Organisation.class, organisationId); + response.setContentType("application/json;charset=utf-8"); + response.getWriter().print(organisation.getLessons().size()); + return null; + } + + @RequestMapping("/error") + public String error(HttpServletRequest request) { + OrganisationController.messageService = AdminServiceProxy + .getMessageService(applicationContext.getServletContext()); + request.setAttribute("errorName", "OrganisationAction"); + request.setAttribute("errorMessage", OrganisationController.messageService.getMessage("error.authorisation")); + return "error"; + } + + private Integer getUserID() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user == null ? null : user.getUserID(); + } + + @SuppressWarnings("unchecked") + private void initLocalesAndStatus() { + if ((OrganisationController.locales == null) + || ((OrganisationController.status == null) && (OrganisationController.service != null))) { + OrganisationController.locales = OrganisationController.service.findAll(SupportedLocale.class); + OrganisationController.status = OrganisationController.service.findAll(OrganisationState.class); + Collections.sort(OrganisationController.locales); + } + } +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/PortraitBatchUploadAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/PortraitBatchUploadController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/PortraitBatchUploadController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/PortraitBatchUploadController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,110 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.io.IOException; +import java.io.Writer; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.lamsfoundation.lams.security.ISecurityService; +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.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * Looks for [login].png images in /tmp/portraits of user IDs within given range and starting with the given prefix + * + * @author Marcin Cieslak + */ +@Controller +public class PortraitBatchUploadController { + + private static IUserManagementService userManagementService; + private static ISecurityService securityService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/uploadPortraits") + @ResponseBody + public String execute(HttpServletRequest request, HttpServletResponse response) throws IOException { + if (!getSecurityService().isSysadmin(getUserID(), "batch upload portraits", false)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a sysadmin"); + return null; + } + + Integer minUserId = WebUtil.readIntParam(request, "minUserID"); + Integer maxUserId = WebUtil.readIntParam(request, "maxUserID"); + String prefix = request.getParameter("prefix"); + + List uploadedUserNames = getUserManagementService().uploadPortraits(minUserId, maxUserId, prefix); + if (uploadedUserNames != null) { + response.setCharacterEncoding("UTF-8"); + response.setContentType("text/plain"); + Writer responseWriter = response.getWriter(); + responseWriter.write("Uploaded portraits for users:\n"); + for (String userName : uploadedUserNames) { + responseWriter.write(userName + "\n"); + } + responseWriter.close(); + } + + return null; + } + + private Integer getUserID() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user == null ? null : user.getUserID(); + } + + private IUserManagementService getUserManagementService() { + if (userManagementService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + userManagementService = (IUserManagementService) ctx.getBean("userManagementService"); + } + return userManagementService; + } + + private ISecurityService getSecurityService() { + if (securityService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + securityService = (ISecurityService) ctx.getBean("securityService"); + } + return securityService; + } +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ScheduledJobListAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ScheduledJobListController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ScheduledJobListController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ScheduledJobListController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,96 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.web.dto.ScheduledJobDTO; +import org.quartz.JobDetail; +import org.quartz.JobKey; +import org.quartz.Scheduler; +import org.quartz.SchedulerException; +import org.quartz.Trigger; +import org.quartz.impl.matchers.GroupMatcher; +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 Steve.Ni + * @version $Revision$ + * + * + * + * + */ +@Controller +public class ScheduledJobListController { + + private static final Logger log = Logger.getLogger(ScheduledJobListController.class); + + @Autowired + private WebApplicationContext applicationContext; + + /** + * Get all waitting queue jobs scheduled in Quartz table and display job name, job start time and description. The + * description will be in format "Lesson Name":"the lesson creator", or "The gate name":"The relatived lesson name". + */ + @SuppressWarnings("unchecked") + @RequestMapping("/joblist") + public String execute(HttpServletRequest request) throws Exception { + + WebApplicationContext ctx = WebApplicationContextUtils + .getWebApplicationContext(this.applicationContext.getServletContext()); + Scheduler scheduler = (Scheduler) ctx.getBean("scheduler"); + ArrayList jobList = new ArrayList<>(); + try { + Set jobKeys = scheduler.getJobKeys(GroupMatcher.jobGroupEquals(Scheduler.DEFAULT_GROUP)); + for (JobKey jobKey : jobKeys) { + ScheduledJobDTO jobDto = new ScheduledJobDTO(); + JobDetail detail = scheduler.getJobDetail(jobKey); + jobDto.setName(jobKey.getName()); + jobDto.setDescription(detail.getDescription()); + List triggers = (List) scheduler.getTriggersOfJob(jobKey); + for (Trigger trigger : triggers) { + jobDto.setStartDate(trigger.getStartTime()); + jobList.add(jobDto); + } + } + } catch (SchedulerException e) { + ScheduledJobListController.log.equals("Failed get job names:" + e.getMessage()); + } + + request.setAttribute("jobList", jobList); + return "joblist"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerListAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerListController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerListController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerListController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,56 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import java.util.Collections; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.integration.ExtServer; +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; + +/** + * + * @author Fei Yang + */ +@Controller +public class ServerListController { + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/serverlist") + public String execute(HttpServletRequest request) throws Exception { + List extServers = AdminServiceProxy.getIntegrationService(applicationContext.getServletContext()) + .getAllExtServers(); + Collections.sort(extServers); + request.setAttribute("servers", extServers); + return "serverlist"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerMaintainAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerMaintainController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerMaintainController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerMaintainController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,91 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.beanutils.BeanUtils; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.ExtServerForm; +import org.lamsfoundation.lams.integration.ExtServer; +import org.lamsfoundation.lams.integration.service.IIntegrationService; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + *

+ * View Source + *

+ * + * @author Fei Yang + */ +@Controller +@RequestMapping("/servermaintain") +public class ServerMaintainController { + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/edit") + public String edit(@ModelAttribute ExtServerForm extServerForm, HttpServletRequest request) throws Exception { + Integer sid = WebUtil.readIntParam(request, "sid", true); + if (sid != null) { + ExtServer map = AdminServiceProxy.getIntegrationService(applicationContext.getServletContext()) + .getExtServer(sid); + BeanUtils.copyProperties(extServerForm, map); + } + return "servermaintain"; + } + + @RequestMapping("/edit") + public String disable(HttpServletRequest request) throws Exception { + IIntegrationService service = AdminServiceProxy.getIntegrationService(applicationContext.getServletContext()); + Integer sid = WebUtil.readIntParam(request, "sid", false); + ExtServer map = service.getExtServer(sid); + map.setDisabled(true); + service.saveExtServer(map); + return "forward:/serverlist.do"; + } + + @RequestMapping("/edit") + public String enable(HttpServletRequest request) throws Exception { + IIntegrationService service = AdminServiceProxy.getIntegrationService(applicationContext.getServletContext()); + Integer sid = WebUtil.readIntParam(request, "sid", false); + ExtServer map = service.getExtServer(sid); + map.setDisabled(false); + service.saveExtServer(map); + return "forward:/serverlist.do"; + } + + @RequestMapping("/edit") + public String delete(HttpServletRequest request) throws Exception { + Integer sid = WebUtil.readIntParam(request, "sid", false); + AdminServiceProxy.getService(applicationContext.getServletContext()).deleteById(ExtServer.class, sid); + return "forward:/serverlist.do"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ServerSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,121 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.ExtServerForm; +import org.lamsfoundation.lams.integration.ExtServer; +import org.lamsfoundation.lams.integration.service.IIntegrationService; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +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; + +/** + *

+ * View Source + *

+ * + * @author Fei Yang + */ +@Controller +public class ServerSaveController { + + private static IIntegrationService service; + private static IUserManagementService userService; + private static MessageService messageService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/serversave") + public String execute(@ModelAttribute ExtServerForm extServerForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (request.getAttribute("CANCEL") != null) { + return "servermaintain"; + } + + service = AdminServiceProxy.getIntegrationService(applicationContext.getServletContext()); + userService = AdminServiceProxy.getService(applicationContext.getServletContext()); + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + String[] requiredFields = { "serverid", "serverkey", "servername", "prefix", "userinfoUrl" }; + for (String requiredField : requiredFields) { + if (StringUtils.trimToNull(extServerForm.getString(requiredField)) == null) { + errorMap.add(requiredField, "error.required", messageService.getMessage("sysadmin." + requiredField)); + } + } + + Integer sid = extServerForm.getSid(); + if (errorMap.isEmpty()) {//check duplication + String[] uniqueFields = { "serverid", "prefix" }; + for (String uniqueField : uniqueFields) { + List list = userService.findByProperty(ExtServer.class, uniqueField, extServerForm.get(uniqueField)); + if (list != null && list.size() > 0) { + if (sid.equals(-1)) {//new map + errorMap.add(uniqueField, "error.not.unique", + messageService.getMessage("sysadmin." + uniqueField)); + } else { + ExtServer map = (ExtServer) list.get(0); + if (!map.getSid().equals(sid)) { + errorMap.add(uniqueField, "error.not.unique", + messageService.getMessage("sysadmin." + uniqueField)); + } + } + + } + } + } + if (errorMap.isEmpty()) { + ExtServer map = null; + if (sid.equals(-1)) { + map = new ExtServer(); + BeanUtils.copyProperties(map, extServerForm); + map.setSid(null); + map.setServerTypeId(ExtServer.INTEGRATION_SERVER_TYPE); + } else { + map = service.getExtServer(sid); + BeanUtils.copyProperties(map, extServerForm); + } + service.saveExtServer(map); + return "forward:/serverlist.do"; + } else { + request.setAttribute("errorMap", errorMap); + return "servermaintain"; + } + } +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SessionMaintainAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SessionMaintainController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SessionMaintainController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SessionMaintainController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,53 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +/** + * @author Marcin Cieslak + */ +@Controller +@RequestMapping("/sessionmaintain") +public class SessionMaintainController { + + @RequestMapping("/list") + public String list(HttpServletRequest request) { + request.setAttribute("sessions", SessionManager.getLoginToSessionIDMappings()); + return "sessionmaintain"; + } + + @RequestMapping("/delete") + public String delete(HttpServletRequest request) { + String login = request.getParameter("login"); + if (StringUtils.isNotBlank(login)) { + SessionManager.removeSessionByLogin(login, true); + } + return list(request); + } +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SignupManagementAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SignupManagementController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SignupManagementController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SignupManagementController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,184 @@ +package org.lamsfoundation.lams.admin.web.controller; + +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.web.form.SignupManagementForm; +import org.lamsfoundation.lams.signup.model.SignupOrganisation; +import org.lamsfoundation.lams.signup.service.ISignupService; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +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; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * + * + * + * + * + * + */ +@RequestMapping("/signupManagement") +public class SignupManagementController { + + private static Logger log = Logger.getLogger(SignupManagementController.class); + private static ISignupService signupService = null; + private static IUserManagementService userManagementService = null; + + @Autowired + private WebApplicationContext applicationContext; + + @Autowired + @Qualifier("adminMessageService") + private MessageService adminMessageService; + + @RequestMapping("/start") + public String execute(@ModelAttribute SignupManagementForm signupForm, HttpServletRequest request, + HttpServletResponse response) { + + try { + if (signupService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + signupService = (ISignupService) wac.getBean("signupService"); + } + if (userManagementService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + userManagementService = (IUserManagementService) wac.getBean("userManagementService"); + } + + String action = WebUtil.readStrParam(request, "action", true); + + if (StringUtils.equals(action, "list") || request.getAttribute("CANCEL") != null) { + // do nothing + } else if (StringUtils.equals(action, "edit")) { + return edit(signupForm, request); + } else if (StringUtils.equals(action, "add")) { + return add(signupForm, request); + } else if (StringUtils.equals(action, "delete")) { + return delete(request); + } + + List signupOrganisations = signupService.getSignupOrganisations(); + request.setAttribute("signupOrganisations", signupOrganisations); + } catch (Exception e) { + log.error(e.getMessage(), e); + request.setAttribute("error", e.getMessage()); + } + + return "signupmanagement/list"; + } + + @RequestMapping(path = "/edit", method = RequestMethod.POST) + public String edit(@ModelAttribute SignupManagementForm signupForm, HttpServletRequest request) throws Exception { + + Integer soid = WebUtil.readIntParam(request, "soid", false); + + if (soid != null && soid > 0) { + SignupOrganisation signup = (SignupOrganisation) userManagementService.findById(SignupOrganisation.class, + soid); + if (signup != null) { + signupForm.setSignupOrganisationId(signup.getSignupOrganisationId()); + signupForm.setOrganisationId(signup.getOrganisation().getOrganisationId()); + signupForm.setAddToLessons(signup.getAddToLessons()); + signupForm.setAddAsStaff(signup.getAddAsStaff()); + signupForm.setAddWithAuthor(signup.getAddWithAuthor()); + signupForm.setAddWithMonitor(signup.getAddWithMonitor()); + signupForm.setCourseKey(signup.getCourseKey()); + signupForm.setBlurb(signup.getBlurb()); + signupForm.setDisabled(signup.getDisabled()); + signupForm.setLoginTabActive(signup.getLoginTabActive()); + signupForm.setContext(signup.getContext()); + request.setAttribute("signupForm", signupForm); + + List organisations = signupService.getOrganisationCandidates(); + request.setAttribute("organisations", organisations); + + return "signupmanagement/add"; + } + } + return null; + } + + @RequestMapping(path = "/add", method = RequestMethod.POST) + public String add(@ModelAttribute SignupManagementForm signupForm, HttpServletRequest request) throws Exception { + + // check if form submitted + if (signupForm.getOrganisationId() != null && signupForm.getOrganisationId() > 0) { + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + + // validate + if (!StringUtils.equals(signupForm.getCourseKey(), signupForm.getConfirmCourseKey())) { + errorMap.add("courseKey", adminMessageService.getMessage("error.course.keys.unequal")); + } + if (signupService.contextExists(signupForm.getSignupOrganisationId(), signupForm.getContext())) { + errorMap.add("context", adminMessageService.getMessage("error.context.exists")); + } + + if (!errorMap.isEmpty()) { + request.setAttribute("errorMap", errorMap); + } else { + // proceed + SignupOrganisation signup; + if (signupForm.getSignupOrganisationId() != null && signupForm.getSignupOrganisationId() > 0) { + // form was editing existing + signup = (SignupOrganisation) userManagementService.findById(SignupOrganisation.class, + signupForm.getSignupOrganisationId()); + } else { + signup = new SignupOrganisation(); + signup.setCreateDate(new Date()); + } + signup.setAddToLessons(signupForm.isAddToLessons()); + signup.setAddAsStaff(signupForm.isAddAsStaff()); + signup.setAddWithAuthor(signupForm.isAddWithAuthor()); + signup.setAddWithMonitor(signupForm.isAddWithMonitor()); + signup.setDisabled(signupForm.isDisabled()); + signup.setLoginTabActive(signupForm.isLoginTabActive()); + signup.setOrganisation((Organisation) userManagementService.findById(Organisation.class, + signupForm.getOrganisationId())); + signup.setCourseKey(signupForm.getCourseKey()); + signup.setBlurb(signupForm.getBlurb()); + signup.setContext(signupForm.getContext()); + userManagementService.save(signup); + + return "forward:signupManagement/list.do"; + } + } else { + // form not submitted, default values + signupForm.setBlurb("Register your LAMS account for this group using the form below."); + } + + List organisations = signupService.getOrganisationCandidates(); + request.setAttribute("organisations", organisations); + + return "signupmanagement/add"; + } + + @RequestMapping(path = "/delete", method = RequestMethod.POST) + public String delete(HttpServletRequest request) throws Exception { + + Integer soid = WebUtil.readIntParam(request, "soid"); + + if (soid != null && soid > 0) { + userManagementService.deleteById(SignupOrganisation.class, soid); + } + + return "forward:signupManagement/list.do"; + } +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/StatisticsAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/StatisticsController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/StatisticsController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/StatisticsController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,101 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.statistics.dto.GroupStatisticsDTO; +import org.lamsfoundation.lams.statistics.dto.StatisticsDTO; +import org.lamsfoundation.lams.statistics.service.IStatisticsService; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.util.WebUtil; +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; + +/** + * Gives the overall statistics for a LAMS server + * + * @author Luke Foxton + */ +@Controller +@RequestMapping("/statistics") +public class StatisticsController { + + private static IStatisticsService statisticsService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/start") + public String unspecified(HttpServletRequest request) throws Exception { + + // check permission + if (!request.isUserInRole(Role.SYSADMIN)) { + request.setAttribute("errorName", "StatisticsAction"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.authorisation")); + return "error"; + } + + if (statisticsService == null) { + statisticsService = AdminServiceProxy.getStatisticsService(applicationContext.getServletContext()); + } + + StatisticsDTO stats = statisticsService.getOverallStatistics(); + + Map groupMap = statisticsService.getGroupMap(); + + request.setAttribute("statisticsDTO", stats); + request.setAttribute("groupMap", groupMap); + return "statistics"; + } + + @RequestMapping("/groupStats") + public String groupStats(HttpServletRequest request) throws Exception { + + Integer orgId = WebUtil.readIntParam(request, "orgId"); + + // check permission + if (!request.isUserInRole(Role.SYSADMIN)) { + request.setAttribute("errorName", "StatisticsAction"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.authorisation")); + return "error"; + } + + if (statisticsService == null) { + statisticsService = AdminServiceProxy.getStatisticsService(applicationContext.getServletContext()); + } + + GroupStatisticsDTO groupStats = statisticsService.getGroupStatisticsDTO(orgId); + + request.setAttribute("groupStatisticsDTO", groupStats); + return "groupStatistics"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SysAdminStartAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SysAdminStartController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SysAdminStartController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/SysAdminStartController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,105 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; + +import javax.servlet.http.HttpServletRequest; + +import org.lamsfoundation.lams.admin.AdminConstants; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.dto.LinkBean; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +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; + +/** + * @author jliew + * + */ +@Controller +public class SysAdminStartController { + + private static IUserManagementService service; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/sysadminstart") + public String execute(HttpServletRequest request) throws Exception { + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + + ArrayList groupedLinks = new ArrayList<>(); + + if (request.isUserInRole(Role.SYSADMIN)) { + ArrayList links = new ArrayList<>(); + links.add(new LinkBean("config.do", "sysadmin.config.settings.edit")); + links.add(new LinkBean("timezonemanagement.do", "admin.timezone.title")); + links.add(new LinkBean("loginmaintain.do", "sysadmin.maintain.loginpage")); + links.add(new LinkBean("signupManagement.do", "admin.signup.title")); + links.add(new LinkBean("serverlist.do", "sysadmin.maintain.external.servers")); + links.add(new LinkBean("ltiConsumerManagement.do", "label.manage.tool.consumers")); + links.add(new LinkBean("toolcontentlist.do", "sysadmin.tool.management")); + links.add(new LinkBean("themeManagement.do", "admin.themes.title")); + links.add(new LinkBean("sessionmaintain.do?method=list", "sysadmin.maintain.session")); + groupedLinks.add(new Object[] { AdminConstants.START_CONFIG_LINKS, links }); + + links = new ArrayList<>(); + links.add(new LinkBean("logevent.do", "label.event.log")); + links.add(new LinkBean("cleanup.do", "sysadmin.batch.temp.file.delete")); + links.add(new LinkBean("cleanupPreviewLessons.do", "sysadmin.batch.preview.lesson.delete")); + links.add(new LinkBean("statistics.do", "admin.statistics.title")); + groupedLinks.add(new Object[] { AdminConstants.START_MONITOR_LINKS, links }); + + links = new ArrayList<>(); + links.add(new LinkBean("usersearch.do", "admin.user.find")); + links.add(new LinkBean("importgroups.do", "sysadmin.import.groups.title")); + links.add(new LinkBean("importexcel.do", "admin.user.import")); + links.add(new LinkBean("disabledmanage.do", "admin.list.disabled.users")); + links.add(new LinkBean("ldap.do", "sysadmin.ldap.configuration")); + groupedLinks.add(new Object[] { AdminConstants.START_COURSE_LINKS, links }); + + } else if (service.isUserGlobalGroupAdmin()) { + ArrayList links = new ArrayList<>(); + links.add(new LinkBean("usersearch.do", "admin.user.find")); + links.add(new LinkBean("importgroups.do", "sysadmin.import.groups.title")); + links.add(new LinkBean("importexcel.do", "admin.user.import")); + links.add(new LinkBean("disabledmanage.do", "admin.list.disabled.users")); + groupedLinks.add(new Object[] { AdminConstants.START_COURSE_LINKS, links }); + + } else { + request.setAttribute("errorName", "SysAdminStartAction"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.authorisation")); + return "error"; + } + + request.setAttribute("groupedLinks", groupedLinks); + return "sysadmin"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ThemeManagementAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ThemeManagementController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ThemeManagementController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ThemeManagementController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,168 @@ +/**************************************************************** + * Copyright (C) 2006 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.admin.web.controller; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.ThemeForm; +import org.lamsfoundation.lams.themes.Theme; +import org.lamsfoundation.lams.themes.service.IThemeService; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.util.CSSThemeUtil; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * Actions for maintaining and altering system themes + * + * @author Luke Foxton + */ +@Controller +@RequestMapping("/themeManagement") +public class ThemeManagementController { + + private static IThemeService themeService; + private static Configuration configurationService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/start") + public String unspecified(@ModelAttribute ThemeForm themeForm, HttpServletRequest request) throws Exception { + + // check permission + if (!request.isUserInRole(Role.SYSADMIN)) { + request.setAttribute("errorName", "ThemeManagementAction"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.authorisation")); + return "error"; + } + + if (ThemeManagementController.themeService == null) { + ThemeManagementController.themeService = AdminServiceProxy + .getThemeService(applicationContext.getServletContext()); + } + + // Get all the themes + List themes = ThemeManagementController.themeService.getAllThemes(); + + // Flag the default and un-editable themes + String currentCSSTheme = Configuration.get(ConfigurationKeys.DEFAULT_THEME); + for (Theme theme : themes) { + theme.setCurrentDefaultTheme(theme.getName().equals(currentCSSTheme)); + theme.setNotEditable(theme.getName().equals(CSSThemeUtil.DEFAULT_HTML_THEME)); + } + + request.setAttribute("themes", themes); + return "themeManagement"; + } + + @RequestMapping(path = "/addOrEditTheme", method = RequestMethod.POST) + public String addOrEditTheme(@ModelAttribute ThemeForm themeForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + // Update the theme + Theme theme = null; + if ((themeForm.getId() != null) && (themeForm.getId() != 0)) { + theme = ThemeManagementController.themeService.getTheme(themeForm.getId()); + } else { + theme = new Theme(); + } + updateThemeFromForm(theme, themeForm); + ThemeManagementController.themeService.saveOrUpdateTheme(theme); + + // Set the theme as default, or disable it as default. + // Disabling restores the system default + if ((themeForm.getCurrentDefaultTheme() != null) && (themeForm.getCurrentDefaultTheme() == true)) { + Configuration.updateItem(ConfigurationKeys.DEFAULT_THEME, themeForm.getName()); + getConfiguration().persistUpdate(); + } else { + String currentTheme = Configuration.get(ConfigurationKeys.DEFAULT_THEME); + if (themeForm.getName().equals(currentTheme)) { + Configuration.updateItem(ConfigurationKeys.DEFAULT_THEME, CSSThemeUtil.DEFAULT_HTML_THEME); + getConfiguration().persistUpdate(); + } + } + themeForm.clear(); + return unspecified(themeForm, request); + } + + @RequestMapping(path = "/removeTheme", method = RequestMethod.POST) + public String removeTheme(@ModelAttribute ThemeForm themeForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + // Remove the theme + if (themeForm.getId() != null) { + ThemeManagementController.themeService.removeTheme(themeForm.getId()); + } + + String currentTheme = Configuration.get(ConfigurationKeys.DEFAULT_THEME); + if (themeForm.getName().equals(currentTheme)) { + Configuration.updateItem(ConfigurationKeys.DEFAULT_THEME, CSSThemeUtil.DEFAULT_HTML_THEME); + getConfiguration().persistUpdate(); + } + + themeForm.clear(); + return unspecified(themeForm, request); + } + + @RequestMapping(path = "/setAsDefault", method = RequestMethod.POST) + public String setAsDefault(@ModelAttribute ThemeForm themeForm, HttpServletRequest request) throws Exception { + + if (themeForm.getName() != null) { + Configuration.updateItem(ConfigurationKeys.DEFAULT_THEME, themeForm.getName()); + getConfiguration().persistUpdate(); + } + themeForm.clear(); + return unspecified(themeForm, request); + } + + private Theme updateThemeFromForm(Theme theme, ThemeForm form) { + theme.setName(form.getName()); + theme.setDescription(form.getDescription()); + theme.setImageDirectory(form.getImageDirectory()); + // theme.setType(Integer.parseInt(form.getType())); no longer in form see LDEV-3674 + return theme; + } + + private Configuration getConfiguration() { + if (ThemeManagementController.configurationService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + ThemeManagementController.configurationService = (Configuration) ctx.getBean("configurationService"); + + } + return ThemeManagementController.configurationService; + } +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/TimezoneManagementAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/TimezoneManagementController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/TimezoneManagementController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/TimezoneManagementController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,144 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.List; +import java.util.TimeZone; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.TimezoneForm; +import org.lamsfoundation.lams.timezone.Timezone; +import org.lamsfoundation.lams.timezone.dto.TimezoneDTO; +import org.lamsfoundation.lams.timezone.service.ITimezoneService; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.context.WebApplicationContext; + +/** + * Implements time zone manager. + * + * @author Andrey Balan + * + * + * + * + * + * + */ +@Controller +@RequestMapping("/timezonemanagement") +public class TimezoneManagementController { + + private static ITimezoneService timezoneService; + + @Autowired + private WebApplicationContext applicationContext; + + /** + * Displays list of all JRE available timezones. + */ + @RequestMapping("/start") + public String unspecified(HttpServletRequest request) throws Exception { + + timezoneService = AdminServiceProxy.getTimezoneService(applicationContext.getServletContext()); + List defaultTimezones = timezoneService.getDefaultTimezones(); + + ArrayList timezoneDtos = new ArrayList<>(); + for (String availableTimezoneId : TimeZone.getAvailableIDs()) { + boolean isSelected = defaultTimezones.contains(new Timezone(availableTimezoneId)); + TimeZone timeZone = TimeZone.getTimeZone(availableTimezoneId); + TimezoneDTO timezoneDto = TimezoneDTO.createTimezoneDTO(timeZone, isSelected); + timezoneDtos.add(timezoneDto); + } + + request.setAttribute("timezoneDtos", timezoneDtos); + request.setAttribute("serverTimezone", timezoneService.getServerTimezone().getTimezoneId()); + + return "timezoneManagement"; + } + + /** + * Makes selected timezones default ones. + */ + @RequestMapping(path = "/save", method = RequestMethod.POST) + public String save(@ModelAttribute TimezoneForm timezoneForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (request.getAttribute("CANCEL") != null) { + return "redirect:/sysadminstart.do"; + } + + String[] selectedTimezoneIds = timezoneForm.getSelected(); + + List selectedTimezones = new ArrayList<>(); + for (String selectedTimezoneId : selectedTimezoneIds) { + selectedTimezones.add(new Timezone(selectedTimezoneId)); + } + timezoneService.updateTimezones(selectedTimezones); + + return "redirect:/sysadminstart.do"; + } + + /** + * Shows page where admin can choose server timezone. + */ + @RequestMapping(path = "/serverTimezoneManagement", method = RequestMethod.POST) + public String serverTimezoneManagement(HttpServletRequest request) throws Exception { + + timezoneService = AdminServiceProxy.getTimezoneService(applicationContext.getServletContext()); + + ArrayList timezoneDtos = new ArrayList<>(); + for (String availableTimezoneId : TimeZone.getAvailableIDs()) { + TimeZone timeZone = TimeZone.getTimeZone(availableTimezoneId); + TimezoneDTO timezoneDto = TimezoneDTO.createTimezoneDTO(timeZone, false); + timezoneDtos.add(timezoneDto); + } + + request.setAttribute("timezoneDtos", timezoneDtos); + request.setAttribute("serverTimezone", timezoneService.getServerTimezone().getTimezoneId()); + + return "timezoneServerManagement"; + } + + /** + * Changes server timezone with the one selected by user. + */ + @RequestMapping(path = "/changeServerTimezone", method = RequestMethod.POST) + public String changeServerTimezone(HttpServletRequest request) throws Exception { + timezoneService = AdminServiceProxy.getTimezoneService(applicationContext.getServletContext()); + + String timeZoneId = WebUtil.readStrParam(request, "timeZoneId"); + timezoneService.setServerTimezone(timeZoneId); + + return unspecified(request); + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ToolContentListAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ToolContentListController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ToolContentListController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/ToolContentListController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,310 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; +import javax.sql.DataSource; + +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.learningdesign.LearningLibrary; +import org.lamsfoundation.lams.learningdesign.LearningLibraryGroup; +import org.lamsfoundation.lams.learningdesign.dto.LearningLibraryDTO; +import org.lamsfoundation.lams.learningdesign.dto.LibraryActivityDTO; +import org.lamsfoundation.lams.learningdesign.service.ILearningDesignService; +import org.lamsfoundation.lams.tool.Tool; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +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.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.fasterxml.jackson.databind.node.ObjectNode; + +/** + * @author jliew + * + * + * + * + * + * + */ +@Controller +@RequestMapping("/toolcontentlist") +public class ToolContentListController { + + private static ILearningDesignService learningDesignService; + private static IUserManagementService userManagementService; + private static DataSource dataSource; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/start") + public String execute(HttpServletRequest request) throws Exception { + // check permission + if (!(request.isUserInRole(Role.SYSADMIN))) { + request.setAttribute("errorName", "ToolContentListAction"); + request.setAttribute("errorMessage", AdminServiceProxy + .getMessageService(applicationContext.getServletContext()).getMessage("error.authorisation")); + return "error"; + } + + // not just display, but enable/disable a learning library + String param = request.getParameter("action"); + if (StringUtils.equals(param, "enable")) { + if (checkPriviledge(request)) { + enableLibrary(request); + } else { + return "error"; + } + } else if (StringUtils.equals(param, "disable")) { + if (checkPriviledge(request)) { + disableLibrary(request); + } else { + return "error"; + } + } else if (StringUtils.equals(param, "openLearningLibraryGroups")) { + return openLearningLibraryGroups(request); + } else if (StringUtils.equals(param, "saveLearningLibraryGroups")) { + saveLearningLibraryGroups(request); + return null; + } + + // get learning library dtos and their validity + List learningLibraryDTOs = getLearningDesignService().getAllLearningLibraryDetails(false, + getUserLanguage()); + // this is filled when executing following method, for efficiency purposes + HashMap learningLibraryValidity = new HashMap<>(learningLibraryDTOs.size()); + ArrayList toolLibrary = filterMultipleToolEntries(learningLibraryDTOs, + learningLibraryValidity); + request.setAttribute("toolLibrary", toolLibrary); + request.setAttribute("learningLibraryValidity", learningLibraryValidity); + + // get tool versions + HashMap toolVersions = new HashMap<>(); + List tools = getUserManagementService().findAll(Tool.class); + for (Tool tool : tools) { + toolVersions.put(tool.getToolId(), tool.getToolVersion()); + } + request.setAttribute("toolVersions", toolVersions); + + // get tool database versions + HashMap dbVersions = new HashMap<>(); + Connection conn = getDataSource().getConnection(); + PreparedStatement query = conn.prepareStatement("select system_name, patch_level from patches"); + ResultSet results = query.executeQuery(); + while (results.next()) { + dbVersions.put(results.getString("system_name"), results.getInt("patch_level")); + } + request.setAttribute("dbVersions", dbVersions); + + return "toolcontent/toolcontentlist"; + } + + // returns full list of learning libraries, valid or not + @SuppressWarnings("unchecked") + private ArrayList filterMultipleToolEntries(List learningLibraryDTOs, + HashMap learningLibraryValidity) { + ArrayList activeTools = new ArrayList<>(); + ArrayList activeCombinedTools = new ArrayList<>(); + for (LearningLibraryDTO learningLibraryDTO : learningLibraryDTOs) { + // populate information about learning libary validity + learningLibraryValidity.put(learningLibraryDTO.getLearningLibraryID(), learningLibraryDTO.getValidFlag()); + for (LibraryActivityDTO template : (List) learningLibraryDTO.getTemplateActivities()) { + // no learning library ID = a part of combined learning library, we already have it in the list + if (template.getLearningLibraryID() != null) { + // combined libraries do not have tool content ID set + if (template.getToolContentID() == null) { + if (!toolExists(template, activeCombinedTools)) { + activeCombinedTools.add(template); + } + } else { + if (!toolExists(template, activeTools)) { + activeTools.add(template); + } + } + } + } + } + // put combined libraries at the end, purely for easy of use + activeTools.addAll(activeCombinedTools); + return activeTools; + } + + private boolean toolExists(LibraryActivityDTO newItem, ArrayList list) { + for (LibraryActivityDTO libraryActivityDTO : list) { + if (newItem.getLearningLibraryID().equals(libraryActivityDTO.getLearningLibraryID())) { + return true; + } + } + return false; + } + + private String getUserLanguage() { + HttpSession ss = SessionManager.getSession(); + UserDTO user = (UserDTO) ss.getAttribute(AttributeNames.USER); + return user == null ? "" : user.getLocaleLanguage(); + } + + private boolean checkPriviledge(HttpServletRequest request) { + if (!getUserManagementService().isUserSysAdmin()) { + request.setAttribute("errorName", "ToolContentListAction"); + request.setAttribute("errorMessage", + AdminServiceProxy.getMessageService(applicationContext.getServletContext()) + .getMessage("error.no.sysadmin.priviledge")); + return false; + } + return true; + } + + @RequestMapping("/disableLibrary") + private void disableLibrary(HttpServletRequest request) { + Long learningLibraryId = WebUtil.readLongParam(request, "libraryID", false); + ILearningDesignService ldService = getLearningDesignService(); + ldService.setValid(learningLibraryId, false); + } + + @RequestMapping("/enableLibrary") + private void enableLibrary(HttpServletRequest request) { + Long learningLibraryId = WebUtil.readLongParam(request, "libraryID", false); + ILearningDesignService ldService = getLearningDesignService(); + ldService.setValid(learningLibraryId, true); + + } + + /** + * Loads groups and libraries and displays the management dialog. + */ + @RequestMapping("/openLearningLibraryGroups") + public String openLearningLibraryGroups(HttpServletRequest request) throws IOException { + // build full list of available learning libraries + List learningLibraries = getLearningDesignService() + .getAllLearningLibraryDetails(getUserLanguage()); + ArrayNode learningLibrariesJSON = JsonNodeFactory.instance.arrayNode(); + for (LearningLibraryDTO learningLibrary : learningLibraries) { + ObjectNode learningLibraryJSON = JsonNodeFactory.instance.objectNode(); + learningLibraryJSON.put("learningLibraryId", learningLibrary.getLearningLibraryID()); + learningLibraryJSON.put("title", learningLibrary.getTitle()); + learningLibrariesJSON.add(learningLibraryJSON); + } + request.setAttribute("learningLibraries", learningLibrariesJSON.toString()); + + // build list of existing groups + List groups = getLearningDesignService().getLearningLibraryGroups(); + ArrayNode groupsJSON = JsonNodeFactory.instance.arrayNode(); + for (LearningLibraryGroup group : groups) { + ObjectNode groupJSON = JsonNodeFactory.instance.objectNode(); + groupJSON.put("groupId", group.getGroupId()); + groupJSON.put("name", group.getName()); + for (LearningLibrary learningLibrary : group.getLearningLibraries()) { + ObjectNode learningLibraryJSON = JsonNodeFactory.instance.objectNode(); + learningLibraryJSON.put("learningLibraryId", learningLibrary.getLearningLibraryId()); + learningLibraryJSON.put("title", learningLibrary.getTitle()); + groupJSON.withArray("learningLibraries").add(learningLibraryJSON); + } + groupsJSON.add(groupJSON); + } + request.setAttribute("groups", groupsJSON.toString()); + + return "toolcontent/learningLibraryGroup"; + } + + @RequestMapping("/saveLearningLibraryGroups") + private void saveLearningLibraryGroups(HttpServletRequest request) throws IOException { + // extract groups from JSON and persist them + + ArrayNode groupsJSON = JsonUtil.readArray(request.getParameter("groups")); + List groups = new ArrayList<>(groupsJSON.size()); + for (JsonNode groupJSON : groupsJSON) { + LearningLibraryGroup group = new LearningLibraryGroup(); + groups.add(group); + + long groupId = groupJSON.get("groupId").asLong(); + if (groupId > 0) { + group.setGroupId(groupId); + } + group.setName(groupJSON.get("name").asText(null)); + + group.setLearningLibraries(new HashSet()); + ArrayNode learningLibrariesJSON = (ArrayNode) groupJSON.get("learningLibraries"); + for (JsonNode learningLibraryJSON : learningLibrariesJSON) { + long learningLibraryId = learningLibraryJSON.asLong(); + LearningLibrary learningLibrary = getLearningDesignService().getLearningLibrary(learningLibraryId); + group.getLearningLibraries().add(learningLibrary); + } + } + + getLearningDesignService().saveLearningLibraryGroups(groups); + } + + private ILearningDesignService getLearningDesignService() { + if (ToolContentListController.learningDesignService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + ToolContentListController.learningDesignService = (ILearningDesignService) ctx + .getBean("learningDesignService"); + } + return ToolContentListController.learningDesignService; + } + + private IUserManagementService getUserManagementService() { + if (ToolContentListController.userManagementService == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + ToolContentListController.userManagementService = (IUserManagementService) ctx + .getBean("userManagementService"); + } + return ToolContentListController.userManagementService; + } + + private DataSource getDataSource() { + if (ToolContentListController.dataSource == null) { + WebApplicationContext ctx = WebApplicationContextUtils + .getRequiredWebApplicationContext(applicationContext.getServletContext()); + ToolContentListController.dataSource = (DataSource) ctx.getBean("dataSource"); + } + return ToolContentListController.dataSource; + } +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserAction.java'. Fisheye: No comparison available. Pass `N' to diff? Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserBasicListAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserBasicListController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserBasicListController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserBasicListController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,115 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.Role; +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.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author jliew + * + * + * + * + */ +@Controller +public class UserBasicListController { + + private static IUserManagementService service; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/user/basiclist") + public String execute(HttpServletRequest request) throws Exception { + + UserBasicListController.service = AdminServiceProxy.getService(applicationContext.getServletContext()); + HttpSession session = SessionManager.getSession(); + if (session != null) { + UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); + if (userDto != null) { + // get inputs + Integer userId = userDto.getUserID(); + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + String potential = WebUtil.readStrParam(request, "potential", true); + if (orgId != null) { + if (!StringUtils.equals(potential, "1")) { + // list users in org + List users = UserBasicListController.service.getUsersFromOrganisation(orgId); + request.setAttribute("users", users); + } else { + // get all potential users of this org instead... filters results according to user's roles + // get group + Organisation org = (Organisation) UserBasicListController.service.findById(Organisation.class, + orgId); + Organisation group; + if (org != null) { + if (org.getOrganisationType().getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) { + group = org.getParentOrganisation(); + } else { + group = org; + } + // get users + List users = new ArrayList(); + if (request.isUserInRole(Role.SYSADMIN) + || UserBasicListController.service.isUserGlobalGroupAdmin()) { + users = UserBasicListController.service.getAllUsers(org.getOrganisationId()); + } else if (UserBasicListController.service.isUserInRole(userId, group.getOrganisationId(), + Role.GROUP_ADMIN) + || UserBasicListController.service.isUserInRole(userId, group.getOrganisationId(), + Role.GROUP_MANAGER)) { + if (group.getCourseAdminCanBrowseAllUsers()) { + users = UserBasicListController.service.getAllUsers(org.getOrganisationId()); + } else if (org.getOrganisationType().getOrganisationTypeId() + .equals(OrganisationType.CLASS_TYPE)) { + users = UserBasicListController.service.findUsers(null, group.getOrganisationId(), + orgId); + } + } + request.setAttribute("users", users); + } + } + } + } + } + return "user/basiclist"; + } +} \ No newline at end of file Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,402 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.Collections; +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.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.dto.UserOrgRoleDTO; +import org.lamsfoundation.lams.admin.web.form.UserForm; +import org.lamsfoundation.lams.logevent.LogEvent; +import org.lamsfoundation.lams.logevent.service.ILogEventService; +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.TimezoneDTOComparator; +import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; +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.SupportedLocale; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.UserOrganisation; +import org.lamsfoundation.lams.usermanagement.UserOrganisationRole; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.LanguageUtil; +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.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author Jun-Dir Liew + */ +@Controller +@RequestMapping("/user") +public class UserController { + + private static Logger log = Logger.getLogger(UserController.class); + private IUserManagementService service; + private MessageService messageService; + private static IThemeService themeService; + private static ITimezoneService timezoneService; + private static List locales; + private static List authenticationMethods; + + @Autowired + private WebApplicationContext applicationContext; + + private void initServices() { + if (service == null) { + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + } + if (messageService == null) { + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + } + if (UserController.themeService == null) { + UserController.themeService = AdminServiceProxy.getThemeService(applicationContext.getServletContext()); + } + if (UserController.timezoneService == null) { + UserController.timezoneService = AdminServiceProxy + .getTimezoneService(applicationContext.getServletContext()); + } + } + + @RequestMapping(path = "/edit", method = RequestMethod.POST) + public String edit(@ModelAttribute UserForm userForm, HttpServletRequest request) throws Exception { + + initServices(); + if (UserController.locales == null) { + UserController.locales = service.findAll(SupportedLocale.class); + Collections.sort(UserController.locales); + } + if (UserController.authenticationMethods == null) { + UserController.authenticationMethods = service.findAll(AuthenticationMethod.class); + } + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId", true); + + // Get all the css themess + List themes = UserController.themeService.getAllThemes(); + request.setAttribute("themes", themes); + + // Select the default themes by default + Theme defaultTheme = UserController.themeService.getDefaultTheme(); + for (Theme theme : themes) { + if (theme.getThemeId().equals(defaultTheme.getThemeId())) { + userForm.setUserTheme(theme.getThemeId()); + break; + } + } + + // test requestor's permission + Organisation org = null; + Boolean canEdit = service.isUserGlobalGroupAdmin(); + if (orgId != null) { + org = (Organisation) service.findById(Organisation.class, orgId); + if (!canEdit) { + OrganisationType orgType = org.getOrganisationType(); + Integer orgIdOfCourse = orgType.getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE) + ? org.getParentOrganisation().getOrganisationId() + : orgId; + User requestor = service.getUserByLogin(request.getRemoteUser()); + if (service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_ADMIN) + || service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_MANAGER)) { + Organisation course = (Organisation) service.findById(Organisation.class, orgIdOfCourse); + canEdit = course.getCourseAdminCanAddNewUsers(); + } + } + } + + if (!(canEdit || request.isUserInRole(Role.SYSADMIN))) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + + // editing a user + if ((userId != null) && (userId != 0)) { + User user = (User) service.findById(User.class, userId); + UserController.log.debug("got userid to edit: " + userId); + BeanUtils.copyProperties(userForm, user); + userForm.setPassword(null); + SupportedLocale locale = user.getLocale(); + userForm.setLocaleId(locale.getLocaleId()); + + AuthenticationMethod authenticationMethod = user.getAuthenticationMethod(); + userForm.setAuthenticationMethodId(authenticationMethod.getAuthenticationMethodId()); + // set user's organisations to display + request.setAttribute("userOrgRoles", getUserOrgRoles(user)); + request.setAttribute("globalRoles", getGlobalRoles(user)); + + // Check the user css theme is still installed + Long userSelectedTheme = null; + if (user.getTheme() != null) { + for (Theme theme : themes) { + if (theme.getThemeId() == user.getTheme().getThemeId()) { + userSelectedTheme = theme.getThemeId(); + break; + } + } + } + // if still null, use the default + if (userSelectedTheme == null) { + userSelectedTheme = UserController.themeService.getDefaultTheme().getThemeId(); + } + userForm.setUserTheme(userSelectedTheme); + userForm.setInitialPortraitId(user.getPortraitUuid()); + + //property available for modification only to sysadmins + userForm.setTwoFactorAuthenticationEnabled(user.isTwoFactorAuthenticationEnabled()); + } else { // create a user + try { + SupportedLocale locale = LanguageUtil.getDefaultLocale(); + userForm.setLocaleId(locale.getLocaleId()); + } catch (Exception e) { + UserController.log.debug(e); + } + } + userForm.setOrgId(org == null ? null : org.getOrganisationId()); + + // sysadmins can mark users as required to use two-factor authentication + if (request.isUserInRole(Role.SYSADMIN)) { + request.setAttribute("isSysadmin", true); + } + + // Get all available time zones + List availableTimeZones = UserController.timezoneService.getDefaultTimezones(); + TreeSet timezoneDtos = new TreeSet<>(new TimezoneDTOComparator()); + 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); + + // for breadcrumb links + if (org != null) { + request.setAttribute("orgName", org.getName()); + Organisation parentOrg = org.getParentOrganisation(); + if ((parentOrg != null) && !parentOrg.equals(service.getRootOrganisation())) { + request.setAttribute("pOrgId", parentOrg.getOrganisationId()); + request.setAttribute("parentName", parentOrg.getName()); + } + } + + request.setAttribute("locales", UserController.locales); + request.setAttribute("authenticationMethods", UserController.authenticationMethods); + + return "user"; + } + + // display user's global roles, if any + private UserOrgRoleDTO getGlobalRoles(User user) { + initServices(); + UserOrganisation uo = service.getUserOrganisation(user.getUserId(), + service.getRootOrganisation().getOrganisationId()); + if (uo == null) { + return null; + } + UserOrgRoleDTO uorDTO = new UserOrgRoleDTO(); + List roles = new ArrayList<>(); + for (Object uor : uo.getUserOrganisationRoles()) { + roles.add(((UserOrganisationRole) uor).getRole().getName()); + } + Collections.sort(roles); + uorDTO.setOrgName(uo.getOrganisation().getName()); + uorDTO.setRoles(roles); + return uorDTO; + } + + // display user's organisations and roles in them + @SuppressWarnings("unchecked") + private List getUserOrgRoles(User user) { + + initServices(); + List uorDTOs = new ArrayList<>(); + List uos = service.getUserOrganisationsForUserByTypeAndStatus(user.getLogin(), + OrganisationType.COURSE_TYPE, OrganisationState.ACTIVE); + for (UserOrganisation uo : uos) { + UserOrgRoleDTO uorDTO = new UserOrgRoleDTO(); + List roles = new ArrayList<>(); + for (Object uor : uo.getUserOrganisationRoles()) { + roles.add(((UserOrganisationRole) uor).getRole().getName()); + } + Collections.sort(roles); + uorDTO.setOrgName(uo.getOrganisation().getName()); + uorDTO.setRoles(roles); + List childDTOs = new ArrayList<>(); + List childuos = service.getUserOrganisationsForUserByTypeAndStatusAndParent( + user.getLogin(), OrganisationType.CLASS_TYPE, OrganisationState.ACTIVE, + uo.getOrganisation().getOrganisationId()); + for (UserOrganisation childuo : childuos) { + UserOrgRoleDTO childDTO = new UserOrgRoleDTO(); + List childroles = new ArrayList<>(); + for (Object uor : childuo.getUserOrganisationRoles()) { + childroles.add(((UserOrganisationRole) uor).getRole().getName()); + } + Collections.sort(childroles); + childDTO.setOrgName(childuo.getOrganisation().getName()); + childDTO.setRoles(childroles); + childDTOs.add(childDTO); + } + uorDTO.setChildDTOs(childDTOs); + uorDTOs.add(uorDTO); + } + + return uorDTOs; + } + + // determine whether to disable or delete user based on their lams data + @RequestMapping(path = "/remove", method = RequestMethod.POST) + public String remove(HttpServletRequest request) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId"); + User user = (User) service.findById(User.class, userId); + + Boolean hasData = service.userHasData(user); + + request.setAttribute("method", (hasData ? "disable" : "delete")); + request.setAttribute("orgId", orgId); + request.setAttribute("userId", userId); + return "remove"; + } + + @RequestMapping(path = "/disable", method = RequestMethod.POST) + public String disable(HttpServletRequest request) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + UserDTO sysadmin = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId"); + service.disableUser(userId); + String[] args = new String[1]; + args[0] = userId.toString(); + String message = messageService.getMessage("audit.user.disable", args); + ILogEventService logEventService = AdminServiceProxy.getLogEventService(applicationContext.getServletContext()); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, sysadmin != null ? sysadmin.getUserID() : null, userId, + null, null, message); + if ((orgId == null) || (orgId == 0)) { + return "forward:/usersearch.do"; + } else { + request.setAttribute("org", orgId); + return "forward:/usermanage.do"; + } + } + + @RequestMapping(path = "/delete", method = RequestMethod.POST) + public String delete(HttpServletRequest request) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + UserDTO sysadmin = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId"); + try { + service.removeUser(userId); + } catch (Exception e) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", e.getMessage()); + return "error"; + } + String[] args = new String[1]; + args[0] = userId.toString(); + String message = messageService.getMessage("audit.user.delete", args); + ILogEventService logEventService = AdminServiceProxy.getLogEventService(applicationContext.getServletContext()); + logEventService.logEvent(LogEvent.TYPE_USER_ORG_ADMIN, sysadmin != null ? sysadmin.getUserID() : null, userId, + null, null, message); + if ((orgId == null) || (orgId == 0)) { + return "forward:/usersearch.do"; + } else { + request.setAttribute("org", orgId); + return "forward:/usermanage.do"; + } + } + + // called from disabled users screen + @RequestMapping(path = "/enable", method = RequestMethod.POST) + public String enable(HttpServletRequest request) throws Exception { + + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + request.setAttribute("errorName", "UserAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + + Integer userId = WebUtil.readIntParam(request, "userId", true); + User user = (User) service.findById(User.class, userId); + + UserController.log.debug("enabling user: " + userId); + user.setDisabledFlag(false); + service.saveUser(user); + + return "forward:/disabledmanage.do"; + } + +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserManageAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserManageController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserManageController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserManageController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,172 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.dto.UserListDTO; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.dto.UserManageBean; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +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; + +/** + * @author Jun-Dir Liew + * + * Created at 13:51:51 on 9/06/2006 + */ + +/** + * + * + * + * + */ +@Controller +@RequestMapping("/usermanage") +public class UserManageController { + + private static final Logger log = Logger.getLogger(UserManageController.class); + private static IUserManagementService service; + private static MessageService messageService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/usermanage") + public String execute(HttpServletRequest request, HttpServletResponse response) throws Exception { + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + + // get id of org to list users for + Integer orgId = WebUtil.readIntParam(request, "org", true); + if (orgId == null) { + orgId = (Integer) request.getAttribute("org"); + } + if ((orgId == null) || (orgId <= 0)) { + return forwardError(request, "error.org.invalid"); + } + log.debug("orgId: " + orgId); + + // get org name + Organisation organisation = (Organisation) service.findById(Organisation.class, orgId); + if (organisation == null) { + return forwardError(request, "error.org.invalid"); + } + String orgName = organisation.getName(); + log.debug("orgName: " + orgName); + + Organisation pOrg = organisation.getParentOrganisation(); + if (pOrg != null) { + request.setAttribute("pOrgId", pOrg.getOrganisationId()); + request.setAttribute("pOrgName", pOrg.getName()); + } + OrganisationType orgType = organisation.getOrganisationType(); + request.setAttribute("orgType", orgType.getOrganisationTypeId()); + + // create form object + UserListDTO userManageForm = new UserListDTO(); + + Integer userId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); + Organisation orgOfCourseAdmin = (orgType.getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) ? pOrg + : organisation; + // check permission + Integer rootOrgId = service.getRootOrganisation().getOrganisationId(); + if (request.isUserInRole(Role.SYSADMIN) || (service.isUserGlobalGroupAdmin() && !orgId.equals(rootOrgId))) { + userManageForm.setCourseAdminCanAddNewUsers(true); + userManageForm.setCourseAdminCanBrowseAllUsers(true); + request.setAttribute("canDeleteUser", true); + } else if ((service.isUserInRole(userId, orgOfCourseAdmin.getOrganisationId(), Role.GROUP_ADMIN) + || service.isUserInRole(userId, orgOfCourseAdmin.getOrganisationId(), Role.GROUP_MANAGER)) + && !orgId.equals(rootOrgId)) { + userManageForm.setCourseAdminCanAddNewUsers(orgOfCourseAdmin.getCourseAdminCanAddNewUsers()); + userManageForm.setCourseAdminCanBrowseAllUsers(orgOfCourseAdmin.getCourseAdminCanBrowseAllUsers()); + } else { + return forwardError(request, "error.authorisation"); + } + userManageForm.setCanResetOrgPassword(request.isUserInRole(Role.SYSADMIN)); + + userManageForm.setOrgId(orgId); + userManageForm.setOrgName(orgName); + List userManageBeans = service.getUserManageBeans(orgId); + Collections.sort(userManageBeans); + userManageForm.setUserManageBeans(userManageBeans); + request.setAttribute("UserManageForm", userManageForm); + + // heading + String[] args = { orgName }; + request.setAttribute("heading", messageService.getMessage("heading.manage.group.users", args)); + + // count roles in the org + HashMap roleCount = new HashMap<>(); + if (orgId.equals(rootOrgId)) { + roleCount.put(Role.SYSADMIN, Role.ROLE_SYSADMIN); + roleCount.put(Role.GROUP_ADMIN, Role.ROLE_GROUP_ADMIN); + } else { + roleCount.put(Role.LEARNER, Role.ROLE_LEARNER); + roleCount.put(Role.MONITOR, Role.ROLE_MONITOR); + roleCount.put(Role.AUTHOR, Role.ROLE_AUTHOR); + roleCount.put(Role.GROUP_MANAGER, Role.ROLE_GROUP_MANAGER); + roleCount.put(Role.GROUP_ADMIN, Role.ROLE_GROUP_ADMIN); + } + for (String role : roleCount.keySet()) { + Integer count = service.getCountRoleForOrg(orgId, roleCount.get(role), null); + request.setAttribute(role.replace(' ', '_'), count); + } + + // count users in the org + // TODO use hql that does a count instead of getting whole objects + Integer numUsers = Integer.valueOf(service.getUsersFromOrganisation(orgId).size()); + args[0] = numUsers.toString(); + request.setAttribute("numUsers", messageService.getMessage("label.users.in.group", args)); + + return "userlist"; + } + + @RequestMapping("/forwardError") + private String forwardError(HttpServletRequest request, String key) { + request.setAttribute("errorName", "UserManageAction"); + request.setAttribute("errorMessage", messageService.getMessage(key)); + return "error"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,104 @@ +/**************************************************************** + * 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.admin.web.controller; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.UserOrgForm; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author Jun-Dir Liew + * + */ + +/** + * + * + * + * + * + * + * + * + */ +@Controller +public class UserOrgController { + + private static final Logger log = Logger.getLogger(UserOrgController.class); + private static IUserManagementService service; + private static MessageService messageService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/userorg") + public String execute(@ModelAttribute UserOrgForm userOrgForm, HttpServletRequest request) throws Exception { + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + + //ActionMessages errors = new ActionMessages(); + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + log.debug("orgId: " + orgId); + // get org name + Organisation organisation = (Organisation) service.findById(Organisation.class, orgId); + + if ((orgId == null) || (orgId <= 0) || organisation == null) { + request.setAttribute("errorName", "UserOrgAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.org.invalid")); + return "error"; + } + + String orgName = organisation.getName(); + log.debug("orgName: " + orgName); + Organisation parentOrg = organisation.getParentOrganisation(); + if (parentOrg != null && !parentOrg.equals(service.getRootOrganisation())) { + request.setAttribute("pOrgId", parentOrg.getOrganisationId()); + request.setAttribute("pOrgName", parentOrg.getName()); + } + Integer orgType = organisation.getOrganisationType().getOrganisationTypeId(); + request.setAttribute("orgType", orgType); + + // create form object + userOrgForm.setOrgId(orgId); + userOrgForm.setOrgName(orgName); + + String[] args = { "0" }; + request.setAttribute("numExistUsers", messageService.getMessage("label.number.of.users", args)); + request.setAttribute("numPotentialUsers", messageService.getMessage("label.number.of.potential.users", args)); + + return "userorg"; + } +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,124 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.dto.UserBean; +import org.lamsfoundation.lams.admin.web.form.UserOrgRoleForm; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.UserOrganisation; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author jliew + * + * Called when a user has added users to an organisation. + * + */ + +/** + * + * + * + * + * + * + * + * + */ +@Controller +public class UserOrgRoleController { + + private static Logger log = Logger.getLogger(UserOrgRoleController.class); + private static IUserManagementService service; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/userorgrole") + public String execute(@ModelAttribute UserOrgRoleForm userOrgRoleForm, HttpServletRequest request) + throws Exception { + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + // make sure we don't have left overs from any previous attempt + userOrgRoleForm.setUserBeans(new ArrayList()); + + // set list of roles appropriate for the organisation type + List roles = (List) request.getAttribute("roles"); + request.setAttribute("numroles", roles.size()); + Collections.sort(roles); + request.setAttribute("roles", roles); + + Organisation organisation = (Organisation) service.findById(Organisation.class, + (Integer) request.getAttribute("orgId")); + userOrgRoleForm.setOrgId(organisation.getOrganisationId()); + + // display breadcrumb links + request.setAttribute("orgName", organisation.getName()); + Organisation parentOrg = organisation.getParentOrganisation(); + if (parentOrg != null && !parentOrg.equals(service.getRootOrganisation())) { + request.setAttribute("pOrgId", parentOrg.getOrganisationId()); + request.setAttribute("pOrgName", parentOrg.getName()); + } + request.setAttribute("orgType", organisation.getOrganisationType().getOrganisationTypeId()); + + // populate form with users + ArrayList userOrgs = (ArrayList) request.getAttribute("newUserOrganisations"); + for (int i = 0; i < userOrgs.size(); i++) { + UserBean userBean = new UserBean(); + User user = ((UserOrganisation) userOrgs.get(i)).getUser(); + BeanUtils.copyProperties(userBean, user); + // flag users that will be added to parent group if necessary + userBean.setMemberOfParent(true); + if (organisation.getOrganisationType().getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) { + if (service.getUserOrganisation(user.getUserId(), + organisation.getParentOrganisation().getOrganisationId()) == null) { + userBean.setMemberOfParent(false); + } + } + userOrgRoleForm.addUserBean(userBean); + log.debug("ready to assign role for user=" + userBean.getUserId()); + } + log.debug("ready to assign roles for " + userOrgRoleForm.getUserBeans().size() + " new users in organisation " + + organisation.getName()); + + return "userorgrole"; + } + +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgRoleSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,125 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.Arrays; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.dto.UserBean; +import org.lamsfoundation.lams.admin.web.form.UserOrgRoleForm; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +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; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author jliew + * + * Saves roles for users that were just added. + * Uses session scope because using request scope doesn't copy the form data + * into UserOrgRoleForm's userBeans ArrayList (the list becomes empty). + * + */ + +/** + * + * + * + * + * + * + * + * + * + */ +@Controller +public class UserOrgRoleSaveController { + + private static Logger log = Logger.getLogger(UserOrgRoleSaveController.class); + private static IUserManagementService service; + + @Autowired + private WebApplicationContext applicationContext; + + @Autowired + @Qualifier("adminMessageService") + private MessageService adminMessageService; + + @RequestMapping("/userorgrolesave") + public String execute(@ModelAttribute UserOrgRoleForm userOrgRoleForm, HttpServletRequest request) + throws Exception { + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + + ArrayList userBeans = userOrgRoleForm.getUserBeans(); + log.debug("userBeans is null? " + userBeans == null); + Integer orgId = userOrgRoleForm.getOrgId(); + log.debug("orgId: " + orgId); + + request.setAttribute("org", orgId); + request.getSession().removeAttribute("UserOrgRoleForm"); + + if (request.getAttribute("CANCEL") != null) { + return "forward:/usermanage.do"; + } + + // save UserOrganisation memberships, and the associated roles; + // for subgroups, if user is not a member of the parent group then add to that as well. + for (int i = 0; i < userBeans.size(); i++) { + UserBean bean = (UserBean) userBeans.get(i); + User user = (User) service.findById(User.class, bean.getUserId()); + log.debug("userId: " + bean.getUserId()); + String[] roleIds = bean.getRoleIds(); + if (roleIds.length == 0) { + // TODO forward to userorgrole.do, not userorg.do + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + errorMap.add("roles", adminMessageService.getMessage("error.roles.empty")); + request.setAttribute("errorMap", errorMap); + request.setAttribute("orgId", orgId); + return "forward:/userorg.do"; + } + service.setRolesForUserOrganisation(user, orgId, Arrays.asList(roleIds)); + // FMALIKOFF 5/7/7 Commented out the following code that set the roles in the course if the current org is a class, as the logic + // is done in service.setRolesForUserOrganisation() + //if (organisation.getOrganisationType().getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) { + // if (service.getUserOrganisation(bean.getUserId(), organisation.getParentOrganisation().getOrganisationId())==null) { + // service.setRolesForUserOrganisation(user, organisation.getParentOrganisation(), (List)Arrays.asList(roleIds)); + // } + //} + } + return "forward:/usermanage.do"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserOrgSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,147 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.UserOrgForm; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.UserOrganisation; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author Jun-Dir Liew + * + * Created at 17:22:21 on 20/06/2006 + */ + +/** + * + * + * + * + * + */ +@Controller +public class UserOrgSaveController { + + private static Logger log = Logger.getLogger(UserOrgSaveController.class); + private static IUserManagementService service; + private List rolelist; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/userorgsave") + public String execute(@ModelAttribute UserOrgForm userOrgForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + Integer orgId = userOrgForm.getOrgId(); + request.setAttribute("org", orgId); + + if (request.getAttribute("CANCEL") != null) { + return "forward:/usermanage.do"; + } + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + if (rolelist == null) { + rolelist = service.findAll(Role.class); + } + + Organisation organisation = (Organisation) service.findById(Organisation.class, orgId); + Set uos = organisation.getUserOrganisations(); + + String[] userIds = userOrgForm.getUserIds(); + List userIdList = Arrays.asList(userIds); + log.debug("new user membership of orgId=" + orgId + " will be: " + userIdList); + + // remove UserOrganisations that aren't in form data + Iterator iter = uos.iterator(); + while (iter.hasNext()) { + UserOrganisation uo = (UserOrganisation) iter.next(); + Integer userId = uo.getUser().getUserId(); + if (userIdList.indexOf(userId.toString()) < 0) { + User user = (User) service.findById(User.class, userId); + Set userUos = user.getUserOrganisations(); + userUos.remove(uo); + user.setUserOrganisations(userUos); + iter.remove(); + log.debug("removed userId=" + userId + " from orgId=" + orgId); + // remove from subgroups + service.deleteChildUserOrganisations(uo.getUser(), uo.getOrganisation()); + } + } + // add UserOrganisations that are in form data + List newUserOrganisations = new ArrayList(); + for (int i = 0; i < userIdList.size(); i++) { + Integer userId = new Integer(userIdList.get(i)); + Iterator iter2 = uos.iterator(); + Boolean alreadyInOrg = false; + while (iter2.hasNext()) { + UserOrganisation uo = (UserOrganisation) iter2.next(); + if (uo.getUser().getUserId().equals(userId)) { + alreadyInOrg = true; + break; + } + } + if (!alreadyInOrg) { + User user = (User) service.findById(User.class, userId); + UserOrganisation uo = new UserOrganisation(user, organisation); + newUserOrganisations.add(uo); + } + } + + organisation.setUserOrganisations(uos); + service.save(organisation); + + // if no new users, then finish; otherwise forward to where roles can be assigned for new users. + if (newUserOrganisations.isEmpty()) { + log.debug("no new users to add to orgId=" + orgId); + return "forward:/usermanage.do"; + } else { + request.setAttribute("roles", service.filterRoles(rolelist, request.isUserInRole(Role.SYSADMIN), + organisation.getOrganisationType())); + request.setAttribute("newUserOrganisations", newUserOrganisations); + request.setAttribute("orgId", orgId); + return "forward:/userorgrole.do"; + } + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,166 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.UserRolesForm; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.UserOrganisation; +import org.lamsfoundation.lams.usermanagement.UserOrganisationRole; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +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.validation.Errors; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author jliew + * + * + * + * + * + * + * + * + * + */ +@Controller +public class UserRolesController { + + private static Logger log = Logger.getLogger(UserRolesController.class); + private static IUserManagementService service; + private static MessageService messageService; + private static List rolelist; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/userroles") + public String execute(@ModelAttribute UserRolesForm userRolesForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + if (rolelist == null) { + rolelist = service.findAll(Role.class); + Collections.sort(rolelist); + } + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + Integer userId = WebUtil.readIntParam(request, "userId", true); + + // user and org ids passed as attributes by UserSaveAction + if (orgId == null) { + orgId = (Integer) request.getAttribute("orgId"); + } + if (orgId == null) { + errorMap.add("GLOBAL", messageService.getMessage("error.org.invalid")); + request.setAttribute("errorMap", errorMap); + return "userrole"; + } + if (userId == null || userId == 0) { + userId = (Integer) request.getAttribute("userId"); + } + if (userId == null) { + errorMap.add("GLOBAL", messageService.getMessage("error.userid.invalid")); + request.setAttribute("errorMap", errorMap); + return "userrole"; + } + log.debug("editing roles for userId: " + userId + " and orgId: " + orgId); + + // test requestor's permission + Organisation org = (Organisation) service.findById(Organisation.class, orgId); + User user = (User) service.findById(User.class, userId); + OrganisationType orgType = org.getOrganisationType(); + Integer orgIdOfCourse = (orgType.getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) + ? org.getParentOrganisation().getOrganisationId() + : orgId; + Boolean isSysadmin = request.isUserInRole(Role.SYSADMIN); + User requestor = service.getUserByLogin(request.getRemoteUser()); + Integer rootOrgId = service.getRootOrganisation().getOrganisationId(); + Boolean requestorHasRole = service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_MANAGER) + || (service.isUserInRole(requestor.getUserId(), orgIdOfCourse, Role.GROUP_ADMIN) + && !rootOrgId.equals(orgId)) + || (service.isUserGlobalGroupAdmin() && !rootOrgId.equals(orgId)); + + if (!(requestorHasRole || isSysadmin)) { + request.setAttribute("errorName", "UserRolesAction"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + + userRolesForm.setUserId(userId); + userRolesForm.setOrgId(org.getOrganisationId()); + // screen display vars + request.setAttribute("rolelist", service.filterRoles(rolelist, isSysadmin, orgType)); + request.setAttribute("login", user.getLogin()); + request.setAttribute("fullName", user.getFullName()); + request.setAttribute("orgName", org.getName()); + Organisation parentOrg = org.getParentOrganisation(); + if (parentOrg != null && !parentOrg.equals(service.getRootOrganisation())) { + request.setAttribute("pOrgId", parentOrg.getOrganisationId()); + request.setAttribute("parentName", parentOrg.getName()); + } + + String[] roles = null; + UserOrganisation uo = service.getUserOrganisation(userId, orgId); + if (uo != null) { + Iterator iter2 = uo.getUserOrganisationRoles().iterator(); + roles = new String[uo.getUserOrganisationRoles().size()]; + int i = 0; + while (iter2.hasNext()) { + UserOrganisationRole uor = (UserOrganisationRole) iter2.next(); + roles[i] = uor.getRole().getRoleId().toString(); + log.debug("got roleid: " + roles[i]); + i++; + } + } else { + Errors messages = null; + messages.reject("roles", messageService.getMessage("msg.add.to.org", org.getName())); + } + userRolesForm.setRoles(roles); + + return "userrole"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserRolesSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,113 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.UserRolesForm; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author jliew + * + * + * + * + * + * + * + * + * + * + */ +@Controller +public class UserRolesSaveController { + + private static Logger log = Logger.getLogger(UserRolesSaveController.class); + private static IUserManagementService service; + private static MessageService messageService; + private static List rolelist; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/userrolessave") + public String execute(@ModelAttribute UserRolesForm userRolesForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + if (rolelist == null) { + rolelist = service.findAll(Role.class); + Collections.sort(rolelist); + } + + Errors errors = null; + Integer orgId = userRolesForm.getOrgId(); + Integer userId = userRolesForm.getUserId(); + String[] roles = userRolesForm.getRoles(); + + request.setAttribute("org", orgId); + + if (request.getAttribute("CANCEL") != null) { + return "forward:/usermanage.do"; + } + + log.debug("userId: " + userId + ", orgId: " + orgId + " will have " + roles.length + " roles"); + Organisation org = (Organisation) service.findById(Organisation.class, orgId); + User user = (User) service.findById(User.class, userId); + + // user must have at least 1 role + if (roles.length < 1) { + errors.reject("roles", messageService.getMessage("error.roles.empty")); + request.setAttribute("rolelist", + service.filterRoles(rolelist, request.isUserInRole(Role.SYSADMIN), org.getOrganisationType())); + request.setAttribute("login", user.getLogin()); + request.setAttribute("fullName", user.getFullName()); + return "forward:/userroles.do"; + } + + service.setRolesForUserOrganisation(user, orgId, Arrays.asList(roles)); + + return "forward:/usermanage.do"; + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSaveAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSaveController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSaveController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSaveController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -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.admin.web.controller; + +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.beanutils.BeanUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.admin.web.form.UserForm; +import org.lamsfoundation.lams.security.ISecurityService; +import org.lamsfoundation.lams.themes.Theme; +import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; +import org.lamsfoundation.lams.usermanagement.SupportedLocale; +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.HashUtil; +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.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; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author Jun-Dir Liew + * + * Created at 12:35:38 on 14/06/2006 + */ + +/** + * + * + * + * + * + * + * + */ + +@Controller +@RequestMapping +public class UserSaveController { + + private static Logger log = Logger.getLogger(UserSaveController.class); + private static IUserManagementService service; + private static MessageService messageService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping(path = "/saveUserDetails", method = RequestMethod.POST) + public String saveUserDetails(@ModelAttribute UserForm userForm, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + UserSaveController.service = AdminServiceProxy.getService(applicationContext.getServletContext()); + // action input + Integer orgId = userForm.getOrgId(); + Integer userId = userForm.getUserId(); + ISecurityService securityService = AdminServiceProxy.getSecurityService(applicationContext.getServletContext()); + Integer loggeduserId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); + + // check if logged in User is Sysadmin + if (!securityService.isSysadmin(loggeduserId, "Edit User Details " + userId, true)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Only Sysadmin has edit permisions"); + return null; + } + UserDTO sysadmin = (UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER); + + UserSaveController.log.debug("orgId: " + orgId); + Boolean edit = false; + SupportedLocale locale = (SupportedLocale) UserSaveController.service.findById(SupportedLocale.class, + userForm.getLocaleId()); + AuthenticationMethod authenticationMethod = (AuthenticationMethod) UserSaveController.service + .findById(AuthenticationMethod.class, userForm.getAuthenticationMethodId()); + UserSaveController.log.debug("locale: " + locale); + UserSaveController.log.debug("authenticationMethod:" + authenticationMethod); + + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + + if (request.getAttribute("CANCEL") != null) { + if ((orgId == null) || (orgId == 0)) { + return "forward:/usersearch.do"; + } + request.setAttribute("org", orgId); + return "forward:/usermanage.do"; + } + + User user = null; + if (userId != 0) { + edit = true; + user = (User) UserSaveController.service.findById(User.class, userId); + } + + // login validation + String login = userForm.getLogin() == null ? null : userForm.getLogin().trim(); + if (StringUtils.isBlank(login)) { + errorMap.add("login", messageService.getMessage("error.login.required")); + } else if (!ValidationUtil.isUserNameValid(login)) { + errorMap.add("login", messageService.getMessage("error.username.invalid.characters")); + } else { + userForm.setLogin(login); + User existingUser = UserSaveController.service.getUserByLogin(login); + if (existingUser != null) { + if ((user != null) && StringUtils.equals(user.getLogin(), login)) { + // login exists - it's the user's current login + } else { + errorMap.add("login", messageService.getMessage("error.login.unique", + "(" + login + ", ID: " + existingUser.getUserId() + ")")); + } + } + } + + //first name validation + String firstName = (userForm.getFirstName() == null) ? null : 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 : 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 : 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()) { + if (edit) { // edit user + UserSaveController.log.debug("editing userId: " + userId); + // hash the new password if necessary, and audit the fact + userForm.setPassword(user.getPassword()); + BeanUtils.copyProperties(user, userForm); + user.setLocale(locale); + user.setAuthenticationMethod(authenticationMethod); + + Theme cssTheme = (Theme) UserSaveController.service.findById(Theme.class, userForm.getUserTheme()); + user.setTheme(cssTheme); + + UserSaveController.service.saveUser(user); + } else { // create user + + //password validation + String password2 = userForm.getPassword2(); + String password = (userForm.getPassword() == null) ? null : userForm.getPassword(); + if (StringUtils.isBlank(password)) { + errorMap.add("password", messageService.getMessage("error.password.required")); + } + if (!StringUtils.equals(password, (userForm.getPassword2()))) { + errorMap.add("password", messageService.getMessage("error.newpassword.mismatch")); + } + if (!ValidationUtil.isPasswordValueValid(password, password2)) { + errorMap.add("password", messageService.getMessage("error.newpassword.mismatch")); + } + + if (errorMap.isEmpty()) { + user = new User(); + String salt = HashUtil.salt(); + String passwordHash = HashUtil.sha256(userForm.getPassword(), salt); + BeanUtils.copyProperties(user, userForm); + user.setSalt(salt); + user.setPassword(passwordHash); + UserSaveController.log.debug("creating user... new login: " + user.getLogin()); + if (errorMap.isEmpty()) { + // TODO set theme according to user input + // instead of server default. + user.setTheme(UserSaveController.service.getDefaultTheme()); + user.setDisabledFlag(false); + user.setCreateDate(new Date()); + user.setAuthenticationMethod((AuthenticationMethod) UserSaveController.service + .findByProperty(AuthenticationMethod.class, "authenticationMethodName", "LAMS-Database") + .get(0)); + user.setUserId(null); + user.setLocale(locale); + + Theme theme = (Theme) UserSaveController.service.findById(Theme.class, userForm.getUserTheme()); + user.setTheme(theme); + + UserSaveController.service.saveUser(user); + + // make 'create user' audit log entry + UserSaveController.service.logUserCreated(user, sysadmin); + + UserSaveController.log.debug("user: " + user.toString()); + } + } + } + } + + if (errorMap.isEmpty()) { + if ((orgId == null) || (orgId == 0)) { + return "forward:/usersearch.do"; + } + if (edit) { + request.setAttribute("org", orgId); + return "forward:/usermanage.do"; + } else { + request.setAttribute("orgId", orgId); + request.setAttribute("userId", user.getUserId()); + return "forward:/userroles.do"; + } + } else { + request.setAttribute("errorMap", errorMap); + request.setAttribute("orgId", orgId); + return "/user/edit.do"; + } + } + + @RequestMapping(path = "/changePass", method = RequestMethod.POST) + public String changePass(HttpServletRequest request, HttpServletResponse response) throws Exception { + + UserSaveController.service = AdminServiceProxy.getService(applicationContext.getServletContext()); + MultiValueMap errorMap = new LinkedMultiValueMap<>(); + Integer userId = WebUtil.readIntParam(request, "userId", true); + ISecurityService securityService = AdminServiceProxy.getSecurityService(applicationContext.getServletContext()); + Integer loggeduserId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); + + // check if logged in User is Sysadmin + if (!securityService.isSysadmin(loggeduserId, "Change Password of User " + userId, true)) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "Only Sysadmin has edit permisions"); + return null; + } + + String password = WebUtil.readStrParam(request, "password"); + String password2 = WebUtil.readStrParam(request, "password2"); + + //password validation + if (StringUtils.isBlank(password)) { + errorMap.add("password", messageService.getMessage("error.password.required")); + } + + if (!StringUtils.equals(password, password2)) { + errorMap.add("password", messageService.getMessage("error.newpassword.mismatch")); + } + if (!ValidationUtil.isPasswordValueValid(password, password2)) { + errorMap.add("password", messageService.getMessage("label.password.restrictions")); + } + + if (errorMap.isEmpty()) { + User user = (User) UserSaveController.service.findById(User.class, userId); + String salt = HashUtil.salt(); + String passwordHash = HashUtil.sha256(password, salt); + user.setSalt(salt); + user.setPassword(passwordHash); + UserSaveController.service.saveUser(user); + return "forward:/user/edit.do"; + } + request.setAttribute("errorMap", errorMap); + return "userChangePass"; + + } + +} Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -0,0 +1,163 @@ +/**************************************************************** + * 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.admin.web.controller; + +import java.io.IOException; +import java.util.List; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.dto.UserDTO; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.MessageService; +import org.lamsfoundation.lams.util.WebUtil; +import org.springframework.beans.factory.annotation.Autowired; +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 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 jliew + * + * + * + * + */ +@Controller +@RequestMapping("/usersearch") +public class UserSearchController { + + private static Logger log = Logger.getLogger(UserSearchController.class); + private static IUserManagementService service; + private static MessageService messageService; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/start") + public String unspecified(HttpServletRequest request) throws Exception { + initServices(); + + if (!(request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin())) { + log.debug("user not sysadmin or global group admin"); + + request.setAttribute("errorName", "UserSearchAction authorisation"); + request.setAttribute("errorMessage", messageService.getMessage("error.authorisation")); + return "error"; + } + + return "usersearchlist"; + } + + /** + * Returns list of paged users. + */ + @RequestMapping("/getPagedUsers") + @ResponseBody + public String getPagedUsers(HttpServletRequest request, HttpServletResponse res) + throws IOException, ServletException { + initServices(); + + // the organisation type of the children + 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); + Integer isSort5 = WebUtil.readIntParam(request, "column[4]", true); + + String sortBy = "userId"; + String sortOrder = "DESC"; + if (isSort1 != null) { + sortBy = "userId"; + sortOrder = isSort1.equals(0) ? "ASC" : "DESC"; + + } else if (isSort2 != null) { + sortBy = "login"; + sortOrder = isSort2.equals(0) ? "ASC" : "DESC"; + + } else if (isSort3 != null) { + sortBy = "firstName"; + sortOrder = isSort3.equals(0) ? "ASC" : "DESC"; + + } else if (isSort4 != null) { + sortBy = "lastName"; + sortOrder = isSort4.equals(0) ? "ASC" : "DESC"; + + } else if (isSort5 != null) { + sortBy = "email"; + sortOrder = isSort5.equals(0) ? "ASC" : "DESC"; + } + + List userDtos = service.getAllUsers(page, size, sortBy, sortOrder, searchString); + + ObjectNode responcedata = JsonNodeFactory.instance.objectNode(); + responcedata.put("total_rows", service.getCountUsers(searchString)); + + ArrayNode rows = JsonNodeFactory.instance.arrayNode(); + for (UserDTO userDto : userDtos) { + ObjectNode responseRow = JsonNodeFactory.instance.objectNode(); + responseRow.put("userId", userDto.getUserID()); + responseRow.put("login", HtmlUtils.htmlEscape(userDto.getLogin())); + String firstName = userDto.getFirstName() == null ? "" : userDto.getFirstName(); + responseRow.put("firstName", HtmlUtils.htmlEscape(firstName)); + String lastName = userDto.getLastName() == null ? "" : userDto.getLastName(); + responseRow.put("lastName", HtmlUtils.htmlEscape(lastName)); + String email = userDto.getEmail() == null ? "" : userDto.getEmail(); + responseRow.put("email", HtmlUtils.htmlEscape(email)); + if (userDto.getPortraitUuid() != null) { + responseRow.put("portraitId", userDto.getPortraitUuid()); + } + rows.add(responseRow); + } + responcedata.set("rows", rows); + res.setContentType("application/json;charset=utf-8"); + return responcedata.toString(); + } + + private void initServices() { + if (service == null) { + service = AdminServiceProxy.getService(applicationContext.getServletContext()); + } + if (messageService == null) { + messageService = AdminServiceProxy.getMessageService(applicationContext.getServletContext()); + } + } + +} \ No newline at end of file Fisheye: Tag e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7 refers to a dead (removed) revision in file `lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchSingleTermAction.java'. Fisheye: No comparison available. Pass `N' to diff? Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchSingleTermController.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchSingleTermController.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/controller/UserSearchSingleTermController.java (revision e2c0c928c2cf3c0527ec942ad9af0ec67a3aa8d7) @@ -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.admin.web.controller; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpSession; + +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.admin.service.AdminServiceProxy; +import org.lamsfoundation.lams.usermanagement.Organisation; +import org.lamsfoundation.lams.usermanagement.OrganisationType; +import org.lamsfoundation.lams.usermanagement.Role; +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.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.context.WebApplicationContext; + +/** + * @author jliew + * + * + * + * + */ +@Controller +public class UserSearchSingleTermController { + + private static IUserManagementService service; + + @Autowired + private WebApplicationContext applicationContext; + + @RequestMapping("/user/searchsingle") + public String execute(HttpServletRequest request) throws Exception { + + UserSearchSingleTermController.service = AdminServiceProxy.getService(applicationContext.getServletContext()); + String term = WebUtil.readStrParam(request, "term", true); + Integer orgId = WebUtil.readIntParam(request, "orgId", true); + + if (StringUtils.isNotBlank(term)) { + List users = new ArrayList(); + if (orgId != null) { + // filter results according to user's roles + Organisation org = (Organisation) UserSearchSingleTermController.service.findById(Organisation.class, + orgId); + Organisation group; + if (org != null) { + HttpSession session = SessionManager.getSession(); + if (session != null) { + UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER); + if (userDto != null) { + Integer userId = userDto.getUserID(); + if (org.getOrganisationType().getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) { + group = org.getParentOrganisation(); + } else { + group = org; + } + // get search results, filtered according to orgId + if (request.isUserInRole(Role.SYSADMIN) + || UserSearchSingleTermController.service.isUserGlobalGroupAdmin()) { + users = UserSearchSingleTermController.service.findUsers(term, orgId); + } else if (UserSearchSingleTermController.service.isUserInRole(userId, + group.getOrganisationId(), Role.GROUP_ADMIN) + || UserSearchSingleTermController.service.isUserInRole(userId, + group.getOrganisationId(), Role.GROUP_MANAGER)) { + if (group.getCourseAdminCanBrowseAllUsers()) { + users = UserSearchSingleTermController.service.findUsers(term, orgId); + } else if (org.getOrganisationType().getOrganisationTypeId() + .equals(OrganisationType.CLASS_TYPE)) { + users = UserSearchSingleTermController.service.findUsers(term, + group.getOrganisationId(), orgId); + } + } + } + } + } + } else { + // if there's no orgId param, search all users + users = UserSearchSingleTermController.service.findUsers(term); + } + request.setAttribute("users", users); + } + + return "user/basiclist"; + } +}