Search in sources :

Example 1 with WikiDescriptor

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;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) WikiUserManagerException(org.xwiki.wiki.user.WikiUserManagerException) ArrayList(java.util.ArrayList) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 2 with WikiDescriptor

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());
}
Also used : WikiManagerException(org.xwiki.wiki.manager.WikiManagerException) AccessDeniedException(org.xwiki.security.authorization.AccessDeniedException) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 3 with WikiDescriptor

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);
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 4 with WikiDescriptor

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);
}
Also used : WikiReference(org.xwiki.model.reference.WikiReference) WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) Test(org.junit.Test)

Example 5 with WikiDescriptor

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);
}
Also used : WikiDescriptor(org.xwiki.wiki.descriptor.WikiDescriptor) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Aggregations

WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)60 Test (org.junit.Test)40 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)28 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)17 WikiReference (org.xwiki.model.reference.WikiReference)11 XWikiContext (com.xpn.xwiki.XWikiContext)9 WikiTemplateManagerException (org.xwiki.wiki.template.WikiTemplateManagerException)9 ArrayList (java.util.ArrayList)7 DocumentReference (org.xwiki.model.reference.DocumentReference)6 WikiDescriptorManager (org.xwiki.wiki.descriptor.WikiDescriptorManager)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 BaseObject (com.xpn.xwiki.objects.BaseObject)5 DefaultWikiDescriptor (org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor)5 WikiCreationRequest (org.xwiki.platform.wiki.creationjob.WikiCreationRequest)3 AuthorizationException (org.xwiki.security.authorization.AuthorizationException)3 WikiCopiedEvent (org.xwiki.bridge.event.WikiCopiedEvent)2 WikiCreatedEvent (org.xwiki.bridge.event.WikiCreatedEvent)2 WikiCreatingEvent (org.xwiki.bridge.event.WikiCreatingEvent)2 WikiCreationException (org.xwiki.platform.wiki.creationjob.WikiCreationException)2 WikiDescriptorBuilderException (org.xwiki.wiki.internal.descriptor.builder.WikiDescriptorBuilderException)2