Skip to content

Commit

Permalink
feat: Display Empty Spaces List when no access permission to filtered…
Browse files Browse the repository at this point in the history
… categories - MEED-8053 - Meeds-io/meeds#2726

This change will avoid listing spaces of user when the Spaces Directory Application filters applies a category which isn't accessible. Thus, the spaces Directory will simply display a placeholder when no access to filtered categories.
  • Loading branch information
boubaker committed Jan 10, 2025
1 parent 09c76f3 commit 2dd5e34
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class SpaceFilter implements Cloneable {

private List<Long> categoryIds;

public List<Long> getCategoryIds() {
return categoryIds;
}
private List<Long> managingTemplateIds;

private SpaceMembershipStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.LocaleUtils;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -94,6 +95,7 @@

import io.meeds.portal.security.constant.UserRegistrationType;
import io.meeds.portal.security.service.SecuritySettingService;
import io.meeds.social.category.service.CategoryService;
import io.meeds.social.space.constant.SpaceRegistration;
import io.meeds.social.space.constant.SpaceVisibility;
import io.meeds.social.space.service.SpaceLayoutService;
Expand Down Expand Up @@ -155,6 +157,8 @@ public class SpaceRest implements ResourceContainer {

private final SpaceService spaceService;

private final CategoryService categoryService;

private final SpaceLayoutService spaceLayoutService;

private final SecuritySettingService securitySettingService;
Expand All @@ -167,12 +171,14 @@ public class SpaceRest implements ResourceContainer {

public SpaceRest(SpaceService spaceService,
SpaceLayoutService spaceLayoutService,
CategoryService categoryService,
IdentityManager identityManager,
UploadService uploadService,
ImageThumbnailService imageThumbnailService,
SecuritySettingService securitySettingService) {
this.spaceService = spaceService;
this.spaceLayoutService = spaceLayoutService;
this.categoryService = categoryService;
this.identityManager = identityManager;
this.uploadService = uploadService;
this.imageThumbnailService = imageThumbnailService;
Expand Down Expand Up @@ -270,7 +276,19 @@ public Response getSpaces( // NOSONAR
spaceFilter.setTagNames(tagNames);
spaceFilter.setTemplateIds(templateIds);
spaceFilter.setExcludedIds(excludedIds);
spaceFilter.setCategoryIds(categoryIds);
if (CollectionUtils.isNotEmpty(categoryIds)) {
spaceFilter.setCategoryIds(categoryIds.stream()
.filter(id -> categoryService.canAccess(id, authenticatedUser))
.toList());
if (CollectionUtils.isEmpty(spaceFilter.getCategoryIds())) {
CollectionEntity collectionSpace = new CollectionEntity(Collections.emptyList(),
EntityBuilder.SPACES_TYPE,
offset,
limit);
return EntityBuilder.getResponseBuilder(collectionSpace, uriInfo, RestUtils.getJsonMediaType(), Response.Status.OK)
.build();
}
}
spaceFilter.setRegistration(registration);
spaceFilter.setVisibility(visibility);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@
import org.exoplatform.upload.UploadService;

import io.meeds.portal.security.service.SecuritySettingService;
import io.meeds.social.category.service.CategoryService;
import io.meeds.social.space.service.SpaceLayoutService;

public class SpaceRestResourcesTest extends AbstractResourceTest {
private IdentityManager identityManager;

private OrganizationService organizationService;

private UserACL userACL;

private ActivityManager activityManager;

private SpaceService spaceService;
Expand Down Expand Up @@ -81,6 +79,7 @@ public void setUp() throws Exception {
identityManager = getContainer().getComponentInstanceOfType(IdentityManager.class);
activityManager = getContainer().getComponentInstanceOfType(ActivityManager.class);
spaceService = getContainer().getComponentInstanceOfType(SpaceService.class);
CategoryService categoryService = getContainer().getComponentInstanceOfType(CategoryService.class);
organizationService = getContainer().getComponentInstanceOfType(OrganizationService.class);
uploadService = (MockUploadService) getContainer().getComponentInstanceOfType(UploadService.class);
imageThumbnailService = getContainer().getComponentInstanceOfType(ImageThumbnailService.class);
Expand All @@ -94,6 +93,7 @@ public void setUp() throws Exception {

spaceRestResources = new SpaceRest(spaceService,
spaceLayoutService,
categoryService,
identityManager,
uploadService,
imageThumbnailService,
Expand Down

0 comments on commit 2dd5e34

Please sign in to comment.