Skip to content
Snippets Groups Projects
Commit 2cd9dfcb authored by Clemens Robbenhaar's avatar Clemens Robbenhaar
Browse files

XWIKI-19119: Rights for a group are not updated in subwikis after rename of the group

- first part of a fix: try to find groups both by relative and absolute
  name when trying to rename
parent 41fd405b
Branches XWIKI-19119
No related tags found
No related merge requests found
......@@ -148,6 +148,9 @@ public final class RightsManager
private EntityReferenceSerializer<String> compactWikiEntityReferenceSerializer =
Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "compactwiki");
private EntityReferenceSerializer<String> absoluteEntityReferenceSerializer =
Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "default");
private EntityReferenceSerializer<String> localEntityReferenceSerializer =
Utils.getComponent(EntityReferenceSerializer.TYPE_STRING, "local");
......@@ -1086,9 +1089,12 @@ private boolean replaceUserOrGroupFromRight(BaseObject right, DocumentReference
ListClass.getListFromString(right.getLargeStringValue(userOrGroupField), USERGROUPLISTFIELD_SEP, false);
String userOrGroupSource = this.compactWikiEntityReferenceSerializer.serialize(userOrGroupSourceReference);
String aboluteUserOrGroupSource = this.absoluteEntityReferenceSerializer.serialize(userOrGroupSourceReference);
String userOrGroupTarget = this.compactWikiEntityReferenceSerializer.serialize(userOrGroupTargetReference);
if (usersOrGroups.remove(userOrGroupSource)) {
boolean isRelativeReferencePresent = usersOrGroups.remove(userOrGroupSource);
boolean isAbsoluteReferencePresent = usersOrGroups.remove(aboluteUserOrGroupSource);
if (isRelativeReferencePresent || isAbsoluteReferencePresent) {
usersOrGroups.add(userOrGroupTarget);
needUpdate = true;
}
......
......@@ -23,10 +23,12 @@
import java.util.Collections;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.xwiki.model.reference.DocumentReference;
import org.xwiki.test.annotation.AllComponents;
import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.doc.XWikiDocument;
import com.xpn.xwiki.objects.BaseObject;
import com.xpn.xwiki.test.MockitoOldcore;
......@@ -96,6 +98,50 @@ void replaceUserOrGroupFromAllRights() throws Exception
assertEquals(expectedValue, updatedRightsObject.getLargeStringValue("groups"));
}
@Test
void replaceUserOrGroupFromAllRightsWithAbsoluteReferences() throws Exception
{
DocumentReference oldGroupName = new DocumentReference("xwiki", "XWiki", "GroupBefore");
DocumentReference newGroupName = new DocumentReference("xwiki", "XWiki", "GroupAfter");
String oldValue = "xwiki:XWiki.GroupBefore,subwiki:XWiki.Some\\,OtherGroup,XWiki.GroupBefore";
String expectedValue = "subwiki:XWiki.Some\\,OtherGroup,XWiki.GroupAfter";
XWikiDocument rightsDocument = loadTestDocumentFromStore();
BaseObject rightsObject = rightsDocument.getXObject(MockitoOldcore.GLOBAL_RIGHTS_CLASS);
rightsObject.setLargeStringValue("groups", oldValue);
oldcore.getSpyXWiki().saveDocument(rightsDocument, oldcore.getXWikiContext());
rights.replaceUserOrGroupFromAllRights(oldGroupName, newGroupName, false, oldcore.getXWikiContext());
BaseObject updatedRightsObject = loadTestDocumentFromStore().getXObject(MockitoOldcore.GLOBAL_RIGHTS_CLASS);
assertEquals(expectedValue, updatedRightsObject.getLargeStringValue("groups"));
}
@Test
@Disabled("this does not work yet; the code renames the local group with the same name as the global group, too")
void replaceUserOrGroupFromAllRightsInSubWiki() throws Exception
{
DocumentReference oldGroupName = new DocumentReference("xwiki", "XWiki", "GroupBefore");
DocumentReference newGroupName = new DocumentReference("subwiki", "XWiki", "GroupAfter");
String oldValue = "xwiki:XWiki.GroupBefore,subwiki:XWiki.Some\\,OtherGroup,XWiki.GroupBefore";
String expectedValue = "subwiki:XWiki.Some\\,OtherGroup,subwiki:XWiki.GroupAfter,XWiki.GroupBefore";
XWikiContext context = oldcore.getXWikiContext();
context.setWikiId("subwiki");
XWikiDocument rightsDocument = loadTestDocumentFromStore();
BaseObject rightsObject = rightsDocument.getXObject(MockitoOldcore.GLOBAL_RIGHTS_CLASS);
rightsObject.setLargeStringValue("groups", oldValue);
oldcore.getSpyXWiki().saveDocument(rightsDocument, oldcore.getXWikiContext());
rights.replaceUserOrGroupFromAllRights(oldGroupName, newGroupName, false, oldcore.getXWikiContext());
BaseObject updatedRightsObject = loadTestDocumentFromStore().getXObject(MockitoOldcore.GLOBAL_RIGHTS_CLASS);
assertEquals(expectedValue, updatedRightsObject.getLargeStringValue("groups"));
}
@Test
void removeUserOrGroupFromAllRights() throws Exception
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment