Skip to content

Commit

Permalink
fixed new space missing in list of spaces if created by other admins,…
Browse files Browse the repository at this point in the history
… but reappears after restart
  • Loading branch information
albogdano committed Mar 19, 2024
1 parent edeb3b6 commit c7163c0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/main/java/com/erudika/scoold/core/Profile.java
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ public boolean isModInSpace(String space) {
}

public Set<String> getSpaces() {
if (ScooldUtils.getInstance().isMod(this) && ScooldUtils.getConfig().modsAccessAllSpaces()) {
if (ScooldUtils.getInstance().isAdmin(this) ||
(ScooldUtils.getInstance().isMod(this) && ScooldUtils.getConfig().modsAccessAllSpaces())) {
ScooldUtils utils = ScooldUtils.getInstance();
spaces = utils.getAllSpaces().stream().
map(s -> s.getId() + Para.getConfig().separator() + s.getName()).
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/com/erudika/scoold/utils/ScooldUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -127,6 +128,8 @@ public final class ScooldUtils {

private Set<Sysprop> allSpaces;
private Set<String> autoAssignedSpacesFromConfig;
private long lastSpacesCountTimestamp;
private int spacesCount = 0;

private static final ScooldConfig CONF = new ScooldConfig();

Expand Down Expand Up @@ -1374,17 +1377,19 @@ public boolean isAllSpaces(String space) {
}

public Set<Sysprop> getAllSpaces() {
if (allSpaces == null) {
allSpaces = new LinkedHashSet<>(pc.findQuery("scooldspace", "*", new Pager(Config.DEFAULT_LIMIT)));
}
return allSpaces;
return getAllSpacesAdmin();
}

public Set<Sysprop> getAllSpacesAdmin() {
if (allSpaces == null || pc.getCount("scooldspace").intValue() != allSpaces.size()) { // caching issue on >1 nodes
if (Utils.timestamp() - lastSpacesCountTimestamp > TimeUnit.SECONDS.toMillis(30)) {
lastSpacesCountTimestamp = Utils.timestamp();
spacesCount = pc.getCount("scooldspace").intValue();
}
if (allSpaces == null || spacesCount != allSpaces.size()) { // caching issue on >1 nodes
allSpaces = new LinkedHashSet<>(pc.findQuery("scooldspace", "*", new Pager(Config.DEFAULT_LIMIT)));
}
return allSpaces;
return allSpaces.stream().sorted((s1, s2) -> getSpaceName(s1.getName()).compareToIgnoreCase(getSpaceName(s2.getName()))).
collect(Collectors.toCollection(LinkedHashSet::new));
}

public boolean canAccessSpace(Profile authUser, String targetSpaceId) {
Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/templates/people.vm
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@
<div class="input-field" id="spaces-selector">
<select multiple name="selectedSpaces">
<option selected="selected" value="$scooldUtils.getDefaultSpace()">$!lang.get('defaultspace')</option>
#foreach($space in $authUser.allSpaces)
#if(!$scooldUtils.isDefaultSpace($space))
<option value="$space">$!scooldUtils.getSpaceName($space)</option>
#foreach($space in $scooldUtils.allSpacesAdmin)
#if(!$scooldUtils.isDefaultSpace($space.id))
<option value="$space">$!space.name</option>
#end
#end
</select>
Expand Down

0 comments on commit c7163c0

Please sign in to comment.