Search in sources :

Example 26 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method acceptInvitation.

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

Example 27 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method getAllInvitations.

@Test
public void getAllInvitations() throws Exception {
    ArrayList<MemberCandidacy> candidacies = new ArrayList<MemberCandidacy>();
    // the first candidacy concerns the current user
    candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.User", MemberCandidacy.CandidateType.INVITATION));
    // not the second
    candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.INVITATION));
    candidacies.get(0).setAdminPrivateComment("private message");
    // We do not have admin rights
    when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef), eq(new WikiReference("subwiki")))).thenReturn(false);
    when(wikiUserManager.getAllInvitations("subwiki")).thenReturn(candidacies);
    // Test
    Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllInvitations("subwiki");
    // the result must have been filtered
    assertEquals(1, result.size());
    assertTrue(result.contains(candidacies.get(0)));
    assertFalse(result.contains(candidacies.get(1)));
    // The private message from the candidacy must be removed
    assertNull(((MemberCandidacy) result.toArray()[0]).getAdminPrivateComment());
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) ArrayList(java.util.ArrayList) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 28 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method refuseInvitationWhenUserHasNoAdminRight.

@Test
public void refuseInvitationWhenUserHasNoAdminRight() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.INVITATION);
    // Mocks
    Exception expectedException = currentUserHasNotAdminRight();
    // Test
    Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks");
    // Asserts
    assertFalse(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 29 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method cancelCandidacyWhenUserHasNoAdminRight.

@Test
public void cancelCandidacyWhenUserHasNoAdminRight() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.INVITATION);
    // Mocks
    Exception expectedException = currentUserHasNotAdminRight();
    // Test
    Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy);
    // Asserts
    assertFalse(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 30 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method cancelCandidacyWhenUserHasNoAdminRightButConcerned.

@Test
public void cancelCandidacyWhenUserHasNoAdminRightButConcerned() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", MemberCandidacy.CandidateType.INVITATION);
    // Mocks
    currentUserHasNotAdminRight();
    // Test
    Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy);
    // Asserts
    assertTrue(result);
    assertNull(mocker.getComponentUnderTest().getLastError());
    verify(wikiUserManager).cancelCandidacy(candidacy);
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) 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