Search in sources :

Example 6 with WikiUserConfiguration

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);
}
Also used : WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration)

Example 7 with WikiUserConfiguration

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);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration) ArrayList(java.util.ArrayList) XWikiContext(com.xpn.xwiki.XWikiContext) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Date(java.util.Date) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 8 with WikiUserConfiguration

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);
}
Also used : WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration)

Aggregations

WikiUserConfiguration (org.xwiki.wiki.user.WikiUserConfiguration)8 XWikiContext (com.xpn.xwiki.XWikiContext)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)4 Test (org.junit.Test)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)3 XWikiException (com.xpn.xwiki.XWikiException)2 BaseObject (com.xpn.xwiki.objects.BaseObject)2 MembershipType (org.xwiki.wiki.user.MembershipType)2 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)2 XWiki (com.xpn.xwiki.XWiki)1 DataMigrationException (com.xpn.xwiki.store.migration.DataMigrationException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 UserScope (org.xwiki.wiki.user.UserScope)1