Search in sources :

Example 1 with MembershipType

use of org.xwiki.wiki.user.MembershipType 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 2 with MembershipType

use of org.xwiki.wiki.user.MembershipType 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)

Example 3 with MembershipType

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

the class WikiUserManagerScriptServiceTest method getMembershipTypeWithError.

@Test
public void getMembershipTypeWithError() throws Exception {
    // Mocks
    Exception expectedException = new WikiUserManagerException("Error in getMembershipType");
    when(wikiUserManager.getMembershipType("test")).thenThrow(expectedException);
    // Test
    MembershipType result = mocker.getComponentUnderTest().getMembershipType("test");
    // Asserts
    assertNull(result);
    assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) MembershipType(org.xwiki.wiki.user.MembershipType) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Example 4 with MembershipType

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

the class WikiUserManagerScriptServiceTest method getMembershipType.

@Test
public void getMembershipType() throws Exception {
    // Mocks
    when(wikiUserManager.getMembershipType("subwiki")).thenReturn(MembershipType.INVITE);
    // Test
    MembershipType result = mocker.getComponentUnderTest().getMembershipType();
    // Asserts
    assertEquals(MembershipType.INVITE, result);
}
Also used : MembershipType(org.xwiki.wiki.user.MembershipType) Test(org.junit.Test)

Aggregations

MembershipType (org.xwiki.wiki.user.MembershipType)4 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)3 XWikiException (com.xpn.xwiki.XWikiException)2 Test (org.junit.Test)2 WikiUserConfiguration (org.xwiki.wiki.user.WikiUserConfiguration)2 XWiki (com.xpn.xwiki.XWiki)1 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 DataMigrationException (com.xpn.xwiki.store.migration.DataMigrationException)1 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)1 UserScope (org.xwiki.wiki.user.UserScope)1