Search in sources :

Example 86 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class RightsManager method removeDirectRights.

/**
 * Remove "direct" rights for wiki, space or document. This means that after that inherited right will be used.
 *
 * @param spaceOrPage the space of page where to get XWikiRights. If null get wiki rights.
 * @param levelNames the levels names to check ("view", "edit", etc.).
 * @param comment the comment to use when saving preferences document.
 * @param context the XWiki context.
 * @throws XWikiException error when browsing rights.
 */
public void removeDirectRights(String spaceOrPage, List<String> levelNames, String comment, XWikiContext context) throws XWikiException {
    XWikiDocument preferences = getXWikiPreferencesDoc(spaceOrPage, context);
    boolean global = isGlobal(preferences, spaceOrPage);
    EntityReference rightClassReference = global ? XWikiRightServiceImpl.GLOBALRIGHTCLASS_REFERENCE : XWikiRightServiceImpl.RIGHTCLASS_REFERENCE;
    List<BaseObject> rightObjects = preferences.getXObjects(rightClassReference);
    if (rightObjects != null && !rightObjects.isEmpty()) {
        preferences.removeXObjects(rightClassReference);
        context.getWiki().saveDocument(preferences, comment, context);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) EntityReference(org.xwiki.model.reference.EntityReference) BaseObject(com.xpn.xwiki.objects.BaseObject)

Example 87 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class ExportURLFactoryMockitoTest method createURLWhenNotInExportedPages.

@Test
public void createURLWhenNotInExportedPages() throws Exception {
    DocumentReference pageReference = new DocumentReference("xwiki", "Main", "WebHome");
    when(this.currentDocumentReferenceResolver.resolve("Main.WebHome")).thenReturn(pageReference);
    when(this.defaultEntityReferenceSerializer.serialize(pageReference)).thenReturn("xwiki:Main.WebHome");
    when(this.legacySpaceResolver.resolve("Main")).thenReturn(Arrays.asList("Main"));
    when(this.fsPathEntityReferenceSerializer.serialize(pageReference)).thenReturn("Main/WebHome");
    DocumentReference pageReference2 = new DocumentReference("xwiki", "Main", "SomeOtherPage");
    when(this.fsPathEntityReferenceSerializer.serialize(pageReference2)).thenReturn("Main/SomeOtherPage");
    when(this.relativeEntityReferenceResolver.resolve("Main", EntityType.SPACE)).thenReturn(new EntityReference("Main", EntityType.SPACE));
    this.factory.init(Arrays.asList(pageReference), null, new FilesystemExportContext(), this.context);
    assertEquals(new URL("http://localhost:8080/xwiki/bin/Main/SomeOtherPage"), this.factory.createURL("Main", "SomeOtherPage", "view", null, null, "xwiki", this.context));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) DocumentReference(org.xwiki.model.reference.DocumentReference) URL(java.net.URL) Test(org.junit.Test)

Example 88 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class ExportURLFactoryMockitoTest method createURLWhenInExportedPages.

@Test
public void createURLWhenInExportedPages() throws Exception {
    DocumentReference pageReference = new DocumentReference("xwiki", "Main", "WebHome");
    when(this.currentDocumentReferenceResolver.resolve("Main.WebHome")).thenReturn(pageReference);
    when(this.defaultEntityReferenceSerializer.serialize(pageReference)).thenReturn("xwiki:Main.WebHome");
    when(this.legacySpaceResolver.resolve("Main")).thenReturn(Arrays.asList("Main"));
    when(this.fsPathEntityReferenceSerializer.serialize(pageReference)).thenReturn("Main/WebHome");
    when(this.relativeEntityReferenceResolver.resolve("Main", EntityType.SPACE)).thenReturn(new EntityReference("Main", EntityType.SPACE));
    FilesystemExportContext exportContext = new FilesystemExportContext();
    // Simulate locating the doc in pages/Main/WebHome (ie 3 levels deep)
    exportContext.setDocParentLevels(3);
    this.factory.init(Arrays.asList(pageReference), null, exportContext, this.context);
    assertEquals(new URL("file://../../../pages/Main/WebHome.html"), this.factory.createURL("Main", "WebHome", "view", null, null, "xwiki", this.context));
}
Also used : EntityReference(org.xwiki.model.reference.EntityReference) FilesystemExportContext(org.xwiki.url.filesystem.FilesystemExportContext) DocumentReference(org.xwiki.model.reference.DocumentReference) URL(java.net.URL) Test(org.junit.Test)

Example 89 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class WikisResourceImpl method getWikis.

@Override
public Wikis getWikis() throws XWikiRestException {
    try {
        Wikis wikis = objectFactory.createWikis();
        for (String wikiId : this.wikiDescriptorManager.getAllIds()) {
            // Allow listing a wiki if:
            // - the user has view access to it
            // - or the wiki accepts global users and is not an invitation-based wiki
            // - or the current user has a pending invitation to the wiki
            // Note 1: To check if a user has view access to a wiki we check if the user can access the home page
            // of the "XWiki" space. We do this because this needs to be allowed in view for the wiki to
            // work properly.
            // Note 2: it would be nicer to have an API for this.
            // Note 3: this strategy is copied from WikisLiveTableResults.xml
            EntityReference absoluteCommentReference = new EntityReference(this.defaultDocumentReferenceProvider.get().getName(), EntityType.DOCUMENT, new EntityReference("XWiki", EntityType.SPACE, new EntityReference(wikiId, EntityType.WIKI)));
            DocumentReference currentUserReference = getXWikiContext().getUserReference();
            if (this.authorizationManager.hasAccess(Right.VIEW, absoluteCommentReference) || (this.wikiUserManager.getUserScope(wikiId) != UserScope.LOCAL_ONLY && this.wikiUserManager.getMembershipType(wikiId) != MembershipType.INVITE) || this.wikiUserManager.hasPendingInvitation(currentUserReference, wikiId)) {
                wikis.getWikis().add(DomainObjectFactory.createWiki(objectFactory, uriInfo.getBaseUri(), wikiId));
            }
        }
        String queryUri = Utils.createURI(uriInfo.getBaseUri(), WikisSearchQueryResource.class).toString();
        Link queryLink = objectFactory.createLink();
        queryLink.setHref(queryUri);
        queryLink.setRel(Relations.QUERY);
        wikis.getLinks().add(queryLink);
        return wikis;
    } catch (Exception e) {
        throw new XWikiRestException("Failed to get the list of wikis", e);
    }
}
Also used : WikisSearchQueryResource(org.xwiki.rest.resources.wikis.WikisSearchQueryResource) XWikiRestException(org.xwiki.rest.XWikiRestException) Wikis(org.xwiki.rest.model.jaxb.Wikis) EntityReference(org.xwiki.model.reference.EntityReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Link(org.xwiki.rest.model.jaxb.Link) XWikiRestException(org.xwiki.rest.XWikiRestException)

Example 90 with EntityReference

use of org.xwiki.model.reference.EntityReference in project xwiki-platform by xwiki.

the class AbstractEntityRestURLGenerator method getSpaceList.

protected List<String> getSpaceList(SpaceReference spaceReference) {
    List<String> spaces = new ArrayList<>();
    for (EntityReference ref = spaceReference; ref != null && ref.getType() == EntityType.SPACE; ref = ref.getParent()) {
        spaces.add(ref.getName());
    }
    Collections.reverse(spaces);
    return spaces;
}
Also used : ArrayList(java.util.ArrayList) EntityReference(org.xwiki.model.reference.EntityReference)

Aggregations

EntityReference (org.xwiki.model.reference.EntityReference)338 Test (org.junit.Test)157 DocumentReference (org.xwiki.model.reference.DocumentReference)107 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)39 BaseObject (com.xpn.xwiki.objects.BaseObject)38 ArrayList (java.util.ArrayList)27 XWikiContext (com.xpn.xwiki.XWikiContext)24 WikiReference (org.xwiki.model.reference.WikiReference)24 SpaceReference (org.xwiki.model.reference.SpaceReference)23 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)18 XWikiException (com.xpn.xwiki.XWikiException)17 EntityType (org.xwiki.model.EntityType)11 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)10 EntityReferenceProvider (org.xwiki.model.reference.EntityReferenceProvider)9 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 XDOM (org.xwiki.rendering.block.XDOM)8 URL (java.net.URL)7 AttachmentReference (org.xwiki.model.reference.AttachmentReference)7 HashMap (java.util.HashMap)6 Before (org.junit.Before)6