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;
}
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;
}
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");
}
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");
}
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());
}
Aggregations