Skip to content

Commit

Permalink
feat: Include Hidden spaces for Space Template Managers when listing -
Browse files Browse the repository at this point in the history
…MEED-7771 - Meeds-io/MIPs#160 (#4187)

Prior to this change, the spaces listing wasn't proposing the hidden
spaces for Space Template identified Masters. This change will rework
the Space Filtering process to allow including Space Template Managers
when suggesting spaces in spaces list and using `Suggester Vue` reusable
component using a specific filter.
  • Loading branch information
boubaker authored and exo-swf committed Nov 18, 2024
1 parent f63fe97 commit 15cd3a6
Show file tree
Hide file tree
Showing 31 changed files with 1,115 additions and 844 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class SpaceFilter implements Cloneable {

private long templateId;

private List<Long> managingTemplateIds;

private SpaceMembershipStatus status;

private SpaceMembershipStatus extraStatus;
Expand Down Expand Up @@ -106,6 +108,7 @@ public SpaceFilter clone() { // NOSONAR
remoteId,
identityId,
templateId,
managingTemplateIds,
status,
extraStatus,
sorting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,22 @@ default ListAccess<Space> getManagerSpacesByFilter(String username, SpaceFilter
throw new UnsupportedOperationException();
}

/**
* Gets a list access containing all spaces that a user has the "manager" role
* or is a manager switch the associated Space template.
*
* This list access matches with the provided space filter.
*
* @param username The remote user Id.
* @param spaceFilter The space filter.
* @return The list access.
* @LevelAPI Platform
* @since 1.2.0-GA
*/
default ListAccess<Space> getManagerOrManagingSpacesByFilter(String username, SpaceFilter spaceFilter) {
throw new UnsupportedOperationException();
}

/**
* Gets a list access containing all spaces that a user has the "member" role.
*
Expand All @@ -162,6 +178,22 @@ default ListAccess<Space> getMemberSpacesByFilter(String username, SpaceFilter s
throw new UnsupportedOperationException();
}

/**
* Gets a list access containing all spaces that a user has the "member" role
* or is a manager switch the associated Space template.
*
* This list access matches with the provided space filter.
*
* @param username The remote user Id.
* @param spaceFilter The space filter.
* @return The list access.
* @LevelAPI Platform
* @since 1.2.0-GA
*/
default ListAccess<Space> getMemberOrManagingSpacesByFilter(String username, SpaceFilter spaceFilter) {
throw new UnsupportedOperationException();
}

/**
* Gets a list of favorite spaces of a user. This list access matches with the
* provided space filter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
*/
package io.meeds.social.search;

import static org.exoplatform.social.core.jpa.search.SpaceIndexingServiceConnector.TEMPLATE_MANAGER_PATTERN;
import static org.exoplatform.social.core.jpa.search.SpaceIndexingServiceConnector.TEMPLATE_MANAGER_PREFIX;

import java.io.InputStream;
import java.text.Normalizer;
import java.util.ArrayList;
Expand Down Expand Up @@ -386,13 +389,30 @@ private String buildTermQueryStatement(String phrase) {

private String buildPermissionsQuery(SpaceSearchFilter filter) {
String permissionField = getPermissionField(filter);
String username = filter.getUsername();

return PERMISSIONS_QUERY.replace(PERMISSIONS_FIELD_REPLACEMENT,
permissionField == null ? "permissions" : permissionField)
.replace(PERMISSIONS_REPLACEMENT,
permissionField == null ? String.format("[\"all\", \"%s\"]", username) :
String.format("[\"%s\"]", username));
getPermissionFieldValues(permissionField, filter));
}

private String getPermissionFieldValues(String permissionField, SpaceSearchFilter filter) {
String username = filter.getUsername();
if (CollectionUtils.isNotEmpty(filter.getManagingTemplateIds())
&& !username.startsWith(TEMPLATE_MANAGER_PREFIX)) {

String managingTemplatePermissions = StringUtils.join(filter.getManagingTemplateIds()
.stream()
.map(id -> String.format(TEMPLATE_MANAGER_PATTERN, id))
.toList(),
"\",\"");

return permissionField == null ? String.format("[\"all\", \"%s\", \"%s\"]", username, managingTemplatePermissions) :
String.format("[\"%s\", \"%s\"]", username, managingTemplatePermissions);
} else {
return permissionField == null ? String.format("[\"all\", \"%s\"]", username) :
String.format("[\"%s\"]", username);
}
}

private String buildTemplateIdQueryStatement(SpaceSearchFilter filter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class SpaceSearchFilter {

private long templateId;

private List<Long> managingTemplateIds;

private String term;

private boolean favorites;
Expand Down
Loading

0 comments on commit 15cd3a6

Please sign in to comment.