[xwiki-users] Apply rights automaticly to child pages
If we grant rights to a group of users to view a page, we would like to grant that right also to all the (sub)children of that page. Right now, we have to set the rights on every childpage. Is this possible? -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hamster wrote
If we grant rights to a group of users to view a page, we would like to grant that right also to all the (sub)children of that page.
In a theory - yes. You should have event listener "on change" for parent page. In this event listener need to define your type of changes (only page rights changes), after - should search all child pages and make changes to its rights same as parent page. But in realty - mechanism of event listeners cannot work normally in production - for example, because it is not possible to have enabled event listeners after restarting application server. Every time after restarting need to starting event listeners manually. Of course, existing some possibilities to resolve this, bu all of them are not normally documented and looks like "roof on the roof". Existing and another problems with event listeners ... For the XWiki platform need to well-organized mechanism of event listeners ... For example, same how is organized Scheduler. Some place, where I can create event, select type of them, enable it, look for logs and etc. -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hi Eugen, On Jul 4, 2012, at 8:47 AM, Eugen Colesnicov wrote:
Hamster wrote
If we grant rights to a group of users to view a page, we would like to grant that right also to all the (sub)children of that page.
In a theory - yes. You should have event listener "on change" for parent page. In this event listener need to define your type of changes (only page rights changes), after - should search all child pages and make changes to its rights same as parent page.
But in realty - mechanism of event listeners cannot work normally in production
This is correct only for event listeners defined in groovy scripts in wiki pages but not event listeners written in Java.
- for example, because it is not possible to have enabled event listeners after restarting application server. Every time after restarting need to starting event listeners manually. Of course, existing some possibilities to resolve this, bu all of them are not normally documented and looks like "roof on the roof". Existing and another problems with event listeners ...
For the XWiki platform need to well-organized mechanism of event listeners ... For example, same how is organized Scheduler. Some place, where I can create event, select type of them, enable it, look for logs and etc.
The idea is to finish implementing Wiki Component, see https://github.com/xwiki-contrib/xwiki-platform-component-wiki Then we would retrofit wiki macros to use wiki component and we could have a specialized version for listeners too if we want but generally speaking you'll be able to register any component using a wiki page and objects. And they'll registered on startup. See also http://jira.xwiki.org/jira/browse/XWIKI-5195 Thanks -Vincent
vmassol wrote
... Then we would retrofit wiki macros to use wiki component and we could have a specialized version for listeners too if we want but generally speaking you'll be able to register any component using a wiki page and objects. And they'll registered on startup. ...
It will be great! Nice to see, that Platform XWiki have good developing speed! For example, In one of latest versions added possibility to reusing variables between scripts inside wiki page. As I imagining, for administrators and not deep developers (who programming in XWiki only inside wiki-pages) - this is a great feature!!! Thanks for the good news! Eugen Colesnicov -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
Ok, how about this: Is it possible to write an XWiki Macro which will loop through all the child pages of a given document and change the rights? (giving the child pages the same rights as the parent page) The Admin could add that macro to the parent page. Every time he changes the rights of that page, the macro will be executed and update the rights for every child page. Something like... {{velocity}} #if ($hasAdmin) ## read rights of this page... ## ... # foreach ($page in $pages) ## update rights of child page... ## ... # end #end {{/velocity}} -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
I should have searched the Extensions first... http://extensions.xwiki.org/xwiki/bin/view/Extension/Setting+Rights I guess we could use this as a starting point to read the $rightsObject of the current page and apply that $rightsObject to all the child pages...right? -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
Hamster wrote
I should have searched the Extensions first...
http://extensions.xwiki.org/xwiki/bin/view/Extension/Setting+Rights
I guess we could use this as a starting point to read the $rightsObject of the current page and apply that $rightsObject to all the child pages...right?
Yes, you are right ... but problem - HOW this portion of code WILL BE AUTOMATICALLY STARTED after each right changes? Need something like "trigger" ... For this need to use another example http://extensions.xwiki.org/xwiki/bin/view/Extension/Title+Post+Processing+U... This is another portion of code - Event Listener. But as I said, right now, this methodology have some problems (as explained vmassol, event listeners technology will be expanded soon). Temporary resolution - didn't make any special event listener (which will trigger your event), but include in page something like: #if ($context.action == "view") ... #end and inside put your code regarding to rights changing of a child pages. It means, that updating of all child pages rights will be before each viewing of a parent page... But it is a bad solution, especially if you have too much child pages or often simply opens parent. Process of opening parent page can be extremely slow. But it is possible to run this asynchronously (using ajax). Look this http://extensions.xwiki.org/xwiki/bin/view/Extension/Ajax+and+Show+Hide+Macr... -- Best regards Eugen Colesnicov -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
How can I "apply" or "set" the rightsobject? Here's what I have got: {{velocity}} #macro(setRightsSubPages $document $documentRightsObject) #set($translated = $document.getTranslatedDocument()) #set($name = $translated.getName()) #set($fullname = $translated.getFullName()) #set($prefixed = $translated.getPrefixedFullName()) #set($where = "where doc.parent = '$name' or doc.parent = '$fullname' or doc.parent = '$prefixed' order by doc.name") #if ($name == "WebHome") #set($space = $document.getSpace()) #set($where = "where doc.space = '$space' and (doc.parent = '' or doc.parent = '$name' or doc.parent = '$fullname' or doc.parent = '$prefixed') and doc.name != 'WebHome' order by doc.name") #end #foreach($name in $xwiki.searchDocuments($where)) #if ($xwiki.getDocument($name)) #set($document = $xwiki.getDocument($name)) #set ($rightsObject = $document.getObject("XWiki.XWikiRights", true)) ## HOW DO I COPY/APPLY/SET THE RIGHTS TO THIS OBJECT???? $rightsObject.set($documentRightsObject) ## Save the modifications $document.save() ## Call macro recursive #setRightsSubPages ($document $documentRightsObject) #end #end #end #if ($hasAdmin) #set ($rightsObject = $doc.getObject("XWiki.XWikiRights", true)) #setRightsSubPages($doc $rightsObject) #else You need to have Admin Rights to perform this action! #end {{/velocity}} -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
I still struggle with the code...anybody got a clue? -- View this message in context: http://xwiki.475771.n2.nabble.com/Apply-rights-automaticly-to-child-pages-tp... Sent from the XWiki- Users mailing list archive at Nabble.com.
participants (3)
-
Eugen Colesnicov -
Hamster -
Vincent Massol