Index: lams_admin/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r9ecda292b1506ae3b558454f565c15717d8eb5e8 -r52ed825cf80fc4c9f1b9e114c80b09913e86002e --- lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 9ecda292b1506ae3b558454f565c15717d8eb5e8) +++ lams_admin/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -589,5 +589,36 @@ config.kumalive.enable =Enable Kumalive audit.remarks =Remarks +admin.policies.title =Policies and consents +admin.add.edit.policy =Add/edit new policy +label.name =Name +label.policy.type =Policy type +label.policy.status =Policy status +label.version =Version +label.last.modified =Last modified +label.agreements =Agreements +label.add.new.policy =Add a new policy +label.policy.status.hint =An active policy will require consent from new users. Existing users will need to consent to this policy on their next log in. +label.policy.status.active =Active +label.policy.status.inactive =Inactive +label.policy.status.draft =Draft +label.policy.type.site =Site policy +label.policy.type.privacy =Privacy policy +label.policy.type.third.party =Third party policy +label.policy.type.other =Other policy +label.summary =Summary +label.full.policy =Full policy +label.view.previous.versions =View previous versions +label.set.status.to =Set status to "{0}" +label.minor.change =Minor change +label. = +label. = +label. = +label. = +label. = +label. = +label. = +label. = +label. = #======= End labels: Exported 582 labels for en AU ===== Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/PolicyManagementAction.java =================================================================== diff -u --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/PolicyManagementAction.java (revision 0) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/PolicyManagementAction.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,265 @@ +package org.lamsfoundation.lams.admin.web.action; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.DynaActionForm; +import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.service.IPolicyService; +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.FileUtil; +import org.lamsfoundation.lams.util.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +/** + * Handles Policy management requests. + * + *@author Andrey Balan + */ +public class PolicyManagementAction extends Action { + + private static Logger log = Logger.getLogger(PolicyManagementAction.class); + private static IPolicyService policyService = null; + private static IUserManagementService userManagementService = null; + + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + if (policyService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + policyService = (IPolicyService) wac.getBean("policyService"); + } + if (userManagementService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + userManagementService = (IUserManagementService) wac.getBean("userManagementService"); + } + + String method = WebUtil.readStrParam(request, "method", true); + if (StringUtils.equals(method, "list") || isCancelled(request)) { + return list(mapping, form, request, response); + } else if (StringUtils.equals(method, "edit")) { + return edit(mapping, form, request, response); + } else if (StringUtils.equals(method, "save")) { + return save(mapping, form, request, response); + } else if (StringUtils.equals(method, "delete")) { + return delete(mapping, form, request, response); + } else if (StringUtils.equals(method, "viewPreviousVersions")) { + return viewPreviousVersions(mapping, form, request, response); + } else if (StringUtils.equals(method, "changeStatus")) { + return changeStatus(mapping, form, request, response); + } + + return mapping.findForward("error"); + } + + private ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + List policies = policyService.getPolicies(); + + //calculate which policies have previous version instanses + HashMap policyCount = new HashMap(); + for (Policy policy : policies) { + Long policyId = policy.getPolicyId(); + int previousVersionsCount = policyCount.get(policyId) == null ? 0 : policyCount.get(policyId); + policyCount.put(policy.getPolicyId(), previousVersionsCount + 1); + } + + //filter out older versioned policies + HashMap filteredPolicies = new HashMap(); + for (Policy policy : policies) { + Long policyId = policy.getPolicyId(); + boolean hasPreviousVersions = policyCount.get(policyId) != null && policyCount.get(policyId) > 1; + policy.setPreviousVersions(hasPreviousVersions); + + if (filteredPolicies.containsKey(policyId)) { + Policy alreadyAddedPolicy = filteredPolicies.get(policyId); + Integer policyStateId = policy.getPolicyStateId(); + + //active policy has priority + if (Policy.STATUS_ACTIVE.equals(policyStateId)) { + filteredPolicies.put(policyId, policy); + + //if both are inactive - newer has priority + } else if (Policy.STATUS_INACTIVE.equals(policyStateId) + && Policy.STATUS_INACTIVE.equals(alreadyAddedPolicy.getPolicyStateId()) + && policy.getLastModified().after(alreadyAddedPolicy.getLastModified())) { + filteredPolicies.put(policyId, policy); + } + + } else { + filteredPolicies.put(policyId, policy); + } + + } + request.setAttribute("policies", filteredPolicies.values()); + + int userCount = userManagementService.getCountUsers(); + request.setAttribute("userCount", userCount); + return mapping.findForward("policyList"); + } + + private ActionForward edit(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + Long policyUid = WebUtil.readLongParam(request, "policyUid", true); + if (policyUid != null && policyUid > 0) { + Policy policy = policyService.getPolicyByUid(policyUid); + if (policy != null) { + DynaActionForm policyForm = (DynaActionForm) form; + policyForm.set("policyUid", policy.getUid()); + policyForm.set("policyId", policy.getPolicyId()); + policyForm.set("policyName", policy.getPolicyName()); + policyForm.set("summary", policy.getSummary()); + policyForm.set("fullPolicy", policy.getFullPolicy()); + policyForm.set("policyTypeId", policy.getPolicyTypeId()); + policyForm.set("version", policy.getVersion()); + policyForm.set("policyStateId", policy.getPolicyStateId()); + request.setAttribute("policyForm", policyForm); + } + } + return mapping.findForward("editPolicy"); + } + + private ActionForward save(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + DynaActionForm policyForm = (DynaActionForm) form; + String currentDate = ZonedDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE); + +// ActionMessages errors = new ActionMessages(); +// +// // validate +// if (!StringUtils.equals(policyForm.getString("courseKey"), policyForm.getString("confirmCourseKey"))) { +// errors.add("courseKey", new ActionMessage("error.course.keys.unequal")); +// } +// if (policyService.contextExists((Integer) policyForm.get("signupOrganisationId"), +// policyForm.getString("context"))) { +// errors.add("context", new ActionMessage("error.context.exists")); +// } +// +// if (!errors.isEmpty()) { +// saveErrors(request, errors); +// } else { + Object policyUid = policyForm.get("policyUid"); + String version = policyForm.getString("version"); + Integer policyStateId = (Integer) policyForm.get("policyStateId"); + Boolean isMinorChange = (Boolean) policyForm.get("minorChange"); + + + + Policy policy; + // edit existing policy + if (policyUid != null && (Long) policyUid > 0) { + policy = policyService.getPolicyByUid((Long) policyUid); + + //if it's not a minor change - then instantiate a new child policy + if (!isMinorChange) { + Policy oldPolicy = policy; + + //if the new policy has Active status then set the old one to Inactive + if (policyStateId.equals(Policy.STATUS_ACTIVE)) { + oldPolicy.setPolicyStateId(Policy.STATUS_INACTIVE); + oldPolicy.setLastModified(new Date()); + userManagementService.save(oldPolicy); + } + + //if version was not changed by the user - append current date + if (oldPolicy.getVersion().equals(version)) { + version += " " + currentDate; + } + + policy = new Policy(); + policy.setPolicyId(oldPolicy.getPolicyId()); + } + + //create a new policy + } else { + policy = new Policy(); + // generate Unique long ID + Long policyId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; + policy.setPolicyId(policyId); + } + + //set default version if it's empty + if (StringUtils.isEmpty(version)) { + version = currentDate; + } + policy.setVersion(version); + policy.setSummary(policyForm.getString("summary")); + policy.setFullPolicy(policyForm.getString("fullPolicy")); + policy.setPolicyTypeId((Integer) policyForm.get("policyTypeId")); + policy.setPolicyStateId(policyStateId); + policy.setPolicyName(policyForm.getString("policyName")); + //set created user + Integer loggeduserId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); + User createdBy = (User) userManagementService.findById(User.class, loggeduserId); + policy.setCreatedBy(createdBy); + policy.setLastModified(new Date()); + userManagementService.save(policy); + + return mapping.findForward("policyListMethod"); +// } + +// return mapping.findForward("editPolicy"); + } + + private ActionForward delete(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + Long policyUid = WebUtil.readLongParam(request, "policyUid"); + if (policyUid != null && policyUid > 0) { + userManagementService.deleteById(Policy.class, policyUid); + } + + return mapping.findForward("policyListMethod"); + } + + private ActionForward viewPreviousVersions(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + long policyId = WebUtil.readLongParam(request, "policyId"); + List policies = policyService.getPreviousVersionsPolicies(policyId); + request.setAttribute("policies", policies); + + int userCount = userManagementService.getCountUsers(); + request.setAttribute("userCount", userCount); + request.setAttribute("viewPreviousVersions", "true"); + return mapping.findForward("policyList"); + } + + private ActionForward changeStatus(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + long policyUid = WebUtil.readLongParam(request, "policyUid"); + int newStatus = WebUtil.readIntParam(request, "newStatus"); + policyService.changePolicyStatus(policyUid, newStatus); + + return list(mapping, form, request, response); + } +} Index: lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java =================================================================== diff -u -r5f82321c5864250c612773630ff209a45e71a3f1 -r52ed825cf80fc4c9f1b9e114c80b09913e86002e --- lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision 5f82321c5864250c612773630ff209a45e71a3f1) +++ lams_admin/src/java/org/lamsfoundation/lams/admin/web/action/SysAdminStartAction.java (.../SysAdminStartAction.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -62,6 +62,7 @@ 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("policyManagement.do", "admin.policies.title")); 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")); Index: lams_admin/web/WEB-INF/struts-config.xml =================================================================== diff -u -r9d983eac609d45a939706e34834cfed8c7249810 -r52ed825cf80fc4c9f1b9e114c80b09913e86002e --- lams_admin/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 9d983eac609d45a939706e34834cfed8c7249810) +++ lams_admin/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -160,6 +160,18 @@ + + + + + + + + + + + + @@ -863,6 +875,31 @@ redirect="false" /> + + + + + + + + + + + + + + + + + Index: lams_admin/web/policies/edit.jsp =================================================================== diff -u --- lams_admin/web/policies/edit.jsp (revision 0) +++ lams_admin/web/policies/edit.jsp (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,138 @@ +<%@ include file="/taglibs.jsp"%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  *
: + + + + + + +
  * + + + +
  * + + + +
