Skip to content

Commit

Permalink
SAK-49990 Roster the profile link is unique to current user and cant …
Browse files Browse the repository at this point in the history
…be part of cache
  • Loading branch information
ottenhoff committed May 10, 2024
1 parent 5e6f679 commit 8eaec0b
Showing 1 changed file with 20 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@ private List<RosterMember> filterMembers(Site site, String currentUserId, List<R
}

// Now add any instructors
filtered.addAll(unfiltered.stream().filter(m -> m.isInstructor()).collect(Collectors.toList()));
filtered.addAll(unfiltered.stream().filter(RosterMember::isInstructor).collect(Collectors.toList()));

// The group loop is shuffling members, sort the list again
Collections.sort(filtered, memberComparator);
filtered.sort(memberComparator);
} else if (null != site.getGroup(groupId)) {
// get all members of requested groupId if current user is
// member
Expand All @@ -678,7 +678,12 @@ private List<RosterMember> filterMembers(Site site, String currentUserId, List<R
for (RosterMember m : filtered) {
if (check.add(m.getUserId())) {
cleanedMembers.add(m);
// Now strip out any unauthorised info

// Apply a unique profile link to each user outside of the caching layer
// e.g., /portal/site/~current-user-id/tool/profile2tooluuid/otherUserId
m.setProfileLink(getProfileToolLink(m.getUserId()));

// Now strip out any unauthorised info
if (!isAllowed(currentUserId, RosterFunctions.ROSTER_FUNCTION_VIEWEMAIL, site.getReference())) {
m.setEmail(null);
} else {
Expand Down Expand Up @@ -803,8 +808,6 @@ private RosterMember getRosterMember(Map<String, User> userMap, Collection<Group
}
}

rosterMember.setProfileLink(getProfileToolLink(userId));

// See if there is a pronunciation available for the user
String pronunciation = pronounceMap.get(user.getId());
//Try by email instead of Id
Expand Down Expand Up @@ -892,28 +895,14 @@ private List<RosterMember> getEnrollmentMembership(Site site, String enrollmentS
* RESPONSIBILITY TO FILTER ON AUTHZ RULES.
*/
private List<RosterMember> getAndCacheSortedMembership(Site site, String groupId, String roleId) {

String siteId = site.getId();

Cache cache = getCache(MEMBERSHIPS_CACHE);

String key = siteId;

if (groupId != null) {
key += "#" + groupId;
}

if(roleId != null) {
key += "#" + roleId;
}

log.debug("Key: {}", key);
String key = siteId + (groupId == null ? "" : "#" + groupId) + (roleId == null ? "" : "#" + roleId);

List<RosterMember> siteMembers = (List<RosterMember>) cache.get(key);
log.debug("Trying to get '{}' from cache. Is null? {}", key, siteMembers == null);

if (siteMembers == null) {
log.debug("Cache miss on '{}'.", key);

Set<Member> membership = site.getMembers();

if (null == membership) {
Expand Down Expand Up @@ -955,18 +944,18 @@ private List<RosterMember> getAndCacheSortedMembership(Site site, String groupId
}
cacheMembersMap.get(siteId + "#" + memberRoleId).add(rosterMember);
} catch (UserNotDefinedException e) {
log.warn("user not found: " + e.getId());
log.warn("user not found in membership: {}", e.getId());
}
}

cacheMembersMap.put(siteId, siteMembers);
log.debug("Caching on '{}' ...", siteId);

cacheMembersMap.values().forEach(a -> Collections.sort(a, memberComparator));
cacheMembersMap.values().forEach(a -> a.sort(memberComparator));
cache.putAll(cacheMembersMap);
return (List<RosterMember>) cache.get(key);
siteMembers = (List<RosterMember>) cache.get(key);
}
log.debug("Cache hit on '{}'.", key);

return siteMembers;
}

Expand All @@ -980,16 +969,14 @@ private List<RosterMember> getAndCacheSortedMembership(Site site, String groupId
* RESPONSIBILITY TO FILTER ON AUTHZ RULES.
*/
private Map<String, List<RosterMember>> getAndCacheSortedEnrollmentSet(Site site, String enrollmentSetId) {

String siteId = site.getId();

Cache cache = getCache(ENROLLMENTS_CACHE);

log.debug("Trying to get '{}' from enrollments cache ...", siteId);

Map<String, List<RosterMember>> membersMap = (Map<String, List<RosterMember>>) cache.get(siteId);
log.debug("Trying to get '{}' from enrollments cache. Is null? {}", siteId, membersMap == null);

if (membersMap == null) {
log.debug("Cache miss. Putting empty membersMap on {} ...", siteId);
membersMap = new HashMap<>();
cache.put(siteId, membersMap);
}
Expand All @@ -998,7 +985,6 @@ private Map<String, List<RosterMember>> getAndCacheSortedEnrollmentSet(Site site
&& membersMap.containsKey(enrollmentSetId + "#wait")
&& membersMap.containsKey(enrollmentSetId + "#enrolled")) {
log.debug("Cache hit on '{}'", enrollmentSetId);
return membersMap;
} else {
log.debug("Cache miss on '{}'", enrollmentSetId);

Expand Down Expand Up @@ -1039,19 +1025,18 @@ private Map<String, List<RosterMember>> getAndCacheSortedEnrollmentSet(Site site
members.add(member);
}

Collections.sort(members, memberComparator);
Collections.sort(waiting, memberComparator);
Collections.sort(enrolled, memberComparator);
members.sort(memberComparator);
waiting.sort(memberComparator);
enrolled.sort(memberComparator);

log.debug("Caching all enrollment set members on '{}#all' ...", enrollmentSetId);
membersMap.put(enrollmentSetId + "#all", members);
log.debug("Caching watlisted members on '{}#wait' ...", enrollmentSetId);
membersMap.put(enrollmentSetId + "#wait", waiting);
log.debug("Caching enrolled members on '{}#enrolled' ...", enrollmentSetId);
membersMap.put(enrollmentSetId + "#enrolled", enrolled);

return membersMap;
}
return membersMap;
}

/**
Expand Down

0 comments on commit 8eaec0b

Please sign in to comment.