From acc77ae921b7a11484e0da12af059963b5fce339 Mon Sep 17 00:00:00 2001 From: Sam Ottenhoff Date: Fri, 24 Jan 2025 15:59:34 -0500 Subject: [PATCH 1/2] SAK-50915 LTI send instructor role for DA user with instructor perms --- .../sakaiproject/lti/util/SakaiLTIUtil.java | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java b/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java index 9bc570f66785..757f38dc4b4a 100644 --- a/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java +++ b/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java @@ -609,30 +609,31 @@ public static void addUserInfo(Properties ltiProps, Properties lti13subst, User } } - public static String getCurrentUserSakaiRole(User user, String context, String roleMapProp) { + public static String getCurrentUserSakaiRole(User user, String context) { + if (user == null) return null; String realmId = SiteService.siteReference(context); - Map toolRoleMap = convertOutboundRoleMapPropToMap(roleMapProp); - Map propRoleMap = convertOutboundRoleMapPropToMap( - ServerConfigurationService.getString(LTI_OUTBOUND_ROLE_MAP) - ); - Map defaultRoleMap = convertOutboundRoleMapPropToMap(LTI_OUTBOUND_ROLE_MAP_DEFAULT); try { - if (user != null) { - Role role = null; - String sakaiRole = null; - AuthzGroup realm = ComponentManager.get(AuthzGroupService.class).getAuthzGroup(realmId); - if (realm != null) { - role = realm.getUserRole(user.getId()); - } - if (role != null) { - sakaiRole = role.getId(); + Role role = null; + String sakaiRole = null; + AuthzGroup realm = ComponentManager.get(AuthzGroupService.class).getAuthzGroup(realmId); + if (realm != null) { + role = realm.getUserRole(user.getId()); + + // Handle a delegated access user + if (role == null) { + if (SiteService.allowUpdateSite(context)) { + role = realm.getRole(realm.getMaintainRole()); + } } - if (StringUtils.isNotBlank(sakaiRole)) return sakaiRole; - } - } catch (GroupNotDefinedException e) { - log.error("SiteParticipantHelper.getExternalRealmId: site realm not found {}", e.getMessage()); + } + if (role != null) { + sakaiRole = role.getId(); + } + if (StringUtils.isNotBlank(sakaiRole)) return sakaiRole; + } catch (GroupNotDefinedException e) { + log.error("site realm not found {}", e.getMessage()); } return null; } @@ -650,7 +651,7 @@ public static String getFallBackRole(String context) { public static void addRoleInfo(Properties props, Properties lti13subst, User user, String context, String roleMapProp) { - String sakaiRole = SecurityService.isSuperUser() ? "admin" : getCurrentUserSakaiRole(user, context, roleMapProp); + String sakaiRole = SecurityService.isSuperUser() ? "admin" : getCurrentUserSakaiRole(user, context); String outboundRole = null; if (StringUtils.isNotBlank(sakaiRole)) { From 5853814697185ee16cbb3f7a6f0f68c2c00339a5 Mon Sep 17 00:00:00 2001 From: Sam Ottenhoff Date: Fri, 24 Jan 2025 16:01:01 -0500 Subject: [PATCH 2/2] slightly more compact --- .../src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java b/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java index 757f38dc4b4a..667cb2b4bc8f 100644 --- a/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java +++ b/lti/lti-common/src/java/org/sakaiproject/lti/util/SakaiLTIUtil.java @@ -622,10 +622,8 @@ public static String getCurrentUserSakaiRole(User user, String context) { role = realm.getUserRole(user.getId()); // Handle a delegated access user - if (role == null) { - if (SiteService.allowUpdateSite(context)) { - role = realm.getRole(realm.getMaintainRole()); - } + if (role == null && SiteService.allowUpdateSite(context)) { + role = realm.getRole(realm.getMaintainRole()); } } if (role != null) {