Search in sources :

Example 1 with UserScope

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

the class WikiUserManagerScriptServiceTest method getUserScopeWithError.

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

Example 2 with UserScope

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

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

the class WikiUserManagerScriptServiceTest method getUserScope.

@Test
public void getUserScope() throws Exception {
    when(wikiUserManager.getUserScope("subwiki")).thenReturn(UserScope.GLOBAL_ONLY);
    UserScope result = mocker.getComponentUnderTest().getUserScope();
    assertEquals(UserScope.GLOBAL_ONLY, result);
}
Also used : UserScope(org.xwiki.wiki.user.UserScope) Test(org.junit.Test)

Aggregations

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