+   +
+   +
+ +
+
+ +
+ + + + + + +
+ +
\ No newline at end of file Index: lams_admin/web/policies/list.jsp =================================================================== diff -u --- lams_admin/web/policies/list.jsp (revision 0) +++ lams_admin/web/policies/list.jsp (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,115 @@ +<%@ include file="/taglibs.jsp"%> + +

+ + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${fn:length(policy.consents)}/${userCount} + + + + +    + + + + + + + + + 3 + + + + + + + 1 + + + +    + + + + + + + + +    + + + + +
+ + + + + + Index: lams_admin/web/policies/previousVersionsList.jsp =================================================================== diff -u --- lams_admin/web/policies/previousVersionsList.jsp (revision 0) +++ lams_admin/web/policies/previousVersionsList.jsp (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,81 @@ +<%@ include file="/taglibs.jsp"%> + +

+ + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Consents + + + + +    + + + + +
+ Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java =================================================================== diff -u -r3617b812ba50ea59fd9991680ee73e5ee41357cf -r52ed825cf80fc4c9f1b9e114c80b09913e86002e --- lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java (.../IndexAction.java) (revision 3617b812ba50ea59fd9991680ee73e5ee41357cf) +++ lams_central/src/java/org/lamsfoundation/lams/web/IndexAction.java (.../IndexAction.java) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -103,6 +103,11 @@ && loggedInUser.getTwoFactorAuthenticationSecret() == null) { return mapping.findForward("twoFactorAuthentication"); } + + // check if user needs to get his shared two-factor authorization secret + if (false) { + return mapping.findForward("policyConsents"); + } User user = getUserManagementService().getUserByLogin(userDTO.getLogin()); request.setAttribute("portraitUuid", user.getPortraitUuid()); Index: lams_central/src/java/org/lamsfoundation/lams/web/action/PolicyConsentsAction.java =================================================================== diff -u --- lams_central/src/java/org/lamsfoundation/lams/web/action/PolicyConsentsAction.java (revision 0) +++ lams_central/src/java/org/lamsfoundation/lams/web/action/PolicyConsentsAction.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,153 @@ +package org.lamsfoundation.lams.web.action; + +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang.StringUtils; +import org.apache.struts.action.Action; +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.DynaActionForm; +import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.service.IPolicyService; +import org.lamsfoundation.lams.usermanagement.User; +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.WebUtil; +import org.lamsfoundation.lams.web.session.SessionManager; +import org.lamsfoundation.lams.web.util.AttributeNames; +import org.springframework.web.context.WebApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +import com.warrenstrange.googleauth.GoogleAuthenticator; +import com.warrenstrange.googleauth.GoogleAuthenticatorKey; +import com.warrenstrange.googleauth.GoogleAuthenticatorQRGenerator; + +/** + * Shows policies user has to consent to. Also stores them once user agrees. + * + * @author Andrey Balan + */ +public class PolicyConsentsAction extends Action { + private static IPolicyService policyService = null; + private static IUserManagementService userManagementService = null; + + @Override + public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) throws Exception { + + if (policyService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + policyService = (IPolicyService) wac.getBean("policyService"); + } + if (userManagementService == null) { + WebApplicationContext wac = WebApplicationContextUtils + .getRequiredWebApplicationContext(getServlet().getServletContext()); + userManagementService = (IUserManagementService) wac.getBean("userManagementService"); + } + + String method = WebUtil.readStrParam(request, "method", true); + if (StringUtils.equals(method, "list") || isCancelled(request)) { + return consent(mapping, form, request, response); + } + + List policies = policyService.getActivePolicies(); + request.setAttribute("policies", policies); + +// User loggedInUser = userManagementService.getUserByLogin(request.getRemoteUser()); + + return mapping.findForward("policyConsents"); + } + + private ActionForward consent(ActionMapping mapping, ActionForm form, HttpServletRequest request, + HttpServletResponse response) { + + DynaActionForm policyForm = (DynaActionForm) form; + +// ActionMessages errors = new ActionMessages(); +// +// // validate +// if (!StringUtils.equals(policyForm.getString("courseKey"), policyForm.getString("confirmCourseKey"))) { +// errors.add("courseKey", new ActionMessage("error.course.keys.unequal")); +// } +// if (policyService.contextExists((Integer) policyForm.get("signupOrganisationId"), +// policyForm.getString("context"))) { +// errors.add("context", new ActionMessage("error.context.exists")); +// } +// +// if (!errors.isEmpty()) { +// saveErrors(request, errors); +// } else { + Object policyUid = policyForm.get("policyUid"); + String version = policyForm.getString("version"); + Integer policyStateId = (Integer) policyForm.get("policyStateId"); + Boolean isMinorChange = (Boolean) policyForm.get("minorChange"); + + + + Policy policy; + // edit existing policy +// if (policyUid != null && (Long) policyUid > 0) { +// policy = policyService.getPolicyByUid((Long) policyUid); +// +// //if it's not a minor change - then instantiate a new child policy +// if (!isMinorChange) { +// Policy oldPolicy = policy; +// +// //if the new policy has Active status then set the old one to Inactive +// if (policyStateId.equals(Policy.STATUS_ACTIVE)) { +// oldPolicy.setPolicyStateId(Policy.STATUS_INACTIVE); +// oldPolicy.setLastModified(new Date()); +// userManagementService.save(oldPolicy); +// } +// +// //if version was not changed by the user - append current date +// if (oldPolicy.getVersion().equals(version)) { +// version += " " + currentDate; +// } +// +// policy = new Policy(); +// policy.setPolicyId(oldPolicy.getPolicyId()); +// } +// +// //create a new policy +// } else { +// policy = new Policy(); +// // generate Unique long ID +// Long policyId = UUID.randomUUID().getMostSignificantBits() & Long.MAX_VALUE; +// policy.setPolicyId(policyId); +// } +// +// //set default version if it's empty +// if (StringUtils.isEmpty(version)) { +// version = currentDate; +// } +// policy.setVersion(version); +// policy.setSummary(policyForm.getString("summary")); +// policy.setFullPolicy(policyForm.getString("fullPolicy")); +// policy.setPolicyTypeId((Integer) policyForm.get("policyTypeId")); +// policy.setPolicyStateId(policyStateId); +// policy.setPolicyName(policyForm.getString("policyName")); +// //set created user +// Integer loggeduserId = ((UserDTO) SessionManager.getSession().getAttribute(AttributeNames.USER)).getUserID(); +// User createdBy = (User) userManagementService.findById(User.class, loggeduserId); +// policy.setCreatedBy(createdBy); +// policy.setLastModified(new Date()); +// userManagementService.save(policy); + + return mapping.findForward("policyListMethod"); +// } + +// return mapping.findForward("editPolicy"); + } +} Index: lams_central/web/WEB-INF/struts-config.xml =================================================================== diff -u -rba6d2394558dc6e82f56561d0913c9e75d000e89 -r52ed825cf80fc4c9f1b9e114c80b09913e86002e --- lams_central/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision ba6d2394558dc6e82f56561d0913c9e75d000e89) +++ lams_central/web/WEB-INF/struts-config.xml (.../struts-config.xml) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -141,6 +141,11 @@ redirect="false" /> + -
+ + + + + + + + + + + + + + + + + + + +
+ + + +
+ + : + + + + + + + + + + + + + + +
+ + : +
+ + : +
+ + : + +
+ + + + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/Policy.hbm.xml =================================================================== diff -u --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/Policy.hbm.xml (revision 0) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/Policy.hbm.xml (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/PolicyConsent.hbm.xml =================================================================== diff -u --- lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/PolicyConsent.hbm.xml (revision 0) +++ lams_common/conf/hibernate/mappings/org/lamsfoundation/lams/policies/PolicyConsent.hbm.xml (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/commonContext.xml =================================================================== diff -u -r045ebfd1d11d9ed0a1f81a00abb1a2ea373e8d93 -r52ed825cf80fc4c9f1b9e114c80b09913e86002e --- lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 045ebfd1d11d9ed0a1f81a00abb1a2ea373e8d93) +++ lams_common/src/java/org/lamsfoundation/lams/commonContext.xml (.../commonContext.xml) (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -213,6 +213,29 @@ + + + + + + + + + + true + + + + + + + + PROPAGATION_REQUIRED + PROPAGATION_REQUIRED + + + + @@ -554,6 +577,11 @@ + + + + + Index: lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20180528.sql =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20180528.sql (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/dbupdates/patch20180528.sql (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,70 @@ +-- Turn off autocommit, so nothing is committed if there is an error +SET AUTOCOMMIT = 0; +SET FOREIGN_KEY_CHECKS=0; +----------------------Put all sql statements below here------------------------- + +-- LDEV- +CREATE TABLE lams_policy_state ( + policy_state_id INT(3) NOT NULL + , description VARCHAR(255) NOT NULL + , PRIMARY KEY (policy_state_id) +); + +CREATE TABLE lams_policy_type ( + policy_type_id INT(3) NOT NULL + , description VARCHAR(255) NOT NULL + , PRIMARY KEY (policy_type_id) +); + +CREATE TABLE lams_policy ( + uid BIGINT(20) NOT NULL AUTO_INCREMENT + , policy_id BIGINT(20) + , created_by BIGINT(20) NOT NULL + , policy_name VARCHAR(255) NOT NULL + , version LONG + , summary TEXT + , full_policy TEXT + , last_modified DATETIME NOT NULL + , policy_state_id INT(3) NOT NULL + , policy_type_id INT(3) NOT NULL + , PRIMARY KEY (uid) + , KEY (created_by) + , CONSTRAINT FK_lams_lesson_1 FOREIGN KEY (created_by) + REFERENCES lams_user (user_id) + , KEY (policy_state_id) + , CONSTRAINT FK_lams_policy_2 FOREIGN KEY (policy_state_id) + REFERENCES lams_policy_state (policy_state_id) + , KEY (policy_type_id) + , CONSTRAINT FK_lams_policy_3 FOREIGN KEY (policy_type_id) + REFERENCES lams_policy_type (policy_type_id) +); + +CREATE TABLE lams_policy_consent ( + uid BIGINT(20) NOT NULL AUTO_INCREMENT + , date_agreed_on DATETIME NOT NULL + , policy_uid BIGINT(20) NOT NULL + , user_id BIGINT(20) NOT NULL + , PRIMARY KEY (uid) + , KEY (policy_uid) + , CONSTRAINT FK_lams_consent_1_1 FOREIGN KEY (policy_uid) + REFERENCES lams_policy (uid) + , KEY (user_id) + , CONSTRAINT FK_lams_consent_2 FOREIGN KEY (user_id) + REFERENCES lams_user (user_id) +); + +INSERT INTO lams_policy_state VALUES (1, 'ACTIVE'); +INSERT INTO lams_policy_state VALUES (2, 'INACTIVE'); +INSERT INTO lams_policy_state VALUES (3, 'DRAFT'); + +INSERT INTO lams_policy_type VALUES (1, 'TYPE_SITE_POLICY'); +INSERT INTO lams_policy_type VALUES (2, 'TYPE_PRIVACY_POLICY'); +INSERT INTO lams_policy_type VALUES (3, 'TYPE_THIRD_PARTIES_POLICY'); +INSERT INTO lams_policy_type VALUES (4, 'TYPE_OTHER'); + +----------------------Put all sql statements above here------------------------- + +-- If there were no errors, commit and restore autocommit to on +COMMIT; +SET AUTOCOMMIT = 1; +SET FOREIGN_KEY_CHECKS=1; \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/policies/Policy.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/policies/Policy.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/policies/Policy.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,164 @@ +package org.lamsfoundation.lams.policies; + +import java.util.Date; +import java.util.Set; + +import org.lamsfoundation.lams.usermanagement.User; + +public class Policy { + + /** active policy */ + public static final Integer STATUS_ACTIVE = new Integer(1); + /** inactive policy */ + public static final Integer STATUS_INACTIVE = new Integer(2); + /** The state for draft policy */ + public static final Integer STATUS_DRAFT = new Integer(3); + + /** active policy */ + public static final Integer TYPE_SITE_POLICY = new Integer(1); + /** inactive policy */ + public static final Integer TYPE_PRIVACY_POLICY = new Integer(2); + /** The state for draft policy */ + public static final Integer TYPE_THIRD_PARTIES_POLICY = new Integer(3); + /** The state for draft policy */ + public static final Integer TYPE_OTHER = new Integer(4); + + /** identifier field */ + private Long uid; + + /** + * Shared by all policies created out of one parent one. + */ + private Long policyId; + + /** persistent field */ + private String policyName; + + /** persistent field */ + private String version; + + /** persistent field */ + private String summary; + + /** persistent field */ + private String fullPolicy; + + /** persistent field */ + private Integer policyStateId; + + /** persistent field */ + private Integer policyTypeId; + + private User createdBy; + + /** Date this policy was modified the last time */ + private Date lastModified; + + private Set consents; + + // *************** NON Persistent Fields ******************** + + private boolean hasPreviousVersions; + + /** default constructor */ + public Policy() { + lastModified = new Date(); // default value is set to when the object is created + } + + // --------------------------------------------------------------------- + // Getters and Setters + // --------------------------------------------------------------------- + public Long getUid() { + return uid; + } + + public void setUid(Long id) { + this.uid = id; + } + + public Long getPolicyId() { + return policyId; + } + + public void setPolicyId(Long policyId) { + this.policyId = policyId; + } + + public Integer getPolicyStateId() { + return this.policyStateId; + } + + public void setPolicyStateId(Integer policyStateId) { + this.policyStateId = policyStateId; + } + + public Integer getPolicyTypeId() { + return this.policyTypeId; + } + + public void setPolicyTypeId(Integer policyTypeId) { + this.policyTypeId = policyTypeId; + } + + public String getPolicyName() { + return policyName; + } + public void setPolicyName(String policyName) { + this.policyName = policyName; + } + + public String getVersion() { + return version; + } + public void setVersion(String version) { + this.version = version; + } + + public String getSummary() { + return summary; + } + public void setSummary(String summary) { + this.summary = summary; + } + + public String getFullPolicy() { + return fullPolicy; + } + public void setFullPolicy(String fullPolicy) { + this.fullPolicy = fullPolicy; + } + + public User getCreatedBy() { + return this.createdBy; + } + + public void setCreatedBy(User createdBy) { + this.createdBy = createdBy; + } + + public Date getLastModified() { + return lastModified; + } + + /* If lastModified is null, then it will default to the current date/time */ + public void setLastModified(Date lastModified) { + this.lastModified = lastModified != null ? lastModified : new Date(); + } + + public Set getConsents() { + return this.consents; + } + + public void setConsents(Set consents) { + this.consents = consents; + } + + public void setPreviousVersions(boolean hasPreviousVersions) { + this.hasPreviousVersions = hasPreviousVersions; + } + + public boolean hasPreviousVersions() { + return hasPreviousVersions; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/policies/PolicyConsent.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/policies/PolicyConsent.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/policies/PolicyConsent.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,60 @@ +package org.lamsfoundation.lams.policies; + +import java.util.Date; + +import org.lamsfoundation.lams.usermanagement.User; + +public class PolicyConsent { + + private Long uid; + + private Date dateAgreedOn; + + private Policy policy; + + /** persistent field */ + private User user; + + /** default constructor */ + public PolicyConsent() { + dateAgreedOn = new Date(); // default value is set to when the object is created + } + + /** + */ + public Long getUid() { + return uid; + } + + public void setUid(Long uid) { + this.uid = uid; + } + + public Date getDateAgreedOn() { + return dateAgreedOn; + } + + /* If dateAgreedOn is null, then it will default to the current date/time */ + public void setDateAgreedOn(Date dateAgreedOn) { + this.dateAgreedOn = dateAgreedOn != null ? dateAgreedOn : new Date(); + } + + /** + */ + public Policy getPolicy() { + return policy; + } + + public void setPolicy(Policy policy) { + this.policy = policy; + } + + public User getUser() { + return this.user; + } + + public void setUser(User user) { + this.user = user; + } + +} Index: lams_common/src/java/org/lamsfoundation/lams/policies/dao/IPolicyDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/policies/dao/IPolicyDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/policies/dao/IPolicyDAO.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,42 @@ +/**************************************************************** + * 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.policies.dao; + +import java.util.List; + +import org.lamsfoundation.lams.policies.Policy; + +public interface IPolicyDAO { + + Policy getPolicyByUid(Long uid); + + List getPolicies(); + + List getActivePolicies(); + + List getActivePoliciesWithConsents(); + + List getPreviousVersionsPolicies(Long policyId); + +} Index: lams_common/src/java/org/lamsfoundation/lams/policies/dao/hibernate/PolicyDAO.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/policies/dao/hibernate/PolicyDAO.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/policies/dao/hibernate/PolicyDAO.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,40 @@ +package org.lamsfoundation.lams.policies.dao.hibernate; + +import java.util.List; + +import org.lamsfoundation.lams.dao.hibernate.LAMSBaseDAO; +import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.dao.IPolicyDAO; +import org.springframework.stereotype.Repository; + +@Repository +public class PolicyDAO extends LAMSBaseDAO implements IPolicyDAO { + + @Override + public Policy getPolicyByUid(Long uid) { + return (Policy) super.find(Policy.class, uid); + } + + @Override + public List getPolicies() { + return super.findAll(Policy.class); + } + + @Override + public List getActivePolicies() { + String query = "from Policy p where p.policyStateId=1 GROUP BY p.policyId "; + return (List) doFind(query); + } + + @Override + public List getActivePoliciesWithConsents() { + String query = "from Policy p where p.policyStateId=1 GROUP BY p.policyId "; + return (List) doFind(query); + } + + @Override + public List getPreviousVersionsPolicies(Long policyId) { + String query = "from Policy p where p.policyId=? and p.policyStateId=2"; + return (List) doFind(query, policyId); + } +} Index: lams_common/src/java/org/lamsfoundation/lams/policies/service/IPolicyService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/policies/service/IPolicyService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/policies/service/IPolicyService.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,43 @@ +/**************************************************************** + * 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.policies.service; + +import java.util.List; + +import org.lamsfoundation.lams.policies.Policy; + +public interface IPolicyService { + + void storeUserConsent(String login, Long policyUid); + + Policy getPolicyByUid(Long uid); + + List getPolicies(); + + List getActivePolicies(); + + List getPreviousVersionsPolicies(Long policyId); + + void changePolicyStatus(Long policyUid, Integer newPolicyStatus); +} Index: lams_common/src/java/org/lamsfoundation/lams/policies/service/PolicyService.java =================================================================== diff -u --- lams_common/src/java/org/lamsfoundation/lams/policies/service/PolicyService.java (revision 0) +++ lams_common/src/java/org/lamsfoundation/lams/policies/service/PolicyService.java (revision 52ed825cf80fc4c9f1b9e114c80b09913e86002e) @@ -0,0 +1,84 @@ +package org.lamsfoundation.lams.policies.service; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.lamsfoundation.lams.lesson.Lesson; +import org.lamsfoundation.lams.lesson.service.ILessonService; +import org.lamsfoundation.lams.policies.Policy; +import org.lamsfoundation.lams.policies.PolicyConsent; +import org.lamsfoundation.lams.policies.dao.IPolicyDAO; +import org.lamsfoundation.lams.signup.dao.ISignupDAO; +import org.lamsfoundation.lams.signup.model.SignupOrganisation; +import org.lamsfoundation.lams.usermanagement.AuthenticationMethod; +import org.lamsfoundation.lams.usermanagement.Role; +import org.lamsfoundation.lams.usermanagement.SupportedLocale; +import org.lamsfoundation.lams.usermanagement.User; +import org.lamsfoundation.lams.usermanagement.service.IUserManagementService; +import org.lamsfoundation.lams.util.Configuration; +import org.lamsfoundation.lams.util.ConfigurationKeys; +import org.lamsfoundation.lams.util.LanguageUtil; + +public class PolicyService implements IPolicyService { + + private IPolicyDAO policyDAO; + private IUserManagementService userManagementService; + private ILessonService lessonService; + + @Override + public void storeUserConsent(String login, Long policyUid) { + User user = userManagementService.getUserByLogin(login); + Policy policy = policyDAO.getPolicyByUid(policyUid); + + PolicyConsent consent = new PolicyConsent(); + consent.setUser(user); + consent.setPolicy(policy); + userManagementService.save(consent); + } + + @Override + public Policy getPolicyByUid(Long uid) { + return policyDAO.getPolicyByUid(uid); + } + + @Override + public void changePolicyStatus(Long policyUid, Integer newPolicyStatus) { + Policy policy = policyDAO.getPolicyByUid(policyUid); + policy.setPolicyStateId(newPolicyStatus); + userManagementService.save(policy); + } + + @Override + public List getPolicies() { + return policyDAO.getPolicies(); + } + + @Override + public List getActivePolicies() { + return policyDAO.getActivePolicies(); + } + + @Override + public List getPreviousVersionsPolicies(Long policyId) { + return policyDAO.getPreviousVersionsPolicies(policyId); + } + + public void setPolicyDAO(IPolicyDAO policyDAO) { + this.policyDAO = policyDAO; + } + + public void setUserManagementService(IUserManagementService userManagementService) { + this.userManagementService = userManagementService; + } + + public void setLessonService(ILessonService lessonService) { + this.lessonService = lessonService; + } +}