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