Details
-
Bug
-
Resolution: Fixed
-
Major
-
17.10.14, 18.8.0, 18.4.7
-
None
-
Unit
-
Unknown
-
N/A
-
N/A
-
Description
Steps to reproduce
- Create a page with an XWiki.WikiMacroClass object, visibility Current Wiki (the default), id mymacro and code v1, and a page containing {{mymacro/}}.
- Delete the macro page.
- Look at the page using the macro (or any new page using it).
A second variant: enforce Script right on the macro page ("Information" > "Review required rights"), then change the macro code to v2.
Expected result
The macro is unregistered when its page is deleted (Unknown macro: mymacro). In the variant, the macro is unregistered as soon as its document no longer grants the right its visibility requires, as is the case after a restart.
Actual result
The deleted macro keeps rendering v1 until the next restart. In the variant, the macro keeps rendering v1: the update is silently ignored, and the macro only disappears at the next restart (or XAR import), far away from the change that caused it. With DEBUG logging for org.xwiki.rendering.internal.macro.wikibridge enabled:
DEBUG r.i.m.w.WikiMacroEventListener - Unable to unregister macro in document [xwiki:Space.Macro] org.xwiki.rendering.macro.wikibridge.WikiMacroException: Unable to unregister macro [mymacro] in [xwiki:Space.Macro] for visibility [WIKI] due to insufficient privileges at org.xwiki.rendering.internal.macro.wikibridge.DefaultWikiMacroManager.unregisterWikiMacro(DefaultWikiMacroManager.java:239) at org.xwiki.rendering.internal.macro.wikibridge.WikiMacroEventListener.unregisterMacro(WikiMacroEventListener.java:171)
Why
DefaultWikiMacroManager.unregisterWikiMacro calls WikiMacroFactory.isAllowed for the macro's visibility and refuses to unregister when it returns false. isAllowed checks the right against the current state of the document: its current author, and since required rights, the rights it enforces. So unregistration fails exactly when the document stopped granting the right:
- a deleted document has no author, so the check always fails for Current Wiki and Global macros;
- an author without the right, or enforced required rights below it (e.g. Script for a Current Wiki macro), make it fail too.
WikiMacroEventListener then also skips the re-registration, so the old macro, with its old code and author, stays registered until the next restart, when registration fails and the macro disappears.
Unregistering never grants anything and unregisterWikiMacro is only called by the listener and the initializer, in reaction to a change of the document that was already authorized. Only registration needs the rights check.
How it was found
While taking screenshots for XWIKI-24822 on 18.10.0-SNAPSHOT: enforcing Script on a wiki-visible macro page didn't break the macro as XWIKI-24822 describes; the stale registration explained why. Reproduced on 18.10.0-SNAPSHOT; the same check is on stable-17.10.x and stable-18.4.x, and dates back to XWIKI-7880.
Attachments
Issue Links
- is related to
-
XWIKI-24822 No required rights analyzer for wiki macros, so a wiki-visible macro is reported as needing only script right
-
- Closed
-