Search in sources :

Example 1 with WikiUserConfiguration

use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.

the class DefaultWikiUserManager method setUserScope.

@Override
public void setUserScope(String wikiId, UserScope scope) throws WikiUserManagerException {
    WikiUserConfiguration configuration = wikiUserConfigurationHelper.getConfiguration(wikiId);
    configuration.setUserScope(scope);
    wikiUserConfigurationHelper.saveConfiguration(configuration, wikiId);
}
Also used : WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration)

Example 2 with WikiUserConfiguration

use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.

the class WikiUserFromXEMMigration method upgradeWorkspaceConfiguration.

/**
 * Convert the old WorkspaceManager.WorkspaceClass objects to the new configuration format.
 *
 * @param oldObject old workspace object
 * @param wikiId id of the wiki to upgrade
 * @param oldWikiDescriptor document that holds the old object
 * @throws DataMigrationException if problems occur
 * @throws XWikiException if problems occur
 */
private void upgradeWorkspaceConfiguration(BaseObject oldObject, String wikiId, XWikiDocument oldWikiDescriptor) throws DataMigrationException, XWikiException {
    // Context, XWiki
    XWikiContext context = getXWikiContext();
    XWiki xwiki = context.getWiki();
    // Create the new configuration
    WikiUserConfiguration configuration = new WikiUserConfiguration();
    // No local users
    configuration.setUserScope(UserScope.GLOBAL_ONLY);
    // Set the membershipType value
    if (oldObject != null) {
        // Get the membershipType value
        String membershipTypeValue = oldObject.getStringValue("membershipType");
        MembershipType membershipType;
        try {
            membershipType = MembershipType.valueOf(membershipTypeValue.toUpperCase());
        } catch (Exception e) {
            // Default value
            membershipType = MembershipType.INVITE;
        }
        configuration.setMembershipType(membershipType);
    } else {
        // If there is no workspace object, we put a default value.
        configuration.setMembershipType(MembershipType.INVITE);
    }
    // Save the new configuration
    saveConfiguration(configuration, wikiId);
}
Also used : WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration) MembershipType(org.xwiki.wiki.user.MembershipType) XWikiContext(com.xpn.xwiki.XWikiContext) XWiki(com.xpn.xwiki.XWiki) XWikiException(com.xpn.xwiki.XWikiException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) DataMigrationException(com.xpn.xwiki.store.migration.DataMigrationException)

Example 3 with WikiUserConfiguration

use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.

the class WikiUserFromXEMMigrationTest method upgradeRegularSubWiki.

@Test
public void upgradeRegularSubWiki() throws Exception {
    // Mocks
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
    XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
    when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerSubwiki")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
    when(oldDescriptorDocument.getXObject(eq(new DocumentReference("mainWiki", "WorkspaceManager", "WorkspaceClass")))).thenReturn(null);
    // Run
    mocker.getComponentUnderTest().hibernateMigrate();
    // Verify
    WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration();
    expectedConfiguration.setUserScope(UserScope.LOCAL_AND_GLOBAL);
    expectedConfiguration.setMembershipType(MembershipType.INVITE);
    verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("subwiki"));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration) XWikiContext(com.xpn.xwiki.XWikiContext) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 4 with WikiUserConfiguration

use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.

the class WikiUserFromXEMMigrationTest method upgradeOldWorkspaceTemplate.

@Test
public void upgradeOldWorkspaceTemplate() throws Exception {
    // Mocks about the descriptor
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("workspacetemplate");
    XWikiDocument oldDescriptorDocument = mock(XWikiDocument.class);
    when(xwiki.getDocument(eq(new DocumentReference("mainWiki", XWiki.SYSTEM_SPACE, "XWikiServerWorkspacetemplate")), any(XWikiContext.class))).thenReturn(oldDescriptorDocument);
    // Mock about the workspace special page
    when(xwiki.exists(eq(new DocumentReference("workspacetemplate", "XWiki", "ManageWorkspace")), any(XWikiContext.class))).thenReturn(true);
    // Mocks about candidacies
    DocumentReference memberGroupRef = new DocumentReference("workspacetemplate", XWiki.SYSTEM_SPACE, "XWikiAllGroup");
    XWikiDocument memberGroupDoc = mock(XWikiDocument.class);
    when(xwiki.getDocument(eq(memberGroupRef), any(XWikiContext.class))).thenReturn(memberGroupDoc);
    // Run
    mocker.getComponentUnderTest().hibernateMigrate();
    // Verify the user configuration is accurate
    WikiUserConfiguration expectedConfiguration = new WikiUserConfiguration();
    expectedConfiguration.setUserScope(UserScope.GLOBAL_ONLY);
    expectedConfiguration.setMembershipType(MembershipType.INVITE);
    verify(wikiUserConfigurationHelper).saveConfiguration(eq(expectedConfiguration), eq("workspacetemplate"));
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration) XWikiContext(com.xpn.xwiki.XWikiContext) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 5 with WikiUserConfiguration

use of org.xwiki.wiki.user.WikiUserConfiguration in project xwiki-platform by xwiki.

the class DefaultWikiUserConfigurationHelper method getConfiguration.

@Override
public WikiUserConfiguration getConfiguration(String wikiId) throws WikiUserManagerException {
    // Create the configuration object to return
    WikiUserConfiguration configuration = new WikiUserConfiguration();
    // Get the document
    XWikiDocument document = getDocument(wikiId);
    // Get the XWiki object
    BaseObject object = document.getXObject(WikiUserClassDocumentInitializer.CONFIGURATION_CLASS);
    if (object != null) {
        // Get the user scope
        String scopeValue = object.getStringValue(WikiUserClassDocumentInitializer.FIELD_USERSCOPE);
        UserScope userScope;
        try {
            userScope = UserScope.valueOf(scopeValue.toUpperCase());
        } catch (Exception e) {
            // Default value
            userScope = UserScope.LOCAL_AND_GLOBAL;
        }
        configuration.setUserScope(userScope);
        // Get the membershipType value
        String membershipTypeValue = object.getStringValue(WikiUserClassDocumentInitializer.FIELD_MEMBERSHIPTYPE);
        MembershipType membershipType;
        try {
            membershipType = MembershipType.valueOf(membershipTypeValue.toUpperCase());
        } catch (Exception e) {
            // Default value
            membershipType = MembershipType.INVITE;
        }
        configuration.setMembershipType(membershipType);
    }
    return configuration;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiUserConfiguration(org.xwiki.wiki.user.WikiUserConfiguration) UserScope(org.xwiki.wiki.user.UserScope) MembershipType(org.xwiki.wiki.user.MembershipType) XWikiException(com.xpn.xwiki.XWikiException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) BaseObject(com.xpn.xwiki.objects.BaseObject)

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