Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java,v diff -u -r1.23 -r1.24 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java 9 Aug 2006 07:06:16 -0000 1.23 +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserAction.java 10 Aug 2006 00:50:16 -0000 1.24 @@ -73,7 +73,7 @@ private static Logger log = Logger.getLogger(UserAction.class); private static IUserManagementService service; - private List rolelist; + private static List rolelist; private static List locales; public ActionForward edit(ActionMapping mapping, @@ -86,43 +86,32 @@ OrganisationType orgType = org.getOrganisationType(); Boolean isSysadmin = request.isUserInRole(Role.SYSADMIN); - request.getSession().setAttribute("rolelist",filterRoles(rolelist,isSysadmin, orgType)); + request.setAttribute("rolelist",filterRoles(rolelist,isSysadmin, orgType)); // set canEdit for whether user should be able to edit anything other than roles request.setAttribute("canEdit",isSysadmin); - request.getSession().setAttribute("locales",locales); - + request.setAttribute("locales",locales); + // editing a user Integer userId = WebUtil.readIntParam(request,"userId",true); DynaActionForm userForm = (DynaActionForm)form; if(userId != null) { log.debug("got userid to edit: "+userId); User user = (User)getService().findById(User.class,userId); - request.getSession().setAttribute("user", user); BeanUtils.copyProperties(userForm, user); userForm.set("password",null); - // get user's roles - Iterator iter = user.getUserOrganisations().iterator(); - while(iter.hasNext()){ - UserOrganisation uo = (UserOrganisation)iter.next(); - if(uo.getOrganisation().getOrganisationId().equals(orgId)){ - request.getSession().setAttribute("uo", uo); - request.getSession().setAttribute("uors", uo.getUserOrganisationRoles()); - Iterator iter2 = uo.getUserOrganisationRoles().iterator(); - String[] 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++; - } - userForm.set("roles",roles); - break; - } - } - SupportedLocale locale = getService().getSupportedLocale(user.getLocaleLanguage(),user.getLocaleCountry()); - request.getSession().setAttribute("locale", locale); + UserOrganisation uo = getService().getUserOrganisation(userId, orgId); + Iterator iter2 = uo.getUserOrganisationRoles().iterator(); + String[] 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++; + } + userForm.set("roles",roles); + SupportedLocale locale = getService().getSupportedLocale(user.getLocaleLanguage(),user.getLocaleCountry()); userForm.set("localeId",locale.getLocaleId()); }else{ @@ -132,7 +121,6 @@ String defaultLocale = Configuration.get(ConfigurationKeys.SERVER_LANGUAGE); log.debug("defaultLocale: "+defaultLocale); SupportedLocale locale = getService().getSupportedLocale(defaultLocale.substring(0,2),defaultLocale.substring(3)); - request.getSession().setAttribute("locale", locale); userForm.set("localeId",locale.getLocaleId()); }catch(Exception e){ log.debug(e); @@ -142,10 +130,11 @@ Organisation parentOrg = org.getParentOrganisation(); if(parentOrg!=null){ - request.getSession().setAttribute("parentOrg",parentOrg); + request.setAttribute("pOrgId",parentOrg.getOrganisationId()); + request.setAttribute("pOrgName", parentOrg.getName()); } - request.getSession().setAttribute("org",org); - request.getSession().setAttribute("orgType",orgType); + request.setAttribute("orgName",org.getName()); + request.setAttribute("orgType",orgType.getOrganisationTypeId()); return mapping.findForward("user"); } @@ -184,9 +173,9 @@ if(service==null){ WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); service = (IUserManagementService) ctx.getBean("userManagementServiceTarget"); - locales = getService().findAll(SupportedLocale.class); + locales = service.findAll(SupportedLocale.class); Collections.sort(locales); - rolelist = getService().findAll(Role.class); + rolelist = service.findAll(Role.class); Collections.sort(rolelist); } return service; Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java,v diff -u -r1.17 -r1.18 --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java 9 Aug 2006 07:06:16 -0000 1.17 +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/UserSaveAction.java 10 Aug 2006 00:50:16 -0000 1.18 @@ -33,7 +33,6 @@ 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; @@ -77,6 +76,7 @@ private static Logger log = Logger.getLogger(UserSaveAction.class); private static IUserManagementService service; + private static List rolelist; @SuppressWarnings("unchecked") public ActionForward execute(ActionMapping mapping, ActionForm form, @@ -110,24 +110,21 @@ "error.newpassword.mismatch")); } if ((userForm.get("password") == null) - || (((String) userForm.getString("password").trim()).length() == 0)) { + || (userForm.getString("password").trim().length() == 0)) { passwordChanged = false; if (!edit) errors.add("password", new ActionMessage( "error.password.required")); } - SupportedLocale locale = (SupportedLocale) request.getSession() - .getAttribute("locale"); + SupportedLocale locale = (SupportedLocale) getService().findById(SupportedLocale.class, (Byte)userForm.get("localeId")); log.debug("locale: " + locale); if (errors.isEmpty()) { - List allRoles = (List)request.getSession().getAttribute("rolelist"); - User user; String[] roles = (String[]) userForm.get("roles"); if (edit) { // edit user log.debug("editing userId: " + userId); - user = (User) request.getSession().getAttribute("user"); + User user = (User)getService().findById(User.class, userId); if (passwordChanged) { userForm.set("password", HashUtil.sha1((String) userForm.get("password"))); } else { @@ -142,8 +139,8 @@ List rolesCopy = new ArrayList(); rolesCopy.addAll(rolesList); log.debug("rolesList.size: " + rolesList.size()); - UserOrganisation uo = (UserOrganisation) request.getSession().getAttribute("uo"); - Set uors = (Set) request.getSession().getAttribute("uors"); + UserOrganisation uo = getService().getUserOrganisation(userId, orgId); + Set uors = uo.getUserOrganisationRoles(); Set uorsCopy = new HashSet(); uorsCopy.addAll(uors); //remove the common part from the rolesList and uors @@ -158,17 +155,16 @@ } uors.removeAll(uorsCopy); for(String roleId : rolesCopy){ - UserOrganisationRole uor = new UserOrganisationRole(uo, findRole(allRoles, roleId)); + UserOrganisationRole uor = new UserOrganisationRole(uo, findRole(rolelist, roleId)); getService().save(uor); uors.add(uor); } uo.setUserOrganisationRoles(uors); getService().save(user); } else { // create user log.debug("creating user..."); - user = new User(); - userForm.set("password", HashUtil.sha1((String) userForm - .get("password"))); + User user = new User(); + userForm.set("password", HashUtil.sha1((String) userForm.get("password"))); BeanUtils.copyProperties(user, userForm); log.debug("new login: " + user.getLogin()); if (getService().getUserByLogin(user.getLogin()) != null) { @@ -187,19 +183,18 @@ List orgs = new ArrayList(); // if user is to be added to a class, make user a member of // parent course also - Organisation org = (Organisation)request.getSession().getAttribute("org"); + Organisation org = (Organisation)getService().findById(Organisation.class, orgId); orgs.add(org); - OrganisationType orgType = (OrganisationType)request.getSession().getAttribute("orgType"); + OrganisationType orgType = org.getOrganisationType(); if (orgType.getOrganisationTypeId().equals(OrganisationType.CLASS_TYPE)) { - Organisation parentOrg = (Organisation)request.getSession().getAttribute("parentOrg"); + Organisation parentOrg = org.getParentOrganisation(); orgs.add(parentOrg); } for (Organisation o : orgs) { UserOrganisation uo = new UserOrganisation(user,o); getService().save(uo); - log.debug("created UserOrganisation: " + uo.getUserOrganisationId()); for (String roleId : roles) { - UserOrganisationRole uor = new UserOrganisationRole(uo, findRole(allRoles,roleId)); + UserOrganisationRole uor = new UserOrganisationRole(uo, findRole(rolelist,roleId)); getService().save(uor); uo.addUserOrganisationRole(uor); } @@ -212,7 +207,6 @@ if (errors.isEmpty()) { request.setAttribute("org", orgId); log.debug("orgId: " + orgId); - clearSessionAttributes(request.getSession()); return mapping.findForward("userlist"); } else { if (!edit) { // error screen on create user shouldn't show empty roles @@ -224,14 +218,6 @@ } - private void clearSessionAttributes(HttpSession session) { - String[] attributes = {"locales","org","parentOrg","user","orgType","rolelist","uo","uors"}; - for(String attr : attributes){ - session.removeAttribute(attr); - } - } - - private Role findRole(List allRoles, String roleId){ for(Role role: allRoles){ if(role.getRoleId().toString().equals(roleId)) @@ -240,13 +226,12 @@ return null; } + @SuppressWarnings("unchecked") private IUserManagementService getService() { if (service == null) { - WebApplicationContext ctx = WebApplicationContextUtils - .getRequiredWebApplicationContext(getServlet() - .getServletContext()); - service = (IUserManagementService) ctx - .getBean("userManagementServiceTarget"); + WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(getServlet().getServletContext()); + service = (IUserManagementService) ctx.getBean("userManagementServiceTarget"); + rolelist = service.findAll(Role.class); } return service; } Index: lams_admin/web/user.jsp =================================================================== RCS file: /usr/local/cvsroot/lams_admin/web/user.jsp,v diff -u -r1.10 -r1.11 --- lams_admin/web/user.jsp 9 Aug 2006 07:09:46 -0000 1.10 +++ lams_admin/web/user.jsp 10 Aug 2006 00:50:15 -0000 1.11 @@ -10,11 +10,11 @@

- - "> :: + + "> :: - userorgmanage.do?org="> - :: + userorgmanage.do?org="> + :: User