How to modify page rights with Velocity

Yan Rocheteau yan.rocheteau at monalsystems.com
Fri Dec 8 16:43:24 CET 2006


Hello,

I need to automatically set rights for a page with Velocity

I have some ideas on the way to do this : get the list of rights already set
for the page, check/modify them and eventually add more rights entries if
necessary.
The code will be something like :

      #set($rightindex=0)
      #set($rightsobjectslist=$doc.getObjects("XWiki.XWikiRights"))
      #foreach($rightsobject in $rightsobjectslist)
         current rights n°$rightindex are : groups=$rightsobject.groups
,users=$rightsobject.users , levels=$rightsobject.levels ,
allow=$rightsobject.allow;
         
         ##check if rights_0 exists and modify it
         #if ($rightindex==0)
 
#set($userobject=$xwiki.getDocument("XWiki.aXWikiUser").getObject("XWiki.XWi
kiUsers",0))
           #set($rightsobject.users=$userobject.name)
           modified users for rights_0 = $rightsobject.users
           (...)
         #end

         ##check if rights_1 exists and modify it
         #if ($rightindex==1)
           (...)
         #end

         #set($rightindex=$rightindex+1)

      #end

      #if($rightsobjectslist.size==1)
         ## create missing rights
      #end
      $doc.saveDocument()


My problem with this code is that the value of $rightsobject.users doesn't
change ! It is "XWiki.XWikiGuest" before the #set($rightsobject.users=...)
and it still is "XWiki.XWikiGuest" after ( instead of "XWiki.aXWikiUser" )

If somebody can help, it would be nice
Thanks

Yan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xwiki.org/pipermail/users/attachments/20061208/9b0b21b5/attachment-0001.htm 


More information about the users mailing list