Index: lams_central/conf/language/lams/ApplicationResources.properties =================================================================== diff -u -r7e26cc267b556ce7f7b2116b13a9afe02f353d74 -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_central/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 7e26cc267b556ce7f7b2116b13a9afe02f353d74) +++ lams_central/conf/language/lams/ApplicationResources.properties (.../ApplicationResources.properties) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -73,6 +73,8 @@ index.addlesson = Add Lesson index.monitor = Monitor index.dummymonitor = Dummy Monitor +index.organisation.link = Course URL: +index.organisation.link.tooltip = Copy course URL to clipboard title.import.result = Import tool content result title.import = Import tool content title.import.instruction = Please choose LAMS design to import. Index: lams_central/src/java/org/lamsfoundation/lams/web/DisplayGroupController.java =================================================================== diff -u -rf3e44aee5373a1233080ea5acd1cb5959bb46544 -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_central/src/java/org/lamsfoundation/lams/web/DisplayGroupController.java (.../DisplayGroupController.java) (revision f3e44aee5373a1233080ea5acd1cb5959bb46544) +++ lams_central/src/java/org/lamsfoundation/lams/web/DisplayGroupController.java (.../DisplayGroupController.java) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -55,6 +55,7 @@ import org.lamsfoundation.lams.util.Configuration; import org.lamsfoundation.lams.util.ConfigurationKeys; import org.lamsfoundation.lams.util.IndexUtils; +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; @@ -225,6 +226,11 @@ @SuppressWarnings("unchecked") private IndexOrgBean populateContentsOrgBean(IndexOrgBean orgBean, Organisation org, List roles, String username, boolean isSysAdmin) throws SQLException, NamingException { + if (Configuration.getAsBoolean(ConfigurationKeys.ALLOW_DIRECT_LESSON_LAUNCH)) { + orgBean.setEncodedOrgId( + WebUtil.ORG_SHORTENING_PREFIX + WebUtil.encodeIdForDirectLaunch(org.getOrganisationId())); + } + Integer userId = getUser(username).getUserId(); // set lesson beans Index: lams_central/src/java/org/lamsfoundation/lams/web/IndexController.java =================================================================== diff -u -r7fe28edd2994800c1cbd0a81b19f398191e00f2e -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_central/src/java/org/lamsfoundation/lams/web/IndexController.java (.../IndexController.java) (revision 7fe28edd2994800c1cbd0a81b19f398191e00f2e) +++ lams_central/src/java/org/lamsfoundation/lams/web/IndexController.java (.../IndexController.java) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -178,7 +178,8 @@ List favoriteOrganisations = userManagementService .getFavoriteOrganisationsByUser(userDTO.getUserID()); request.setAttribute("favoriteOrganisations", favoriteOrganisations); - request.setAttribute("activeOrgId", user.getLastVisitedOrganisationId()); + Integer targetOrgId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID, true); + request.setAttribute("activeOrgId", targetOrgId == null ? user.getLastVisitedOrganisationId() : targetOrgId); boolean isSysadmin = request.isUserInRole(Role.SYSADMIN); int userCoursesCount = userManagementService.getCountActiveCoursesByUser(userDTO.getUserID(), isSysadmin, null); Index: lams_central/src/java/org/lamsfoundation/lams/web/LaunchLearnerUrlServlet.java =================================================================== diff -u -rd416d14c233164ac4787360cbd490f31227694cd -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_central/src/java/org/lamsfoundation/lams/web/LaunchLearnerUrlServlet.java (.../LaunchLearnerUrlServlet.java) (revision d416d14c233164ac4787360cbd490f31227694cd) +++ lams_central/src/java/org/lamsfoundation/lams/web/LaunchLearnerUrlServlet.java (.../LaunchLearnerUrlServlet.java) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -51,7 +51,7 @@ @Autowired private ILessonService lessonService; - + /* * Request Spring to lookup the applicationContext tied to the current ServletContext and inject service beans * available in that applicationContext. @@ -64,27 +64,37 @@ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - String encodedLessonId = request.getPathInfo(); + String encodedId = request.getPathInfo(); // redirect to login page if accessing / URL - if (StringUtils.isBlank(encodedLessonId) || encodedLessonId.length() < 2) { + if (StringUtils.isBlank(encodedId) || encodedId.length() < 2) { String lamsUrl = Configuration.get(ConfigurationKeys.SERVER_URL); response.sendRedirect(lamsUrl); return; } // cut off the first '/' - encodedLessonId = encodedLessonId.substring(1); + encodedId = encodedId.substring(1); + boolean isOrganisationId = encodedId.startsWith(WebUtil.ORG_SHORTENING_PREFIX); + if (isOrganisationId) { + encodedId = encodedId.replaceFirst(WebUtil.ORG_SHORTENING_PREFIX, ""); + String decodedOrgId = WebUtil.decodeIdForDirectLaunch(encodedId); + int orgId = Integer.parseInt(decodedOrgId); + String lamsUrl = Configuration.get(ConfigurationKeys.SERVER_URL) + "index.do"; + response.sendRedirect(lamsUrl + "index.do?" + AttributeNames.PARAM_ORGANISATION_ID + "=" + orgId); + return; + } + Long lessonId; try { - String decodedLessonId = WebUtil.decodeIdForDirectLaunch(encodedLessonId); + String decodedLessonId = WebUtil.decodeIdForDirectLaunch(encodedId); lessonId = Long.valueOf(decodedLessonId); } catch (IllegalArgumentException e) { - log.warn("Supplied lessonId: " + encodedLessonId + " has wrong format."); + log.warn("Supplied lessonId: " + encodedId + " has wrong format."); response.sendError(HttpServletResponse.SC_BAD_REQUEST, - "Supplied lessonId: " + encodedLessonId + " has wrong format."); + "Supplied lessonId: " + encodedId + " has wrong format."); // return mapping.findForward("error"); // displayMessage(request, response, "error.lessonid.has.wrong.format"); return; Index: lams_central/web/css/_main_base.scss =================================================================== diff -u -rebb598b9d631fa479aef19110dc7b8c2cce0575b -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_central/web/css/_main_base.scss (.../_main_base.scss) (revision ebb598b9d631fa479aef19110dc7b8c2cce0575b) +++ lams_central/web/css/_main_base.scss (.../_main_base.scss) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -492,3 +492,7 @@ border-bottom: $border-thin-default; padding-bottom: 15px; } + +#direct-org-launch-link-copy-button { + cursor: pointer; +} \ No newline at end of file Index: lams_central/web/group.jsp =================================================================== diff -u -r4c2d1f37b92435907ec4ce23cb635a7cd9e4161e -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_central/web/group.jsp (.../group.jsp) (revision 4c2d1f37b92435907ec4ce23cb635a7cd9e4161e) +++ lams_central/web/group.jsp (.../group.jsp) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -3,6 +3,7 @@ <%@ page import="org.lamsfoundation.lams.util.ConfigurationKeys"%> <%=Configuration.getAsBoolean(ConfigurationKeys.ENABLE_COLLAPSING_SUBCOURSES)%> +<%=Configuration.getAsBoolean(ConfigurationKeys.ALLOW_DIRECT_LESSON_LAUNCH)%>
@@ -18,6 +19,15 @@ + + + + r/ + + + Index: lams_central/web/includes/javascript/main.js =================================================================== diff -u -r020c86cfa246722a71b281ab9fd68e6a8c4b706e -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_central/web/includes/javascript/main.js (.../main.js) (revision 020c86cfa246722a71b281ab9fd68e6a8c4b706e) +++ lams_central/web/includes/javascript/main.js (.../main.js) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -696,3 +696,8 @@ } } } + +function copyOrgUrlToClipboard(){ + var copyText = $('#direct-org-launch-link').text(); + navigator.clipboard.writeText(copyText); +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/index/IndexOrgBean.java =================================================================== diff -u -rebb598b9d631fa479aef19110dc7b8c2cce0575b -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_common/src/java/org/lamsfoundation/lams/index/IndexOrgBean.java (.../IndexOrgBean.java) (revision ebb598b9d631fa479aef19110dc7b8c2cce0575b) +++ lams_common/src/java/org/lamsfoundation/lams/index/IndexOrgBean.java (.../IndexOrgBean.java) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -43,6 +43,7 @@ private Integer type; private boolean favorite = false; private boolean collapsed = false; + private String encodedOrgId; private List links; private List moreLinks; private List lessons; @@ -52,9 +53,9 @@ this.id = id; this.name = name; this.type = type; - this.links = new ArrayList(); - this.lessons = new ArrayList(); - this.childIndexOrgBeans = new ArrayList(); + this.links = new ArrayList<>(); + this.lessons = new ArrayList<>(); + this.childIndexOrgBeans = new ArrayList<>(); } /** @@ -200,7 +201,7 @@ public void addChildOrgBean(IndexOrgBean orgBean) { childIndexOrgBeans.add(orgBean); } - + /** * @return whether user marked this organisation as favorite */ @@ -211,7 +212,7 @@ public void setFavorite(boolean favorite) { this.favorite = favorite; } - + public boolean getCollapsed() { return this.collapsed; } @@ -220,4 +221,11 @@ this.collapsed = collapsed; } -} + public String getEncodedOrgId() { + return encodedOrgId; + } + + public void setEncodedOrgId(String encodedOrgId) { + this.encodedOrgId = encodedOrgId; + } +} \ No newline at end of file Index: lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java =================================================================== diff -u -rd416d14c233164ac4787360cbd490f31227694cd -r78a307cb67e1f6e62a007f35e4a5eeeabd48b676 --- lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision d416d14c233164ac4787360cbd490f31227694cd) +++ lams_common/src/java/org/lamsfoundation/lams/util/WebUtil.java (.../WebUtil.java) (revision 78a307cb67e1f6e62a007f35e4a5eeeabd48b676) @@ -57,6 +57,8 @@ private static final String URL_SHORTENING_CYPHER = "jbdnuteywk"; + public static final String ORG_SHORTENING_PREFIX = "c-"; + /** * @exception IllegalArgumentException * - if not set @@ -496,7 +498,7 @@ * @param id * @return */ - public static String encodeIdForDirectLaunch(Long id) { + public static String encodeIdForDirectLaunch(Number id) { String encodedId = id.toString(); encodedId = encodedId.replace('0', URL_SHORTENING_CYPHER.charAt(0)); encodedId = encodedId.replace('1', URL_SHORTENING_CYPHER.charAt(1)); @@ -519,10 +521,14 @@ * @return */ public static String decodeIdForDirectLaunch(String encodedId) throws IllegalArgumentException { + boolean isOrganisationId = encodedId.startsWith(ORG_SHORTENING_PREFIX); + if (isOrganisationId) { + encodedId = encodedId.replaceFirst(ORG_SHORTENING_PREFIX, ""); + } // it should contain only the characters from URL_SHORTENING_CYPHER if (!encodedId.matches("[" + URL_SHORTENING_CYPHER + "]*")) { - throw new IllegalArgumentException("Lesson or course ID: " + encodedId + " has wrong format."); + throw new IllegalArgumentException("Lesson or organisation ID: " + encodedId + " has wrong format."); } String decodedId = encodedId;