use of org.xwiki.wiki.user.MemberCandidacy in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method askToJoin.
@Override
public MemberCandidacy askToJoin(String userId, String wikiId, String message) throws WikiUserManagerException {
MemberCandidacy candidacy = new MemberCandidacy(wikiId, userId, MemberCandidacy.CandidateType.REQUEST);
candidacy.setUserComment(message);
// Get the group document
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
// Add a candidacy object
XWikiContext xcontext = xcontextProvider.get();
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.setLargeStringValue(WikiCandidateMemberClassInitializer.FIELD_USER_COMMENT, candidacy.getUserComment());
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 join request.", e);
}
// Save the document
saveGroupDocument(groupDoc, String.format("[%s] asks to join the wiki.", userId));
return candidacy;
}
use of org.xwiki.wiki.user.MemberCandidacy in project xwiki-platform by xwiki.
the class WikiUserManagerScriptService method getCandidacy.
/**
* Get the specified candidacy.
*
* @param wikiId Id of the wiki concerned by the candidacy
* @param candidacyId id of the candidacy
* @return the candidacy or null if problems occur
*/
public MemberCandidacy getCandidacy(String wikiId, int candidacyId) {
// Get the candidacy
MemberCandidacy candidacy = null;
try {
candidacy = wikiUserManager.getCandidacy(wikiId, candidacyId);
// Check the rights
if (!canSeeCandidacy(candidacy)) {
setLastError(new WikiUserManagerScriptServiceException("You are not allowed to see this candidacy."));
candidacy = null;
}
} catch (WikiUserManagerException e) {
setLastError(e);
}
return candidacy;
}
use of org.xwiki.wiki.user.MemberCandidacy in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method getAllRequests.
@Test
public void getAllRequests() 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.REQUEST));
// not the second
candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.REQUEST));
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.getAllRequests("subwiki")).thenReturn(candidacies);
// Test
Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllRequests("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());
}
use of org.xwiki.wiki.user.MemberCandidacy in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method refuseRequestWhenUserHasNoAdminRight.
@Test
public void refuseRequestWhenUserHasNoAdminRight() throws Exception {
MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser", MemberCandidacy.CandidateType.INVITATION);
// Mocks
Exception expectedException = currentUserHasNotAdminRight();
// Test
Boolean result = mocker.getComponentUnderTest().refuseRequest(candidacy, "message", "comment");
// Asserts
assertFalse(result);
assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
verifyZeroInteractions(wikiUserManager);
}
use of org.xwiki.wiki.user.MemberCandidacy in project xwiki-platform by xwiki.
the class WikiUserManagerScriptServiceTest method invite.
@Test
public void invite() throws Exception {
// Mocks
when(wikiUserManager.invite(any(), any(), any())).thenReturn(new MemberCandidacy());
// Test
MemberCandidacy result = mocker.getComponentUnderTest().invite("someUser", "subwiki", "someMessage");
// Asserts
assertNotNull(result);
}
Aggregations