Skip to content

Commit

Permalink
fixed space caching issue when adding or removing spaces on Admin page
Browse files Browse the repository at this point in the history
  • Loading branch information
albogdano committed Jun 18, 2024
1 parent 3f7295b commit d31308f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public String addSpace(@RequestParam String space,
authUser.getSpaces().add(spaceObj.getId() + Para.getConfig().separator() + spaceObj.getName());
authUser.update();
model.addAttribute("space", spaceObj);
utils.getAllSpacesAdmin().add(spaceObj);
utils.addSpaceToCachedList(spaceObj);
} else {
model.addAttribute("error", Collections.singletonMap("name", utils.getLang(req).get("posts.error1")));
}
Expand All @@ -204,7 +204,7 @@ public String removeSpace(@RequestParam String space, HttpServletRequest req, Ht
pc.delete(s);
authUser.getSpaces().remove(space);
authUser.update();
utils.getAllSpacesAdmin().remove(s);
utils.removeSpaceFromCachedList(s);
}
if (utils.isAjaxRequest(req)) {
res.setStatus(200);
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/com/erudika/scoold/utils/ScooldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,24 @@ public Set<Sysprop> getAllSpacesAdmin() {
collect(Collectors.toCollection(LinkedHashSet::new));
}

public void addSpaceToCachedList(Sysprop space) {
if (space != null) {
if (allSpaces == null || allSpaces.isEmpty()) {
getAllSpacesAdmin();
}
allSpaces.add(space);
}
}

public void removeSpaceFromCachedList(Sysprop space) {
if (space != null) {
if (allSpaces == null || allSpaces.isEmpty()) {
getAllSpacesAdmin();
}
allSpaces.remove(space);
}
}

public boolean canAccessSpace(Profile authUser, String targetSpaceId) {
if (authUser == null) {
return isDefaultSpacePublic() && isDefaultSpace(targetSpaceId);
Expand Down Expand Up @@ -2082,8 +2100,8 @@ public Map<String, Long> getApiKeysExpirations() {
return exp.getTime();
}
}
} catch (ParseException ex) {
logger.error("Failed to parse API key " + StringUtils.substring(jwt, 0, 10), ex);
} catch (Exception ex) {
logger.error("Failed to parse API key " + k + " - key doesn't seem to be in JWT format.", ex.getMessage());
}
return 0L;
}));
Expand Down

0 comments on commit d31308f

Please sign in to comment.