diff --git a/xwiki-platform-core/xwiki-platform-edit/xwiki-platform-edit-default/src/main/java/org/xwiki/edit/internal/EditorWikiComponent.java b/xwiki-platform-core/xwiki-platform-edit/xwiki-platform-edit-default/src/main/java/org/xwiki/edit/internal/EditorWikiComponent.java index 9b504400bb90c94a115728be79a9dc9269e31cc5..656fd37ef11b1cd6d9c6234b2775938ee9a965ec 100644 --- a/xwiki-platform-core/xwiki-platform-edit/xwiki-platform-edit-default/src/main/java/org/xwiki/edit/internal/EditorWikiComponent.java +++ b/xwiki-platform-core/xwiki-platform-edit/xwiki-platform-edit-default/src/main/java/org/xwiki/edit/internal/EditorWikiComponent.java @@ -142,10 +142,12 @@ protected String render() throws EditException XWikiDocument editorDocument = xcontext.getWiki().getDocument(this.getDocumentReference(), xcontext); BaseObject editorObject = editorDocument.getXObject(EDITOR_CLASS_REFERENCE); String editorCode = editorObject.getStringValue("code"); + // Make sure the editor code is executed with the rights of the editor document author. + XWikiDocument sdoc = editorDocument; // Execute the editor code in the context of the current document (because the editor code needs to access // the data that has been put on the script context). return xcontext.getDoc().getRenderedContent(editorCode, editorDocument.getSyntax().toIdString(), false, - editorDocument, xcontext); + sdoc, xcontext); } catch (Exception e) { throw new EditException("Failed to render the editor code.", e); } finally { diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java index 1234211fac701304533b4826bed531afe17abe99..093d1f599483d95c73da28523d2a0d8b74739ed4 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/api/Document.java @@ -753,9 +753,20 @@ private String getRenderedContent(String text, String syntaxId, boolean restrict public String getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId) throws XWikiException { // Make sure we keep using current author as passed content author - return this.doc.getRenderedContent(text, sourceSyntaxId, targetSyntaxId, false, null, getXWikiContext()); + return this.doc.getRenderedContent(text, sourceSyntaxId, targetSyntaxId, false, getCallerDocument(getXWikiContext()), + getXWikiContext()); } + private XWikiDocument getCallerDocument(XWikiContext xcontext) + { + XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); + if (sdoc == null) { + sdoc = xcontext.getDoc(); + } + + return sdoc; + } + /** * @param targetSyntax the syntax in which to render the document content * @return the rendered content diff --git a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java index c0faf0dc2a9cb3b43ed0dad10b3da189c92a53d4..d90c2bb77c7d95b79bfb68bf9a226b8d041197b7 100644 --- a/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java +++ b/xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/doc/XWikiDocument.java @@ -1268,7 +1268,7 @@ public String getRenderedContent(String text, String sourceSyntaxId, String targ public String getRenderedContent(String text, String sourceSyntaxId, String targetSyntaxId, boolean restrictedTransformationContext, XWikiContext context) { - return getRenderedContent(text, sourceSyntaxId, targetSyntaxId, restrictedTransformationContext, this, context); + return getRenderedContent(text, sourceSyntaxId, targetSyntaxId, restrictedTransformationContext, null, context); } /** @@ -1288,11 +1288,6 @@ public String getRenderedContent(String text, String sourceSyntaxId, String targ XWikiDocument currentSDocument = (XWikiDocument) context.get(CKEY_SDOC); try { - // Remember what is the current caller document because #setAsContextDoc reset it - if (sDocument == null) { - sDocument = getCallerDocument(context); - } - // We have to render the given text in the context of this document. Check if this document is already // on the context (same Java object reference). We don't check if the document references are equal // because this document can have temporary changes that are not present on the context document even if @@ -1303,7 +1298,7 @@ public String getRenderedContent(String text, String sourceSyntaxId, String targ setAsContextDoc(context); } - // Make sure to execute the document with the right of the calling author + // Make sure to execute the document with the right of the provided sdocument's author if (sDocument != null) { context.put(CKEY_SDOC, sDocument); } @@ -1331,16 +1326,6 @@ public String getRenderedContent(String text, String sourceSyntaxId, String targ return ""; } - private XWikiDocument getCallerDocument(XWikiContext xcontext) - { - XWikiDocument sdoc = (XWikiDocument) xcontext.get("sdoc"); - if (sdoc == null) { - sdoc = xcontext.getDoc(); - } - - return sdoc; - } - public String getEscapedContent(XWikiContext context) throws XWikiException { return XMLUtils.escape(getTranslatedContent(context));