Search in sources :

Example 11 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method refuseInvitation.

@Test
public void refuseInvitation() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", MemberCandidacy.CandidateType.INVITATION);
    // Test
    Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks");
    // Asserts
    assertTrue(result);
    assertNull(mocker.getComponentUnderTest().getLastError());
    verify(wikiUserManager).refuseInvitation(candidacy, "no thanks");
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) Test(org.junit.Test)

Example 12 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method askToJoinWhenUsertHasNoRight.

@Test
public void askToJoinWhenUsertHasNoRight() throws Exception {
    // Mocks
    Exception expectedException = currentUserHasNotAdminRight();
    // Test
    MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.OtherUser", "subwiki", "please!");
    // Asserts
    assertNull(result);
    assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
    verifyZeroInteractions(wikiUserManager);
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Example 13 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method refuseInvitationWhenUserHasNoAdminRightButConcerned.

@Test
public void refuseInvitationWhenUserHasNoAdminRightButConcerned() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", MemberCandidacy.CandidateType.INVITATION);
    // Mocks
    currentUserHasNotAdminRight();
    // Test
    Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks");
    // Asserts
    assertTrue(result);
    assertNull(mocker.getComponentUnderTest().getLastError());
    verify(wikiUserManager).refuseInvitation(candidacy, "no thanks");
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) Test(org.junit.Test)

Example 14 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method getCandidacyAsAdmin.

@Test
public void getCandidacyAsAdmin() throws Exception {
    // Mocks
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.REQUEST);
    candidacy.setId(12);
    candidacy.setAdminPrivateComment("private message");
    when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
    when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), eq(new WikiReference("subwiki")))).thenReturn(true);
    // Test
    MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
    // Asserts
    assertEquals(candidacy, result);
    assertEquals("private message", result.getAdminPrivateComment());
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 15 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method getCandidacyWhenNoRight.

@Test
public void getCandidacyWhenNoRight() throws Exception {
    // Mocks
    // The current user is not the candidate
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.REQUEST);
    candidacy.setId(12);
    when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
    // The current user does not have ADMIN right
    when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), eq(new WikiReference("subwiki")))).thenReturn(false);
    // Test
    MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
    // Asserts
    assertNull(result);
    Exception exception = mocker.getComponentUnderTest().getLastError();
    assertTrue(exception instanceof WikiUserManagerScriptServiceException);
    assertEquals("You are not allowed to see this candidacy.", exception.getMessage());
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiReference(org.xwiki.model.reference.WikiReference) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) Test(org.junit.Test)

Aggregations

MemberCandidacy (org.xwiki.wiki.user.MemberCandidacy)34 Test (org.junit.Test)29 WikiUserManagerException (org.xwiki.wiki.user.WikiUserManagerException)15 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)12 WikiReference (org.xwiki.model.reference.WikiReference)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 BaseObject (com.xpn.xwiki.objects.BaseObject)3 ArrayList (java.util.ArrayList)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 XWikiException (com.xpn.xwiki.XWikiException)2