Skip to content

Commit acb12ee

Browse files
committed
fix: Checking subspace creation when not members of Parent Space - Meeds-io/MIPs#227
Prior to this change, the parent space creation check was made using 'isMember' instead of '!isMember'
1 parent 76d9d44 commit acb12ee

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

component/core/src/main/java/io/meeds/social/space/service/SpaceServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ private void checkSubspaceCreationAllowed(Space space, long parentSpaceId, Strin
14141414
return;
14151415
}
14161416
Space parentSpace = getSpaceById(parentSpaceId);
1417-
if (isMember(parentSpace, username)) {
1417+
if (!isMember(parentSpace, username)) {
14181418
throw new SpaceException(Code.SPACE_PERMISSION,
14191419
String.format("User %s isn't allowed to create subspace under parent space with id %s",
14201420
username,

component/core/src/test/java/org/exoplatform/social/core/space/spi/SpaceServiceTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,14 +2607,15 @@ public void testCreateSubspace() {
26072607
space2.setPrettyName("spaceChild");
26082608
space2.setRegistration(Space.OPEN);
26092609
space2.setDescription("description of space spaceChild");
2610-
space2.setTemplateId(2);
2610+
space2.setTemplateId(2l);
26112611
space2.setVisibility(Space.PRIVATE);
26122612

2613-
String parentSpaceId = space.getId();
2613+
long parentSpaceId = space.getSpaceId();
26142614
Exception exception = assertThrows(SpaceException.class,
2615-
() -> spaceService.createSpace(space2, ROOT_NAME, null, Long.parseLong(parentSpaceId)));
2615+
() -> spaceService.createSpace(space2, ROOT_NAME, null, parentSpaceId));
26162616

2617-
assertEquals("User root isn't allowed to create subspace under parent space with id " + parentSpaceId,
2617+
assertEquals("Subspace template '%s' is not allowed under parent template '%s'".formatted(space2.getTemplateId(),
2618+
2l),
26182619
exception.getMessage());
26192620
}
26202621

0 commit comments

Comments
 (0)