Search in sources :

Example 6 with WikiUserManagerException

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

the class WikiUserManagerScriptService method join.

/**
 * Join a wiki.
 *
 * @param userId userId to add to the wiki
 * @param wikiId id of the wiki
 * @return true if it succeed
 */
public boolean join(String userId, String wikiId) {
    // Check if the current user is userId
    XWikiContext context = xcontextProvider.get();
    DocumentReference candidacyUser = documentReferenceResolver.resolve(userId);
    if (!context.getUserReference().equals(candidacyUser)) {
        setLastError(new WikiUserManagerException(String.format("User [%s] cannot call " + "$services.wiki.user.join() with an other userId.", context.getUserReference())));
        return false;
    }
    try {
        wikiUserManager.join(userId, wikiId);
    } catch (WikiUserManagerException e) {
        setLastError(e);
        return false;
    }
    return true;
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 7 with WikiUserManagerException

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

the class WikiUserManagerScriptServiceTest method leaveWhenError.

@Test
public void leaveWhenError() throws Exception {
    String userId = "mainWiki:XWiki.User";
    String wikiId = "wikiId";
    // Mocks
    WikiUserManagerException expectedException = new WikiUserManagerException("error in wikiUserManager#leave()");
    doThrow(expectedException).when(wikiUserManager).leave(userId, wikiId);
    // Test
    boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId);
    // Asserts
    assertFalse(result);
    assertEquals(expectedException, this.mocker.getComponentUnderTest().getLastError());
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Example 8 with WikiUserManagerException

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

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

the class WikiUserManagerScriptServiceTest method setMembershipTypeError.

@Test
public void setMembershipTypeError() throws Exception {
    // Mocks
    WikiUserManagerException expectedException = new WikiUserManagerException("error in setMembershipType");
    doThrow(expectedException).when(wikiUserManager).setMembershipType(any(), any(MembershipType.class));
    // Test
    boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE");
    // Asserts
    assertEquals(false, result);
    assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) MembershipType(org.xwiki.wiki.user.MembershipType) Test(org.junit.Test)

Example 10 with WikiUserManagerException

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

the class WikiUserManagerScriptServiceTest method getMembersError.

@Test
public void getMembersError() throws Exception {
    // Mocks
    Exception expectedException = new WikiUserManagerException("error in getMembers");
    when(wikiUserManager.getMembers("subwiki")).thenThrow(expectedException);
    // Test
    Collection<String> result = mocker.getComponentUnderTest().getMembers("subwiki");
    // Asserts
    assertNull(result);
    assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
Also used : WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Aggregations

WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)27 Test (org.junit.Test)14 XWikiContext (com.xpn.xwiki.XWikiContext)9 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)9 XWikiException (com.xpn.xwiki.XWikiException)8 BaseObject (com.xpn.xwiki.objects.BaseObject)6 DocumentReference (org.xwiki.model.reference.DocumentReference)6 MemberCandidacy (org.xwiki.wiki.user.MemberCandidacy)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 XWiki (com.xpn.xwiki.XWiki)4 MembershipType (org.xwiki.wiki.user.MembershipType)3 UserScope (org.xwiki.wiki.user.UserScope)3 ArrayList (java.util.ArrayList)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)2 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)2 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)1 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)1 WikiUserConfiguration (org.xwiki.wiki.user.WikiUserConfiguration)1