From c2cfd6ea881f43577fc412a9ccf0c3d30182a825 Mon Sep 17 00:00:00 2001 From: Steve Swinsburg Date: Tue, 31 May 2016 22:58:19 +1000 Subject: [PATCH] #2698 If TA has access to a 'group' and 'all', group filter is not shown since it was only checking the number of groups. It now checks the permissions as well. --- .../gradebookng/tool/pages/GradebookPage.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java index ad57d73f2a21..8ff978433cea 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/tool/pages/GradebookPage.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Random; +import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.time.StopWatch; import org.apache.wicket.AttributeModifier; import org.apache.wicket.Component; @@ -63,6 +64,7 @@ import org.sakaiproject.gradebookng.tool.panels.ToggleGradeItemsToolbarPanel; import org.sakaiproject.service.gradebook.shared.Assignment; import org.sakaiproject.service.gradebook.shared.CategoryDefinition; +import org.sakaiproject.service.gradebook.shared.GraderPermission; import org.sakaiproject.service.gradebook.shared.PermissionDefinition; import org.sakaiproject.service.gradebook.shared.SortType; import org.sakaiproject.tool.gradebook.Gradebook; @@ -95,6 +97,9 @@ public class GradebookPage extends BasePage { Label liveGradingFeedback; Form form; + + List permissions = new ArrayList<>(); + boolean showGroupFilter = true; @SuppressWarnings({ "rawtypes", "unchecked", "serial" }) public GradebookPage() { @@ -116,7 +121,7 @@ public GradebookPage() { } // no perms - List permissions = this.businessService.getPermissionsForUser(this.currentUserUuid); + permissions = this.businessService.getPermissionsForUser(this.currentUserUuid); if(permissions.isEmpty()) { PageParameters params = new PageParameters(); params.add("message", getString("ta.nopermission")); @@ -564,7 +569,23 @@ public boolean isVisible() { // if only one group, just show the title // otherwise add the 'all groups' option - if (this.role == GbRole.TA && groups.size() == 1) { + // cater for the case where there is only one group visible to TA but they can see everyone. + if (this.role == GbRole.TA) { + + //if only one group, hide the filter + if (groups.size() == 1) { + showGroupFilter = false; + + // but need to double check permissions to see if we have any permissions with no group reference + permissions.forEach(p -> { + if (!StringUtils.equalsIgnoreCase(p.getFunction(),GraderPermission.VIEW_COURSE_GRADE.toString()) && StringUtils.isBlank(p.getGroupReference())) { + showGroupFilter = true; + } + }); + } + } + + if(!showGroupFilter) { toolbar.add(new Label("groupFilterOnlyOne", Model.of(groups.get(0).getTitle()))); } else { toolbar.add(new EmptyPanel("groupFilterOnlyOne").setVisible(false)); @@ -575,12 +596,11 @@ public boolean isVisible() { // does the TA have any permissions set? // we can assume that if they have any then there is probably some sort of group restriction so we can change the label - if (!this.businessService.getPermissionsForUser(this.currentUserUuid).isEmpty()) { + if (!this.permissions.isEmpty()) { allGroupsTitle = getString("groups.available"); } } groups.add(0, new GbGroup(null, allGroupsTitle, null, GbGroup.Type.ALL)); - } final DropDownChoice groupFilter = new DropDownChoice("groupFilter", new Model(),