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