Hi China :), On 04/05/2011 05:38 PM, China Sunrise wrote: > Hi, > I'm relatively new to xwiki. I have a few pages where dynamic tables had to > be shown, and I'm using PHP quite heavily there. In a couple of pages, the > content is supposed to be shown only if the user is in a specific group > called 'XWikiEditorsGroup'. I didn't want to rely on xwiki's native > single-page permissions as they looked a little cumbersome for what I > needed, and preferred to control access via the page code itself. Up to > xwiki 2.7, the following velocity section, which was the first section in > the page, did the trick: > > {{velocity}} > #set($user=$xwiki.getUser()) > #if(!$user.isUserInGroup("XWiki.XWikiEditorsGroup")) > {{warning}}You don't have permission to view this document{{/warning}} > #stop > #end > {{/velocity}} I don`t know how the PHP macro(?) works, but why don`t you do something like:
{{velocity}} #set($user=$xwiki.getUser()) #if(!$user.isUserInGroup("XWiki.XWikiEditorsGroup")) {{warning}}You don't have permission to view this document{{/warning}} #else {{php}} do some php here. {{/php}} #end {{/velocity}} If you can nest the php macro into the velocity one, you are good to go and the code does not use velocity-dependent tricks. P.S.: On the other hand, I do recommend using XWiki's rights system. If you want to assign rights to multiple pages at once, do it at space level. You could also create a 'protected' space where you put all your protected pages that should be visible only to group X (so that you manage rights from a single -- space level -- point to avoid page level management). Hope this helps, Eduard > However, after upgrading to xwiki 3.0, this code no longer works. From what > I see, the issue appears to be related to velocity 1.7 and its different > syntax for the #stop directive. I can't seem to find the right syntax > though. As an alternative approach, I've also tried to relocate this access > control logic into the PHP code that follows the above velocity section. To > do that, I need to find a way to get the true/false value of > "$user.isUserInGroup("XWiki.XWikiEditorsGroup")" in PHP, but so far haven't > found a way to do that either and not sure how to pass the $user object and > its isUserInGroup() method to the PHP part. I've even looked into doing this > in groovy but no luck there either. > > Any advice will be appreciated... > > Thanks > _______________________________________________ > users mailing list > users@xwiki.org > http://lists.xwiki.org/mailman/listinfo/users > _______________________________________________ users mailing list users@xwiki.org http://lists.xwiki.org/mailman/listinfo/users