use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigration method upgradeRegularSubwiki.
private void upgradeRegularSubwiki(String wikiId) throws DataMigrationException, XWikiException {
// Create the new configuration
WikiUserConfiguration configuration = new WikiUserConfiguration();
configuration.setUserScope(UserScope.LOCAL_AND_GLOBAL);
configuration.setMembershipType(MembershipType.INVITE);
// Save the new configuration
saveConfiguration(configuration, wikiId);
}
use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.
the class WikiUserFromXEMMigrationTest method upgradeWorkspace.
@Test
public void upgradeWorkspace() throws Exception {
// Mocks about the descriptor
when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspace");
XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspace")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
// Mocks about the old workspace object
BaseObject oldObject = mock(BaseObject.class);
when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass")))).thenReturn(oldObject);
when(oldObject.getStringValue("membershipType")).thenReturn("request");
// Mocks about candidacies
DocumentReference memberGroupRef = new DocumentReference("workspace", XWiki.SYSTEM_SPACE, "XWikiAllGroup");
XWikiDocument memberGroupDoc = mock(XWikiDocument.class);
when(xwiki.getDocument(eq(memberGroupRef), any(XWikiContext.class))).thenReturn(memberGroupDoc);
DocumentReference candidacyOldClass = new DocumentReference("workspace", "XWiki", "WorkspaceCandidateMemberClass");
List<BaseObject> oldCandidacies = new ArrayList<>();
BaseObject oldCandidacy = mock(BaseObject.class);
oldCandidacies.add(oldCandidacy);
when(memberGroupDoc.getXObjects(eq(candidacyOldClass))).thenReturn(oldCandidacies);
LocalDocumentReference newCandidacyClassRef = WikiCandidateMemberClassInitializer.REFERENCE;
BaseObject newCandidacyObject = mock(BaseObject.class);
when(memberGroupDoc.newXObject(eq(newCandidacyClassRef), any(XWikiContext.class))).thenReturn(newCandidacyObject);
when(oldCandidacy.getStringValue("type")).thenReturn("aa");
when(oldCandidacy.getStringValue("status")).thenReturn("bb");
when(oldCandidacy.getStringValue("userName")).thenReturn("cc");
when(oldCandidacy.getLargeStringValue("userComment")).thenReturn("dd");
when(oldCandidacy.getStringValue("reviewer")).thenReturn("ee");
when(oldCandidacy.getLargeStringValue("reviewerComment")).thenReturn("ff");
when(oldCandidacy.getLargeStringValue("reviewerPrivateComment")).thenReturn("gg");
when(oldCandidacy.getDateValue("date")).thenReturn(new Date(2000));
when(oldCandidacy.getDateValue("resolutionDate")).thenReturn(new Date(8000));
// Run
mocker.getComponentUnderTest().hibernateMigrate();
// Verify the user configuration is accurate
WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration();
expectedConfiguration.setUserScope(UserScope.GLOBAL_ONLY);
expectedConfiguration.setMembershipType(MembershipType.REQUEST);
verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("workspace"));
// Verify the old workspace object has been removed and the descriptor saved
verify(oldDescriptorDocument).removeXObject(oldObject);
verify(xwiki, times(1)).saveDocument(oldDescriptorDocument, "[UPGRADE] Remove the old WorkspaceManager.WorkspaceClass" + " object.", xcontext);
// Verify the candidacy has been upgraded
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, "aa");
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, "bb");
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, "cc");
verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, "dd");
verify(newCandidacyObject).setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, "ee");
verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, "ff");
verify(newCandidacyObject).setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT, "gg");
verify(newCandidacyObject).setDateValue(eq(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION), eq(new Date(2000)));
verify(newCandidacyObject).setDateValue(eq(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE), eq(new Date(8000)));
// Verify the old candidacy has been removed and the document saved
verify(memberGroupDoc).removeXObject(oldCandidacy);
verify(xwiki, times(1)).saveDocument(memberGroupDoc, "Upgrade candidacies from the old Workspace Application" + " to the new Wiki Application.", xcontext);
}
use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method setMembershipType.
@Override
public void setMembershipType(String wikiId, MembershipType type) throws WikiUserManagerException {
WikiUserConfiguration configuration = wikiUserConfigurationHelper.getConfiguration(wikiId);
configuration.setMembershipType(type);
wikiUserConfigurationHelper.saveConfiguration(configuration, wikiId);
}
Aggregations