Skip to content

Commit

Permalink
Bug #14015: Fixing administration services about spaces managed by a …
Browse files Browse the repository at this point in the history
…user or by a group.
  • Loading branch information
SilverYoCha authored and mmoqui committed Feb 21, 2024
1 parent dec9721 commit a83565c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -934,15 +934,23 @@ List<ComponentInstLight> getAvailCompoInSpace(String userId, String spaceId)
SpaceInstLight getRootSpace(String spaceId) throws AdminException;

/**
* Get the spaces ids manageable by given group id
* Get all the spaces ids manageable by given group id.
* <p>
* It means the direct space ids the group is indicated to and all the sub spaces ids by
* inheritance.
* </p>
* @param sGroupId the unique identifier of a group
* @return an array of space identifiers.
* @throws AdminException if an error occurs
*/
String[] getGroupManageableSpaceIds(String sGroupId) throws AdminException;

/**
* Get the spaces ids manageable by given user id
* Get all the spaces ids manageable by given user id.
* <p>
* It means the direct space ids the user is indicated to and all the sub spaces ids by
* inheritance.
* </p>
* @param sUserId the unique identifier of a user
* @return an array of space identifiers
* @throws AdminException if an error occurs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3344,37 +3344,23 @@ public SpaceInstLight getRootSpace(String spaceId) throws AdminException {

@Override
public String[] getGroupManageableSpaceIds(String sGroupId) throws AdminException {
String[] asManageableSpaceIds;
ArrayList<String> alManageableSpaceIds = new ArrayList<>();
try {
// Get user manageable space ids from database
List<String> groupIds = new ArrayList<>();
groupIds.add(sGroupId);
List<Integer> manageableSpaceIds = spaceManager.getManageableSpaceIds(null, groupIds);

// Inherits manageability rights for space children
String[] childSpaceIds;
for (Integer spaceId : manageableSpaceIds) {
String asManageableSpaceId = String.valueOf(spaceId);
// add manageable space id in result
if (!alManageableSpaceIds.contains(asManageableSpaceId)) {
alManageableSpaceIds.add(asManageableSpaceId);
}

// calculate manageable space's children
childSpaceIds = spaceManager.getAllSubSpaceIds(spaceId);
// add them in result
for (String childSpaceId : childSpaceIds) {
if (!alManageableSpaceIds.contains(childSpaceId)) {
alManageableSpaceIds.add(childSpaceId);
}
}
}

// Put user manageable space ids in cache
asManageableSpaceIds = alManageableSpaceIds.toArray(new String[0]);

return asManageableSpaceIds;
final List<String> groupIds = List.of(sGroupId);
// Get space ids on which the group is specifically indicated as manager
final List<Integer> directSpaceIds = spaceManager.getManageableSpaceIds(null, groupIds);
final List<SpaceInst> consumer = new ArrayList<>();
for (Integer directSpaceId : directSpaceIds) {
consumer.add(getSpaceInstById(String.valueOf(directSpaceId)));
}
// Identifying all managed space ids
final Set<String> allSpaces = new LinkedHashSet<>();
while (!consumer.isEmpty()) {
final SpaceInst current = consumer.remove(0);
allSpaces.add(String.valueOf(current.getLocalId()));
current.getSubSpaces().forEach(s -> consumer.add(0, s));
}
return allSpaces.toArray(new String[0]);
} catch (Exception e) {
throw new AdminException(failureOnGetting("spaces manageable by group", sGroupId), e);
}
Expand All @@ -3389,17 +3375,17 @@ public String[] getUserManageableSpaceIds(String sUserId) throws AdminException
if (cachedSpaceIds.isEmpty()) {
final List<String> groupIds = getAllGroupsOfUser(sUserId);
// Get space ids on which the user is specifically indicated as manager
final Integer[] directSpacedIds = userManager.getManageableSpaceIds(sUserId, groupIds);
final Integer[] directSpaceIds = userManager.getManageableSpaceIds(sUserId, groupIds);
final List<SpaceInst> consumer = new ArrayList<>();
for (Integer directSpaceId : directSpacedIds) {
for (Integer directSpaceId : directSpaceIds) {
consumer.add(getSpaceInstById(String.valueOf(directSpaceId)));
}
// Identifying all managed space ids
final Set<String> allSpaces = new HashSet<>();
final Set<String> allSpaces = new LinkedHashSet<>();
while (!consumer.isEmpty()) {
final SpaceInst current = consumer.remove(0);
allSpaces.add(String.valueOf(current.getLocalId()));
consumer.addAll(current.getSubSpaces());
current.getSubSpaces().forEach(s -> consumer.add(0, s));
}
result = allSpaces.toArray(new String[0]);
cache.putManageableSpaceIds(sUserId, result);
Expand Down

0 comments on commit a83565c

Please sign in to comment.