use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class DefaultWikiUserManager method getMembers.
@Override
public Collection<String> getMembers(String wikiId) throws WikiUserManagerException {
List<String> members = new ArrayList<>();
try {
// Get the descriptor
WikiDescriptor descriptor = wikiDescriptorManager.getById(wikiId);
// Add the wiki owner
members.add(descriptor.getOwnerId());
} catch (WikiManagerException e) {
throw new WikiUserManagerException(String.format("Failed to get the descriptor for [%s]", wikiId), e);
}
// Get the other members from the wiki AllGroup
XWikiDocument groupDoc = getMembersGroupDocument(wikiId);
List<BaseObject> memberObjects = groupDoc.getXObjects(GROUPCLASS_REFERENCE);
if (memberObjects != null) {
for (BaseObject object : memberObjects) {
if (object == null) {
continue;
}
String member = object.getStringValue(GROUP_CLASS_MEMBER_FIELD);
if (!member.isEmpty() && !members.contains(member)) {
members.add(member);
}
}
}
return members;
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method createWikiNoFailOnExistWithoutPR.
@Test
public void createWikiNoFailOnExistWithoutPR() throws Exception {
Exception exception = currentUserHasNotProgrammingRight();
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", false);
assertNull(result);
assertEquals(exception, mocker.getComponentUnderTest().getLastError());
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method createWiki.
@Test
public void createWiki() throws Exception {
WikiDescriptor descriptor = new WikiDescriptor("newiki", "alias");
when(wikiManager.create("newwiki", "alias", true)).thenReturn(descriptor);
WikiDescriptor result = mocker.getComponentUnderTest().createWiki("newwiki", "alias", "userA", true);
assertEquals(descriptor, result);
assertEquals("userA", result.getOwnerId());
verify(wikiDescriptorManager).saveDescriptor(result);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method saveDescriptorWhenDescriptorDidNotExist.
@Test
public void saveDescriptorWhenDescriptorDidNotExist() throws Exception {
WikiDescriptor descriptor = new WikiDescriptor("wikiId", "wikiAlias");
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor);
assertFalse(result);
// Verify the rights have been checked
verify(authorizationManager).hasAccess(eq(Right.ADMIN), eq(currentUserRef), eq(new WikiReference("mainWiki")));
// The descriptor has not been saved
verify(wikiDescriptorManager, never()).saveDescriptor(descriptor);
}
use of org.xwiki.wiki.descriptor.WikiDescriptor in project xwiki-platform by xwiki.
the class WikiManagerScriptServiceTest method saveDescriptorWhenICanEditDescriptorDocumentAndChangeOwner.
@Test
public void saveDescriptorWhenICanEditDescriptorDocumentAndChangeOwner() throws Exception {
WikiDescriptor oldDescriptor = new WikiDescriptor("wikiId", "wikiAlias");
oldDescriptor.setOwnerId("SomeUser");
when(wikiDescriptorManager.getById(oldDescriptor.getId())).thenReturn(oldDescriptor);
DocumentReference wikiDescriptorDocRef = getAndSetupDescriptorDocument(oldDescriptor.getId());
when(this.authorizationManager.hasAccess(Right.EDIT, currentUserRef, wikiDescriptorDocRef)).thenReturn(true);
// Changing the owner is possible, since I can directly edit the wiki descriptor anyway.
WikiDescriptor descriptor = new WikiDescriptor(oldDescriptor.getId(), "wikiAlias");
descriptor.setOwnerId("SomeOtherUserOrMyself");
boolean result = mocker.getComponentUnderTest().saveDescriptor(descriptor);
assertTrue(result);
// The descriptor has been saved
verify(wikiDescriptorManager).saveDescriptor(descriptor);
}
Aggregations