Skip to content

Commit

Permalink
Merge Spaces Management - Meeds-io/MIPs#160 (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
boubaker authored Nov 18, 2024
2 parents 0b135db + d72d6f1 commit 3205ff7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static String getUserFullName(String userName) throws Exception {
return user.getFullName();
}

public static String getNotificationActivityLink(Space space, String activityId, boolean isMember) {
public static String getNotificationActivityLink(Space space, String activityId, boolean canView) {
String activityLink = "";
if (isMember) {
if (canView) {
activityLink = getActivityPermalink(activityId);
} else {
activityLink = getNotificationActivityLinkForNotSpaceMembers(space);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public ResponseEntity<NewsEntity> getNews(@Parameter(description = "News author"
for (String spaceId : spaces.split(",")) {
Space space = spaceService.getSpaceById(spaceId);
if (space == null
|| (!spaceService.isSuperManager(authenticatedUser) && !spaceService.isMember(space, authenticatedUser))) {
|| (!spaceService.isSuperManager(space, authenticatedUser) && !spaceService.isMember(space, authenticatedUser))) {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).build();
}
spacesList.add(spaceId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,16 @@ public boolean canViewNews(News news, String authenticatedUser) {
if (space == null) {
LOG.warn("Can't find space with id {} when checking access on news with id {}", spaceId, news.getId());
return false;
} else if (spaceService.isSuperManager(space, authenticatedUser)) {
return true;
}
if (!news.isPublished() && StringUtils.equals(news.getPublicationState(), POSTED)
&& !(spaceService.isSuperManager(authenticatedUser) || spaceService.isMember(space, authenticatedUser)
|| isMemberOfsharedInSpaces(news, authenticatedUser))) {
&& !(spaceService.canViewSpace(space, authenticatedUser) || canViewSharedInSpaces(news, authenticatedUser))) {
return false;
}
if (news.isPublished() && StringUtils.equals(news.getPublicationState(), POSTED)
&& NewsUtils.SPACE_NEWS_AUDIENCE.equals(news.getAudience())
&& !(spaceService.isMember(space, authenticatedUser) || isMemberOfsharedInSpaces(news, authenticatedUser))) {
&& !(spaceService.canViewSpace(space, authenticatedUser) || canViewSharedInSpaces(news, authenticatedUser))) {
return false;
}
if (StringUtils.equals(news.getPublicationState(), STAGED)
Expand Down Expand Up @@ -1228,10 +1229,9 @@ private News buildDraftArticle(String draftArticleId, String currentUserId) thro
draftArticle.setSpaceAvatarUrl(draftArticleSpace.getAvatarUrl());
draftArticle.setSpaceDisplayName(draftArticleSpace.getDisplayName());
boolean hiddenSpace = draftArticleSpace.getVisibility().equals(Space.HIDDEN)
&& !spaceService.isMember(draftArticleSpace, currentUserId) && !spaceService.isSuperManager(currentUserId);
&& !spaceService.canViewSpace(draftArticleSpace, currentUserId);
draftArticle.setHiddenSpace(hiddenSpace);
boolean isSpaceMember =
spaceService.isSuperManager(currentUserId) || spaceService.isMember(draftArticleSpace, currentUserId);
boolean isSpaceMember = spaceService.canViewSpace(draftArticleSpace, currentUserId);
draftArticle.setSpaceMember(isSpaceMember);
if (StringUtils.isNotEmpty(draftArticleSpace.getGroupId())) {
draftArticle.setSpaceUrl(NewsUtils.buildSpaceUrl(draftArticleSpace.getId()));
Expand Down Expand Up @@ -1293,7 +1293,7 @@ private void buildArticleProperties(News article, String currentUsername, Metada
sharedInSpacesList.add(sharedInSpaceId);
Space sharedInSpace = spaceService.getSpaceById(sharedInSpaceId);
String activityId = activities[i].split(":")[1];
if (sharedInSpace != null && currentUsername != null && spaceService.isMember(sharedInSpace, currentUsername)
if (sharedInSpace != null && currentUsername != null && spaceService.canViewSpace(sharedInSpace, currentUsername)
&& activityManager.isActivityExists(activityId)) {
memberSpaceActivities.append(activities[i]).append(";");
}
Expand Down Expand Up @@ -1525,10 +1525,10 @@ private boolean canDeleteNews(Identity currentIdentity, String posterId, String
return spaceService.canRedactOnSpace(space, currentIdentity);
}

private boolean isMemberOfsharedInSpaces(News news, String username) {
private boolean canViewSharedInSpaces(News news, String username) {
for (String sharedInSpaceId : news.getSharedInSpacesList()) {
Space sharedInSpace = spaceService.getSpaceById(sharedInSpaceId);
if (sharedInSpace != null && spaceService.isMember(sharedInSpace, username)) {
if (sharedInSpace != null && spaceService.canViewSpace(sharedInSpace, username)) {
return true;
}
}
Expand Down Expand Up @@ -1582,13 +1582,13 @@ private void sendNotification(String currentUserId,
String contentSpaceId = lastSpaceIdActivityId.split(":")[0];
String contentActivityId = lastSpaceIdActivityId.split(":")[1];
Space contentSpace = spaceService.getSpaceById(contentSpaceId);
boolean isMember = spaceService.isMember(contentSpace, contentAuthor);
boolean canView = spaceService.canViewSpace(contentSpace, contentAuthor);
if (contentSpace == null) {
throw new NullPointerException("Cannot find a space with id " + contentSpaceId + ", it may not exist");
}
org.exoplatform.social.core.identity.model.Identity identity = identityManager.getOrCreateUserIdentity(contentAuthor);
String authorAvatarUrl = LinkProviderUtils.getUserAvatarUrl(identity.getProfile());
String activityLink = NotificationUtils.getNotificationActivityLink(contentSpace, contentActivityId, isMember);
String activityLink = NotificationUtils.getNotificationActivityLink(contentSpace, contentActivityId, canView);
String contentSpaceName = contentSpace.getDisplayName();

// Send Notification
Expand Down Expand Up @@ -1875,10 +1875,9 @@ private News buildArticle(String newsId, String lang, boolean fetchOriginal) thr
news.setSpaceId(space.getId());
news.setSpaceAvatarUrl(space.getAvatarUrl());
news.setSpaceDisplayName(space.getDisplayName());
boolean hiddenSpace = space.getVisibility().equals(Space.HIDDEN) && !spaceService.isMember(space, currentUsername)
&& !spaceService.isSuperManager(currentUsername);
boolean hiddenSpace = space.getVisibility().equals(Space.HIDDEN) && !spaceService.canViewSpace(space, currentUsername);
news.setHiddenSpace(hiddenSpace);
boolean isSpaceMember = spaceService.isSuperManager(currentUsername) || spaceService.isMember(space, currentUsername);
boolean isSpaceMember = spaceService.canViewSpace(space, currentUsername);
news.setSpaceMember(isSpaceMember);
if (StringUtils.isNotEmpty(space.getGroupId())) {
news.setSpaceUrl(NewsUtils.buildSpaceUrl(space.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static boolean canPublishNews(String spaceId, org.exoplatform.services.se
&& (currentIdentity.isMemberOf(PLATFORM_WEB_CONTRIBUTORS_GROUP, PUBLISHER_MEMBERSHIP_NAME)
|| spaceService.isPublisher(space, currentIdentity.getUserId())
|| spaceService.isManager(space, currentIdentity.getUserId())
|| spaceService.isSuperManager(currentIdentity.getUserId()));
|| spaceService.isSuperManager(space, currentIdentity.getUserId()));
}
return currentIdentity != null && currentIdentity.isMemberOf(PLATFORM_WEB_CONTRIBUTORS_GROUP, PUBLISHER_MEMBERSHIP_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ public void shouldDeleteNewsWhenNewsExists() throws Exception {
space1.setPrettyName("space1");
lenient().when(spaceService.getSpaceById(anyString())).thenReturn(space1);
lenient().when(spaceService.isMember(any(Space.class), eq(JOHN))).thenReturn(true);
lenient().when(spaceService.isSuperManager(eq(JOHN))).thenReturn(true);
lenient().when(spaceService.isSuperManager(JOHN)).thenReturn(true);

// When
Response response = newsRestController.deleteNews("1", ARTICLE.name().toLowerCase(), 0L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void testCanPublishNews() {
assertTrue(NewsUtils.canPublishNews(space.getId(), userAclIdentity));
when(spaceService.isManager(space, userAclIdentity.getUserId())).thenReturn(false);

when(spaceService.isSuperManager(userAclIdentity.getUserId())).thenReturn(true);
when(spaceService.isSuperManager(space, userAclIdentity.getUserId())).thenReturn(true);
assertTrue(NewsUtils.canPublishNews(space.getId(), userAclIdentity));
}

Expand Down

0 comments on commit 3205ff7

Please sign in to comment.