Search in sources :

Example 1 with MemberCandidacy

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

the class DefaultWikiUserManager method readCandidacyFromObject.

private MemberCandidacy readCandidacyFromObject(BaseObject object, String wikiId) {
    MemberCandidacy candidacy = new MemberCandidacy();
    candidacy.setId(object.getNumber());
    candidacy.setWikiId(wikiId);
    candidacy.setUserId(object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_USER));
    candidacy.setUserComment(object.getLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT));
    candidacy.setAdminId(object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN));
    candidacy.setAdminComment(object.getLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT));
    candidacy.setAdminPrivateComment(object.getLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_PRIVATE_COMMENT));
    candidacy.setStatus(MemberCandidacy.Status.valueOf(object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS).toUpperCase()));
    candidacy.setType(MemberCandidacy.CandidateType.valueOf(object.getStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE).toUpperCase()));
    candidacy.setDateOfCreation(object.getDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION));
    candidacy.setDateOfCreation(object.getDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CLOSURE));
    return candidacy;
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy)

Example 2 with MemberCandidacy

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

the class DefaultWikiUserManager method invite.

@Override
public MemberCandidacy invite(String userId, String wikiId, String message) throws WikiUserManagerException {
    XWikiContext xcontext = xcontextProvider.get();
    // Create the candidacy
    MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.INVITATION);
    candidacy.setUserComment(message);
    candidacy.setAdminId(documentReferenceSerializer.serialize(xcontext.getUserReference()));
    // Get the group document
    XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
    // Add a candidacy object
    try {
        int objectNumber = groupDoc.createXObject(WikiCandidateMemberClassInitializer.REFERENCE, xcontext);
        candidacy.setId(objectNumber);
        BaseObject object = groupDoc.getXObject(WikiCandidateMemberClassInitializer.REFERENCE, objectNumber);
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_USER, candidacy.getUserId());
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN, candidacy.getAdminId());
        object.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_ADMIN_COMMENT, message);
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_STATUS, candidacy.getStatus().name().toLowerCase());
        object.setDateValue(WikiCandidateMemberClassInitializer.FIELD_DATE_OF_CREATION, candidacy.getDateOfCreation());
        object.setStringValue(WikiCandidateMemberClassInitializer.FIELD_TYPE, candidacy.getType().name().toLowerCase());
    } catch (XWikiException e) {
        throw new WikiUserManagerException("Failed to create a new invitation object.", e);
    }
    // Save the document
    saveGroupDocument(groupDoc, String.format("[%s] is invited to join the wiki.", userId));
    return candidacy;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 3 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method refuseRequest.

@Test
public void refuseRequest() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", MemberCandidacy.CandidateType.INVITATION);
    // 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 4 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method acceptInvitationWhenUserHasNoAdminRightButConcerned.

@Test
public void acceptInvitationWhenUserHasNoAdminRightButConcerned() throws Exception {
    MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User", MemberCandidacy.CandidateType.INVITATION);
    // Mocks
    currentUserHasNotAdminRight();
    // 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 5 with MemberCandidacy

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

the class WikiUserManagerScriptServiceTest method getAllRequestError.

@Test
public void getAllRequestError() throws Exception {
    // Mocks
    Exception expectedException = new WikiUserManagerException("error in getAllRequests()");
    when(wikiUserManager.getAllRequests("subwiki")).thenThrow(expectedException);
    // Test
    Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllRequests("subwiki");
    // Asserts
    assertNull(result);
    assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
}
Also used : MemberCandidacy(org.xwiki.wiki.user.MemberCandidacy) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) 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