diff --git a/xwiki-platform-core/xwiki-platform-display/xwiki-platform-display-macro/src/main/java/org/xwiki/rendering/internal/macro/display/DisplayMacro.java b/xwiki-platform-core/xwiki-platform-display/xwiki-platform-display-macro/src/main/java/org/xwiki/rendering/internal/macro/display/DisplayMacro.java index 80c3655d3370..620514a3b6a7 100644 --- a/xwiki-platform-core/xwiki-platform-display/xwiki-platform-display-macro/src/main/java/org/xwiki/rendering/internal/macro/display/DisplayMacro.java +++ b/xwiki-platform-core/xwiki-platform-display/xwiki-platform-display-macro/src/main/java/org/xwiki/rendering/internal/macro/display/DisplayMacro.java @@ -65,9 +65,6 @@ public DisplayMacro() { super("Display", DESCRIPTION, DisplayMacroParameters.class); - // The display macro must execute first since if it runs with the current context it needs to bring - // all the macros from the displayed page before the other macros are executed. - setPriority(10); setDefaultCategories(Set.of(DEFAULT_CATEGORY_CONTENT)); } @@ -97,7 +94,7 @@ public List execute(DisplayMacroParameters parameters, String content, Ma } // Step 3: Check right - if (!this.authorization.hasAccess(Right.VIEW, documentBridge.getDocumentReference())) { + if (!this.contextualAuthorization.hasAccess(Right.VIEW, documentBridge.getDocumentReference())) { throw new MacroExecutionException( String.format("Current user [%s] doesn't have view rights on document [%s]", this.documentAccessBridge.getCurrentUserReference(), documentBridge.getDocumentReference())); diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-context/src/main/java/org/xwiki/rendering/internal/macro/context/ContextMacro.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-context/src/main/java/org/xwiki/rendering/internal/macro/context/ContextMacro.java index 890e538b3624..37d5d1eb61fb 100644 --- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-context/src/main/java/org/xwiki/rendering/internal/macro/context/ContextMacro.java +++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-context/src/main/java/org/xwiki/rendering/internal/macro/context/ContextMacro.java @@ -90,9 +90,6 @@ public ContextMacro() super("Context", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION, true, Block.LIST_BLOCK_TYPE), ContextMacroParameters.class); - // The Context macro must execute early since it can contain include macros which can bring stuff like headings - // for other macros (TOC macro, etc). Make it the same priority as the Include macro. - setPriority(10); setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT)); } diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/AbstractIncludeMacro.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/AbstractIncludeMacro.java index 3652deeb5dec..8ffe2bdee29b 100644 --- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/AbstractIncludeMacro.java +++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/AbstractIncludeMacro.java @@ -57,7 +57,7 @@ public abstract class AbstractIncludeMacro

extends AbstractMacro

protected DocumentAccessBridge documentAccessBridge; @Inject - protected ContextualAuthorizationManager authorization; + protected ContextualAuthorizationManager contextualAuthorization; /** * Used to serialize resolved document links into a string again since the Rendering API only manipulates Strings diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/IncludeMacro.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/IncludeMacro.java index 4385d864b649..0b90b3b20f40 100644 --- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/IncludeMacro.java +++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/internal/macro/include/IncludeMacro.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.Stack; @@ -44,10 +43,12 @@ import org.xwiki.rendering.listener.MetaData; import org.xwiki.rendering.macro.MacroExecutionException; import org.xwiki.rendering.macro.include.IncludeMacroParameters; +import org.xwiki.rendering.macro.include.IncludeMacroParameters.Author; import org.xwiki.rendering.macro.include.IncludeMacroParameters.Context; import org.xwiki.rendering.transformation.MacroTransformationContext; import org.xwiki.rendering.transformation.TransformationManager; import org.xwiki.security.authorization.AuthorExecutor; +import org.xwiki.security.authorization.AuthorizationManager; import org.xwiki.security.authorization.Right; /** @@ -74,6 +75,9 @@ public class IncludeMacro extends AbstractIncludeMacro @Inject private AuthorExecutor authorExecutor; + @Inject + protected AuthorizationManager authorization; + /** * Default constructor. */ @@ -81,9 +85,6 @@ public IncludeMacro() { super("Include", DESCRIPTION, IncludeMacroParameters.class); - // The include macro must execute first since if it runs with the current context it needs to bring - // all the macros from the included page before the other macros are executed. - setPriority(10); setDefaultCategories(Set.of(DEFAULT_CATEGORY_CONTENT)); } @@ -113,7 +114,7 @@ public List execute(IncludeMacroParameters parameters, String content, Ma } // Step 3: Check right - if (!this.authorization.hasAccess(Right.VIEW, documentBridge.getDocumentReference())) { + if (!this.contextualAuthorization.hasAccess(Right.VIEW, documentBridge.getDocumentReference())) { throw new MacroExecutionException( String.format("Current user [%s] doesn't have view rights on document [%s]", this.documentAccessBridge.getCurrentUserReference(), documentBridge.getDocumentReference())); @@ -177,17 +178,17 @@ public List execute(IncludeMacroParameters parameters, String content, Ma metadata.getMetaData().addMetaData(MetaData.BASE, source); } - // Step 7: If the included content author is different from the current author, we have to execute it right now - // so that it used the proper rights - // Get the translated version of the document to compare with the right author + // Step 7: The the include macro is explicitly configured to be executed with the included document content + // author of if that author does not have programming right, execute it right away + // Get the translated version of the document to get the content author DocumentModelBridge translatedDocumentBridge; try { translatedDocumentBridge = this.documentAccessBridge.getTranslatedDocumentInstance(documentBridge); } catch (Exception e) { throw new MacroExecutionException("Failed to retrieve the translated version of the document", e); } - if (!Objects.equals(translatedDocumentBridge.getContentAuthorReference(), - this.documentAccessBridge.getCurrentAuthorReference())) { + if (parameters.getAuthor() == Author.TARGET || parameters.getAuthor() == Author.AUTO && !this.authorization + .hasAccess(Right.PROGRAM, translatedDocumentBridge.getContentAuthorReference(), null)) { // Merge the two XDOM before executing the included content so that it's as close as possible to the expect // execution conditions MacroBlock includeMacro = context.getCurrentMacroBlock(); diff --git a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/macro/include/IncludeMacroParameters.java b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/macro/include/IncludeMacroParameters.java index 95ff9f826e7b..b6cd2317f331 100644 --- a/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/macro/include/IncludeMacroParameters.java +++ b/xwiki-platform-core/xwiki-platform-rendering/xwiki-platform-rendering-macros/xwiki-platform-rendering-macro-include/src/main/java/org/xwiki/rendering/macro/include/IncludeMacroParameters.java @@ -54,6 +54,30 @@ public enum Context CURRENT } + /** + * Control which author to execute the included content with. + * + * @since 15.0RC1 + */ + public enum Author + { + /** + * Apply TARGET option unless the target author has programming right in which case it applies CURRENT (mainly + * for retro-compatibility reasons). + */ + AUTO, + + /** + * The content is executed with the right of the current author which uses the include macro. + */ + CURRENT, + + /** + * The content is executed with the right of the included content author. + */ + TARGET + } + /** * @see #getReference() */ @@ -74,12 +98,14 @@ public enum Context * @see #getSection() */ private String section; - + /** * @see #isExcludeFirstHeading() */ private boolean excludeFirstHeading; - + + private Author author; + /** * @param reference the reference of the resource to include * @since 3.4M1 @@ -122,9 +148,9 @@ public String getSection() } /** - * @param excludeFirstHeading {@code true} to remove the first heading found inside - * the document or the section, {@code false} to keep it - * @since 12.4RC1 + * @param excludeFirstHeading {@code true} to remove the first heading found inside the document or the section, + * {@code false} to keep it + * @since 12.4RC1 */ @PropertyName("Exclude First Heading") @PropertyDescription("Exclude the first heading from the included document or section.") @@ -133,10 +159,10 @@ public void setExcludeFirstHeading(boolean excludeFirstHeading) { this.excludeFirstHeading = excludeFirstHeading; } - + /** * @return whether to exclude the first heading from the included document or section, or not. - * @since 12.4RC1 + * @since 12.4RC1 */ public boolean isExcludeFirstHeading() { @@ -206,4 +232,24 @@ public void setPage(String page) this.reference = page; this.type = EntityType.PAGE; } + + /** + * @return the author to use to execute the content + * @since 15.0RC1 + */ + public Author getAuthor() + { + return this.author; + } + + /** + * @param author the author to use to execute the content + * @since 15.0RC1 + */ + @PropertyDescription("The author to use to execute the content") + @PropertyAdvanced + public void setAuthor(Author author) + { + this.author = author; + } } diff --git a/xwiki-platform-core/xwiki-platform-template/xwiki-platform-template-api/src/main/java/org/xwiki/template/internal/macro/TemplateMacro.java b/xwiki-platform-core/xwiki-platform-template/xwiki-platform-template-api/src/main/java/org/xwiki/template/internal/macro/TemplateMacro.java index 6b4e1e816998..8616569c340f 100644 --- a/xwiki-platform-core/xwiki-platform-template/xwiki-platform-template-api/src/main/java/org/xwiki/template/internal/macro/TemplateMacro.java +++ b/xwiki-platform-core/xwiki-platform-template/xwiki-platform-template-api/src/main/java/org/xwiki/template/internal/macro/TemplateMacro.java @@ -63,9 +63,6 @@ public TemplateMacro() { super("Template", DESCRIPTION, TemplateMacroParameters.class); - // The template macro must execute first since if it runs with the current context it needs to bring - // all the macros from the template before the other macros are executed. - setPriority(10); setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT)); } diff --git a/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionMacro.java b/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionMacro.java index ebc1f1021d22..ddaec0dfb94a 100644 --- a/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionMacro.java +++ b/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionMacro.java @@ -66,9 +66,6 @@ public UIExtensionMacro() { super("UI Extensions", DESCRIPTION, UIExtensionsMacroParameters.class); - // The ui extensions macro must execute first since if it runs with the current context it needs to bring - // all the macros from the extension before the other macros are executed. - setPriority(10); setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT)); } diff --git a/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionsMacro.java b/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionsMacro.java index 92a759a82ede..e4ca1cce58c6 100644 --- a/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionsMacro.java +++ b/xwiki-platform-core/xwiki-platform-uiextension/xwiki-platform-uiextension-api/src/main/java/org/xwiki/uiextension/internal/macro/UIExtensionsMacro.java @@ -64,9 +64,6 @@ public UIExtensionsMacro() { super("UI Extensions", DESCRIPTION, UIExtensionsMacroParameters.class); - // The ui extensions macro must execute first since if it runs with the current context it needs to bring - // all the macros from the extension before the other macros are executed. - setPriority(10); setDefaultCategories(Set.of(DEFAULT_CATEGORY_DEVELOPMENT)); }