Index: lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupController.java =================================================================== diff -u -rf90e719b4eea55b9146d569b08dd7611f78c9752 -rddb552387ac914ce1e6b67746a01632395120ac0 --- lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupController.java (.../OrganisationGroupController.java) (revision f90e719b4eea55b9146d569b08dd7611f78c9752) +++ lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupController.java (.../OrganisationGroupController.java) (revision ddb552387ac914ce1e6b67746a01632395120ac0) @@ -133,7 +133,7 @@ // check if user is allowed to view and edit groupings if (!securityService.hasOrgRole(organisationId, userId, new String[] { Role.GROUP_MANAGER, Role.MONITOR, Role.AUTHOR }, "view organisation groupings")) { - response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a participant in the organisation"); + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a super user in the organisation"); return null; } @@ -176,9 +176,6 @@ return "extGroups"; } - boolean isGroupSuperuser = userManagementService.isUserInRole(userId, organisationId, Role.GROUP_MANAGER); - request.setAttribute("canEdit", isGroupSuperuser || (activityID != null)); - Set orgGroupingDTOs = new TreeSet<>(); for (OrganisationGrouping orgGrouping : orgGroupings) { orgGroupingDTOs.add(new OrganisationGroupingDTO(orgGrouping)); @@ -214,17 +211,13 @@ return null; } - boolean isGroupSuperuser = userManagementService.isUserInRole(userId, organisationId, Role.GROUP_MANAGER); - if (targetOrganisationId == null) { targetOrganisationId = organisationId; } if (log.isDebugEnabled()) { log.debug("Displaying course groups for user " + userId + " and organisation " + targetOrganisationId); } - Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); - request.setAttribute("canEdit", isGroupSuperuser || (activityId != null)); ObjectNode orgGroupingJSON = JsonNodeFactory.instance.objectNode(); orgGroupingJSON.put("organisationId", targetOrganisationId); @@ -246,6 +239,7 @@ boolean isExternalGroupsSelected = extGroupIds != null && extGroupIds.length > 0; // check if any groups already exist in this grouping + Long activityId = WebUtil.readLongParam(request, AttributeNames.PARAM_ACTIVITY_ID, true); Grouping lessonGrouping = getLessonGrouping(activityId); Set lessonGroups = lessonGrouping == null ? null : lessonGrouping.getGroups(); if ((activityId != null) && (lessonGrouping != null) && (isExternalGroupsSelected || (orgGroupingId != null)) @@ -368,9 +362,9 @@ Integer userId = getUserDTO().getUserID(); int organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); // check if user is allowed to save grouping - if (!securityService.hasOrgRole(organisationId, userId, new String[] { Role.GROUP_MANAGER }, - "save organisation grouping")) { - response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a manager or admin in the organisation"); + if (!securityService.hasOrgRole(organisationId, userId, + new String[] { Role.GROUP_MANAGER, Role.MONITOR, Role.AUTHOR }, "save organisation grouping")) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a super user in the organisation"); } if (log.isDebugEnabled()) { @@ -437,9 +431,9 @@ // check if user is allowed to edit groups Integer userId = getUserDTO().getUserID(); int organisationId = WebUtil.readIntParam(request, AttributeNames.PARAM_ORGANISATION_ID); - if (!securityService.hasOrgRole(organisationId, userId, new String[] { Role.GROUP_MANAGER }, - "remove organisation grouping")) { - response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a manager or admin in the organisation"); + if (!securityService.hasOrgRole(organisationId, userId, + new String[] { Role.GROUP_MANAGER, Role.MONITOR, Role.AUTHOR }, "remove organisation grouping")) { + response.sendError(HttpServletResponse.SC_FORBIDDEN, "User is not a super user in the organisation"); return null; } Index: lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupServlet.java =================================================================== diff -u -rc975a1230b65f2245c5c77ba413afe97a2816df9 -rddb552387ac914ce1e6b67746a01632395120ac0 --- lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupServlet.java (.../OrganisationGroupServlet.java) (revision c975a1230b65f2245c5c77ba413afe97a2816df9) +++ lams_central/src/java/org/lamsfoundation/lams/web/OrganisationGroupServlet.java (.../OrganisationGroupServlet.java) (revision ddb552387ac914ce1e6b67746a01632395120ac0) @@ -116,7 +116,9 @@ boolean isGroupSuperuser = userManagementService.isUserInRole(user.getUserId(), organisation.getOrganisationId(), Role.MONITOR) || userManagementService.isUserInRole(user.getUserId(), organisation.getOrganisationId(), - Role.AUTHOR); + Role.AUTHOR) + || userManagementService.isUserInRole(user.getUserId(), organisation.getOrganisationId(), + Role.GROUP_MANAGER); if (!isGroupSuperuser) { log.error("User " + user.getUserId() + " may not perform group actions for course " + organisation.getOrganisationId()); @@ -235,7 +237,7 @@ } // check group name uniqueness - Set groups = new HashSet(grouping.getGroups()); + Set groups = new HashSet<>(grouping.getGroups()); for (OrganisationGroup group : groups) { if (group.getName().equals(groupName)) { throw new ServletException("Group with name \"" + groupingName + "\" exists in grouping with ID " @@ -279,7 +281,7 @@ return; } - Set groups = new HashSet(grouping.getGroups()); + Set groups = new HashSet<>(grouping.getGroups()); groups.remove(group); userManagementService.saveOrganisationGrouping(grouping, groups); @@ -406,7 +408,7 @@ @SuppressWarnings("unchecked") private OrganisationGrouping findGrouping(Integer organisationId, String groupingName) { - Map queryProperties = new TreeMap(); + Map queryProperties = new TreeMap<>(); queryProperties.put("organisationId", organisationId); queryProperties.put("name", groupingName); List result = userManagementService.findByProperties(OrganisationGrouping.class, @@ -416,7 +418,7 @@ @SuppressWarnings("unchecked") private OrganisationGroup findGroup(Long groupingId, String groupName) { - Map queryProperties = new TreeMap(); + Map queryProperties = new TreeMap<>(); queryProperties.put("groupingId", groupingId); queryProperties.put("name", groupName); List result = userManagementService.findByProperties(OrganisationGroup.class, Index: lams_central/web/includes/javascript/orgGroup.js =================================================================== diff -u -ra65568cc36db07abf19550359c0db03a9561c964 -rddb552387ac914ce1e6b67746a01632395120ac0 --- lams_central/web/includes/javascript/orgGroup.js (.../orgGroup.js) (revision a65568cc36db07abf19550359c0db03a9561c964) +++ lams_central/web/includes/javascript/orgGroup.js (.../orgGroup.js) (revision ddb552387ac914ce1e6b67746a01632395120ac0) @@ -34,13 +34,11 @@ }); } - if (canEdit) { - // allow adding new groups - $('#newGroupPlaceholder').click(function(){ - // the label is "Group X" where X is the top group number - addGroup(null, LABELS.GROUP_PREFIX_LABEL + ' ' + $('#groupsTable .groupContainer').length, null); - }); - } + // allow adding new groups + $('#newGroupPlaceholder').click(function(){ + // the label is "Group X" where X is the top group number + addGroup(null, LABELS.GROUP_PREFIX_LABEL + ' ' + $('#groupsTable .groupContainer').length, null); + }); }); @@ -126,63 +124,60 @@ userDivs.push(userDiv); userIds.push(userJSON.id); - // if teacher can not edit, then no drag&drop is available - if (canEdit) { - userDiv.draggable({ - 'appendTo' : 'body', - 'containment' : '#groupsTable', - 'revert' : 'invalid', - 'distance' : 20, - 'scroll' : false, - 'cursor' : 'move', - 'helper' : function(event){ - // include the user from which dragging started - $(this).addClass('draggableSelected'); - - // copy selected users - var helperContainer = $('
'); - $(this).siblings('.draggableSelected').addBack().each(function(){ - $(this).clone().appendTo(helperContainer); - }); - return helperContainer; - } - }) - - .click(function(event){ - var wasSelected = $(this).hasClass('draggableSelected'); - var parentId = $(this).parent().parent().attr('id'); - // this is needed for shift+click - var lastSelectedUser = lastSelectedUsers[parentId]; + userDiv.draggable({ + 'appendTo' : 'body', + 'containment' : '#groupsTable', + 'revert' : 'invalid', + 'distance' : 20, + 'scroll' : false, + 'cursor' : 'move', + 'helper' : function(event){ + // include the user from which dragging started + $(this).addClass('draggableSelected'); + + // copy selected users + var helperContainer = $('
'); + $(this).siblings('.draggableSelected').addBack().each(function(){ + $(this).clone().appendTo(helperContainer); + }); + return helperContainer; + } + }) + + .click(function(event){ + var wasSelected = $(this).hasClass('draggableSelected'); + var parentId = $(this).parent().parent().attr('id'); + // this is needed for shift+click + var lastSelectedUser = lastSelectedUsers[parentId]; + + if (event.shiftKey && lastSelectedUser && lastSelectedUser != this) { + // clear current selection + $(this).siblings().addBack().removeClass('draggableSelected'); - if (event.shiftKey && lastSelectedUser && lastSelectedUser != this) { - // clear current selection + // find range of users to select + var lastSelectedIndex = $(lastSelectedUser).index(); + var index = $(this).index(); + + var startingElem = lastSelectedIndex > index ? this : lastSelectedUser; + var endingElem = lastSelectedIndex > index ? lastSelectedUser : this; + + $(startingElem).nextUntil(endingElem).addBack().add(endingElem) + .addClass('draggableSelected'); + } else { + if (!event.ctrlKey) { + // clear current sleection $(this).siblings().addBack().removeClass('draggableSelected'); - - // find range of users to select - var lastSelectedIndex = $(lastSelectedUser).index(); - var index = $(this).index(); - - var startingElem = lastSelectedIndex > index ? this : lastSelectedUser; - var endingElem = lastSelectedIndex > index ? lastSelectedUser : this; - - $(startingElem).nextUntil(endingElem).addBack().add(endingElem) - .addClass('draggableSelected'); + } + + if (wasSelected && !event.shiftKey){ + $(this).removeClass('draggableSelected'); + lastSelectedUsers[parentId] = null; } else { - if (!event.ctrlKey) { - // clear current sleection - $(this).siblings().addBack().removeClass('draggableSelected'); - } - - if (wasSelected && !event.shiftKey){ - $(this).removeClass('draggableSelected'); - lastSelectedUsers[parentId] = null; - } else { - $(this).addClass('draggableSelected'); - lastSelectedUsers[parentId] = this; - } + $(this).addClass('draggableSelected'); + lastSelectedUsers[parentId] = this; } - }); - } + } + }); if (!createOnServer) { $('.userContainer', container).append(userDiv); @@ -209,48 +204,46 @@ sortUsers(container); }); - if (canEdit) { - $(container).droppable({ - 'activeClass' : 'droppableHighlight', - 'tolerance' : 'pointer', - 'drop' : function (event, ui) { - var draggableUserContainer = $(ui.draggable).parent(); - var thisUserContainer = $('.userContainer', this); - // do not do anything if it is the same container - // using "accept" feature breaks the layout - if (draggableUserContainer[0] != thisUserContainer[0]) { - var executeDrop = !lessonMode; - if (!executeDrop) { - var transferToLocked = $(this).hasClass('locked'); - // make sure user wants to transfer learners to a group which is already in use - executeDrop = !transferToLocked || confirm(LABELS.TRANSFER_LOCKED_LABEL); - if (executeDrop) { - var userIds = []; - $('div.draggableSelected', draggableUserContainer).each(function(){ - userIds.push($(this).attr('userId')); - }); - // execute transfer on server side - executeDrop = assignUsersToGroup(userIds, $(this)); - } - } - + $(container).droppable({ + 'activeClass' : 'droppableHighlight', + 'tolerance' : 'pointer', + 'drop' : function (event, ui) { + var draggableUserContainer = $(ui.draggable).parent(); + var thisUserContainer = $('.userContainer', this); + // do not do anything if it is the same container + // using "accept" feature breaks the layout + if (draggableUserContainer[0] != thisUserContainer[0]) { + var executeDrop = !lessonMode; + if (!executeDrop) { + var transferToLocked = $(this).hasClass('locked'); + // make sure user wants to transfer learners to a group which is already in use + executeDrop = !transferToLocked || confirm(LABELS.TRANSFER_LOCKED_LABEL); if (executeDrop) { - transferUsers(draggableUserContainer, thisUserContainer); + var userIds = []; + $('div.draggableSelected', draggableUserContainer).each(function(){ + userIds.push($(this).attr('userId')); + }); + // execute transfer on server side + executeDrop = assignUsersToGroup(userIds, $(this)); } - } - } - }); + } + + if (executeDrop) { + transferUsers(draggableUserContainer, thisUserContainer); + } + } + } + }); + - - $('.removeGroupButton', container).click(function(){ - removeGroup(container); + $('.removeGroupButton', container).click(function(){ + removeGroup(container); + }); + + if (lessonMode) { + $('input', container).blur(function(){ + renameGroup(container); }); - - if (lessonMode) { - $('input', container).blur(function(){ - renameGroup(container); - }); - } } } @@ -389,7 +382,7 @@ * Save a course grouping. */ function saveGroups(){ - if (!canEdit || lessonMode) { + if (lessonMode) { return false; } $('.errorMessage').hide(); @@ -580,10 +573,6 @@ } function importGroupsFromSpreadsheet() { - if (!canEdit) { - return false; - } - disableButtons(); var file = getValidateSpreadsheetFile(); if ( file != null && ( ! warnBeforeUpload || confirm(LABELS.WARNING_REPLACE_GROUPS_LABEL) ) ) { Index: lams_central/web/orgGroup.jsp =================================================================== diff -u -r721f7d62f6f34d24b9e9c690386253a4b12a0264 -rddb552387ac914ce1e6b67746a01632395120ac0 --- lams_central/web/orgGroup.jsp (.../orgGroup.jsp) (revision 721f7d62f6f34d24b9e9c690386253a4b12a0264) +++ lams_central/web/orgGroup.jsp (.../orgGroup.jsp) (revision ddb552387ac914ce1e6b67746a01632395120ac0) @@ -26,7 +26,6 @@ var grouping = ${grouping}, organisationId = grouping.organisationId, unassignedUsers = ${unassignedUsers}, - canEdit = ${canEdit}, groupingActivityId = '${param.activityID}', lessonId = '${lessonID}', lessonMode = ${lessonMode}, @@ -112,17 +111,15 @@
+ readonly="readonly" /> - - - +