Skip to content

Commit

Permalink
fix: Fix Display Last Accessed Space - Meeds-io/MIPs#160
Browse files Browse the repository at this point in the history
Prior to this change, the last accessed space wasn't displayed for the space template masters. This change will fix the Space LAst Access Listing.
  • Loading branch information
boubaker authored and exo-swf committed Nov 18, 2024
1 parent 05b5b63 commit 0fb2f64
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ public ListAccess<Space> getLastAccessedSpace(String username) {
}
return new SpaceListAccess(spaceStorage,
spaceSearchConnector,
getSpaceTemplateService(),
username,
SpaceListAccessType.LASTEST_ACCESSED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.exoplatform.social.core.jpa.storage.entity.SpaceEntity;
import org.exoplatform.social.core.search.Sorting;
import org.exoplatform.social.core.search.Sorting.SortBy;
import org.exoplatform.social.core.space.SpaceFilter;
import org.exoplatform.social.core.space.model.Space;

import io.meeds.social.space.constant.SpaceMembershipStatus;
Expand Down Expand Up @@ -279,13 +278,13 @@ private String getQueryFilterName(List<String> suffixes, boolean count) {
return queryName;
}

private String getQueryFilterContent(SpaceFilter spaceFilter,
private String getQueryFilterContent(XSpaceFilter spaceFilter,
List<String> predicates,
List<String> parameterNames,
boolean count) {
String querySelect = count ? "SELECT COUNT(DISTINCT s.id) FROM SocSpaceEntity s " :
"SELECT DISTINCT(s.id, " + getSortField(spaceFilter.getSorting()) + ") FROM SocSpaceEntity s ";
if (parameterNames.contains(PARAM_USER_ID)) {
"SELECT DISTINCT(s.id, " + getSortField(spaceFilter) + ") FROM SocSpaceEntity s ";
if (parameterNames.contains(PARAM_USER_ID) || spaceFilter.isLastAccess()) {
querySelect += " INNER JOIN s.members sm ";
}

Expand All @@ -296,8 +295,8 @@ private String getQueryFilterContent(SpaceFilter spaceFilter,
queryContent = querySelect + " WHERE " + StringUtils.join(predicates, " AND ");
}
if (!count) {
queryContent += " ORDER BY " + getSortField(spaceFilter.getSorting()) +
(spaceFilter.getSorting().orderBy.equals(Sorting.OrderBy.DESC) ? " DESC " : " ASC ");
queryContent += " ORDER BY " + getSortField(spaceFilter) +
(spaceFilter.isLastAccess() || spaceFilter.getSorting().orderBy.equals(Sorting.OrderBy.DESC) ? " DESC " : " ASC ");
}
return queryContent;
}
Expand Down Expand Up @@ -414,18 +413,21 @@ private void buildPermissionPredicates(XSpaceFilter spaceFilter, // NOSONAR

private void buildSortSuffixes(XSpaceFilter spaceFilter, List<String> suffixes) {
Sorting sorting = spaceFilter.getSorting();
String sortField = getSortField(spaceFilter.getSorting());
String sortField = getSortField(spaceFilter);
suffixes.add("OrderBy");
suffixes.add(StringUtils.capitalize(sortField.replace("s.", "")));
suffixes.add(StringUtils.capitalize(sortField.replace("s.", "").replace("sm.", "")));
if (sorting.orderBy.equals(Sorting.OrderBy.DESC)) {
suffixes.add("DESC");
} else {
suffixes.add("ASC");
}
}

private String getSortField(Sorting sorting) {
if (sorting.sortBy.equals(SortBy.DATE)) {
private String getSortField(XSpaceFilter spaceFilter) {
Sorting sorting = spaceFilter.getSorting();
if (spaceFilter.isLastAccess()) {
return "sm.lastAccess";
} else if (sorting.sortBy.equals(SortBy.DATE)) {
return "s.createdDate";
} else {
return "s.displayName";
Expand Down

0 comments on commit 0fb2f64

Please sign in to comment.