From ebafb4f8da8556314e7e1217e7417747a9f31562 Mon Sep 17 00:00:00 2001 From: kunaljaykam Date: Sat, 18 May 2024 20:13:55 +0530 Subject: [PATCH] SAK-49150 Gradebook: TA not in group, but with permission to grade a group, cannot actually gradesave progress --- .../business/GradebookNgBusinessService.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java index 4300c3d9b78c..9e9c72089c3e 100644 --- a/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java +++ b/gradebookng/tool/src/java/org/sakaiproject/gradebookng/business/GradebookNgBusinessService.java @@ -1795,6 +1795,7 @@ public List sortGradeMatrix(Map */ public List getSiteSectionsAndGroups() { final String siteId = getCurrentSiteId(); + final String userId = getCurrentUser().getId(); final List rval = new ArrayList<>(); @@ -1809,7 +1810,22 @@ public List getSiteSectionsAndGroups() { // get groups (handles both groups and sections) try { final Site site = this.siteService.getSite(siteId); - final Collection groups = isSuperUser() || role == GbRole.INSTRUCTOR ? site.getGroups() : site.getGroupsWithMember(userDirectoryService.getCurrentUser().getId()); + + final List perms = getPermissionsForUser(userId, siteId); + + List groupReferences = perms.stream().map(PermissionDefinition::getGroupReference).filter(Objects::nonNull).collect(Collectors.toList()); + + final Collection groups; + + if (GbRole.INSTRUCTOR.equals(role)) { + groups = site.getGroups(); + } else { + if (!groupReferences.isEmpty()) { + groups = site.getGroups().stream().filter(group -> groupReferences.contains(group.getReference())).collect(Collectors.toList()); + } else { + groups = site.getGroupsWithMember(userDirectoryService.getCurrentUser().getId()); + } + } for (final Group group : groups) { rval.add(new GbGroup(group.getId(), group.getTitle(), group.getReference(), GbGroup.Type.GROUP));