Search in sources :

Example 16 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method acceptRequest.

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

Example 17 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method acceptRequestWhenUserHasNoAdminRight.

@Test
public void acceptRequestWhenUserHasNoAdminRight() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.INVITATION);
    // Mocks
    Exception expecyedException = currentUserHasNotAdminRight();
    // Test
    Boolean result = mocker.getComponentUnderTest().acceptRequest(candidacy, "message", "comment");
    // Asserts
    assertFalse(result);
    assertEquals(expecyedException, 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 18 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method refuseRequestWhenUserHasNoAdminRightButConcerned.

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

Example 19 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method getCandidacyAsUserConcerned.

@Test
public void getCandidacyAsUserConcerned() throws Exception {
    // Mocks
    // Here, the candidate is the current user
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", MemberCandidacy.CandidateType.REQUEST);
    candidacy.setId(12);
    candidacy.setAdminPrivateComment("some private message that I should not be able to see");
    when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
    // Test
    MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
    // Asserts
    assertEquals(candidacy, result);
    // Verify that the private message has been removed from the candidacy
    assertNull(candidacy.getAdminPrivateComment());
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) Test(org.junit.Test)

Example 20 with MemberCandidacy

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

the class DefaultWikiUserManager method getAllMemberCandidacies.

private Collection<MemberCandidacy> getAllMemberCandidacies(String wikiId, MemberCandidacy.CandidateType type) throws WikiUserManagerException {
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    // Collect all the candidacy of the good type
    Collection<MemberCandidacy> candidacies = new ArrayList<>();
    String typeString = type.name().toLowerCase();
    List<BaseObject> candidacyObjects = groupDoc.getXObjects(WikiCandidateMemberClassInitializer.REFERENCE);
    if (candidacyObjects != null) {
        for (BaseObject object : candidacyObjects) {
            if (object != null && object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE).equals(typeString)) {
                candidacies.add(readCandidacyFromObject(object, wikiId));
            }
        }
    }
    return candidacies;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) ArrayList(java.util.ArrayList) BaseObject(com.xpn.xwiki.objects.BaseObject)

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