Menu Application access for Unregistered Users

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Menu Application access for Unregistered Users

DeHaynes
I am in a private wiki site used for documentation.  You must be a user to see anything, so "Unregistered Users" can only see the login page.  On my wiki I am using the "Menu Application", which unregistered users do not have access to.  So on the login page there is an error "Failed to execute the [include] macro".  The long version says

org.xwiki.rendering.macro.MacroExecutionException: Current user [XWiki.XWikiGuest] doesn't have view rights on document [xwiki:Menu.Wiki Level Menu]

This is correct.  I don't want XWikiGuest to see the menu.  Any idea how I could get rid of the error?  

I tried searching and found references to xwiki.hasAccessLevel.   Am I on the right track?

I am using XWiki 5.4.2 with MySQL and Tomcat 7
Reply | Threaded
Open this post in threaded view
|

Re: Menu Application access for Unregistered Users

DeHaynes
I fixed this by modifying the Menu.MenuMacro in Object mode and then changing the code in the XWiki.WikiMacroClass.  I added a condition that looked to see if the user was a guest.  What I added is in bold below.


{{velocity}}
#set ($id = $xcontext.macro.params.id)
#set ($type = $xcontext.macro.params.type)
#set ($colorTheme = $xwiki.getUserPreference('colorTheme'))
#if ("$!colorTheme" != '')
  ## Make sure we use an absolute reference (see XWIKI-9672)
  #set ($colorTheme = $services.model.resolveDocument($colorTheme, $doc.documentReference))
#end
#set ($discard = $xwiki.ssx.use("$xcontext.macro.doc.prefixedFullName", {'colorTheme': $colorTheme}))
#set ($discard = $xwiki.jsx.use("$xcontext.macro.doc.prefixedFullName"))
(% #if ("$!id" != '') id="$id"#end class="menu menu-$!type" %)(((#if ($isGuest == false)
  $xcontext.macro.content
#end)))
{{/velocity}}
Reply | Threaded
Open this post in threaded view
|

Re: Menu Application access for Unregistered Users

Hamster
Thanks for sharing DeHaynes, we were having the same issue!
Reply | Threaded
Open this post in threaded view
|

Re: Menu Application access for Unregistered Users

Clemens Klein-Robbenhaar
In reply to this post by DeHaynes
On 02/28/2014 07:11 PM, DeHaynes wrote:

> I fixed it by modifying the code in Menu.MenuMacro.  I wrapped it in an
> if($isGuest) like this.
>
> {{velocity}}
> #if ($isGuest)
> #else
> #set ($id = $xcontext.macro.params.id)
> #set ($type = $xcontext.macro.params.type)
> #set ($colorTheme = $xwiki.getUserPreference('colorTheme'))
> #if ("$!colorTheme" != '')
>   ## Make sure we use an absolute reference (see XWIKI-9672)
>   #set ($colorTheme = $services.model.resolveDocument($colorTheme,
> $doc.documentReference))
> #end
> #set ($discard = $xwiki.ssx.use("$xcontext.macro.doc.prefixedFullName",
> {'colorTheme': $colorTheme}))
> #set ($discard = $xwiki.jsx.use("$xcontext.macro.doc.prefixedFullName"))
> (% #if ("$!id" != '') id="$id"#end class="menu menu-$!type" %)(((
>   $xcontext.macro.content
> )))
> #end
> {{/velocity}}
>
> Sorry, I don't know the scripting language well enough to do a ($isGuest) ==
> false.
>

#if (!$isGuest)

should do the trick :)

A slightly better check might be to see if the current user (who ever this is) has view rights on the document to be included,
via $xwiki.hasAccessLevel('view', $xcontext.userReference, <insert page ref here>)
But this seems to be in a different place, (and I have to admit I do not know the menu extension good enough to know where it is).
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users
Reply | Threaded
Open this post in threaded view
|

Re: Menu Application access for Unregistered Users

DeHaynes
This post was updated on .
Thank you.  I changed the code to:

{{velocity}}
#set ($id = $xcontext.macro.params.id)
#set ($type = $xcontext.macro.params.type)
#set ($colorTheme = $xwiki.getUserPreference('colorTheme'))
#if ("$!colorTheme" != '')
  ## Make sure we use an absolute reference (see XWIKI-9672)
  #set ($colorTheme = $services.model.resolveDocument($colorTheme, $doc.documentReference))
#end
#set ($discard = $xwiki.ssx.use("$xcontext.macro.doc.prefixedFullName", {'colorTheme': $colorTheme}))
#set ($discard = $xwiki.jsx.use("$xcontext.macro.doc.prefixedFullName"))
(% #if ("$!id" != '') id="$id"#end class="menu menu-$!type" %)(((#if ($xwiki.hasAccessLevel('view', $xcontext.userReference, 'Menu.MenuCode'))
  $xcontext.macro.content
#end)))
{{/velocity}}
Reply | Threaded
Open this post in threaded view
|

Re: Menu Application access for Unregistered Users

Marius Dumitru Florea
See http://jira.xwiki.org/browse/XWIKI-10171 . Check the changes in
the Commits tab.

On Mon, Mar 3, 2014 at 3:42 PM, DeHaynes <[hidden email]> wrote:

> Thank you.
>
>
>
> --
> View this message in context: http://xwiki.475771.n2.nabble.com/Menu-Application-access-for-Unregistered-Users-tp7589375p7589397.html
> Sent from the XWiki- Users mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.xwiki.org/mailman/listinfo/users