Creating Multiple Different Menus with Menu.Builder

139 views
Skip to first unread message

Antonio Martinez

unread,
Apr 18, 2011, 12:30:32 AM4/18/11
to lif...@googlegroups.com
Hello, I have run into a small problem with Menu.Builder when trying to separate my admin menus from my normal user menus. What I am trying to do is have a top menu bar with just the normal user menus and an admin link if the user is an admin that will take them to a page that has a sidebar with just the admin menus. What I currently have shows the admin link in the top bar regardless of superuser status (This one is probably because I set that link to locgroup admin and public in an attemp to show it in the top bar) but the ProtoUser menus disappear when I display only group public in the top bar. When you navigate to the admin page it shows the sidebar menu but it shows everything in the sitemap (except hidden ones) instead of just the admin menus. Here is my sitemap definition : 

val entries = List(Menu("Home") / "index" >> LocGroup("public"),
                       Menu("News and Jobs") / "NewsJobs" >> LocGroup("public") >> MustBeLoggedIn,
                       Menu("Messages and People") / "MessagesPeople" >> LocGroup("public") >> MustBeLoggedIn,
                       Menu("Profile temp link") / "profile" / "profile" >> LocGroup("public") >> Hidden,
                       Menu("Even or Job Listing") / "Listing" >> LocGroup("public") >> Hidden,
                       Menu("Admin") / "admin" / "index" >> MustBeLoggedIn >> LocGroup("admin") >> LocGroup("public"),
                       Menu("Message Control") / "admin" / "Message" >> MustBeLoggedIn >> LocGroup("admin") submenus(Message.menus : _*)) :::
                       User.menus // Is it possible to attach a locgroup here?

and here are the menu.builder calls

//in default.html
          <lift:Menu.builder group="public">// the top menu bar should only show normal user menus plus the admin link if superuser

//in the admin template
        <lift:Menu.builder group="public"> // the top menu bar should only show normal user menus plus the admin link if superuser 

        <span class="lift:Menu.builder" group="admin"></span>//the sidebar, should show only the admin specific menus

Thanks a lot for the help guys!

David Pollak

unread,
Apr 18, 2011, 8:50:29 AM4/18/11
to lif...@googlegroups.com
It's not easy... it requires walking a lot of menu items.  Please open a ticket for the issue and assign it to me for Lift 2.4-M1 (http://ticket.liftweb.net you must be a watcher of the LiftWeb space on Assembla).

If you need something before 2.4-M1 or can't upgrade to 2.4-M1, please let me know and I'll write up some code to walk menus and add MenuGroup to all the Locs in a List[Menu].

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



--
Lift, the simply functional web framework http://liftweb.net

Antonio Martinez

unread,
Apr 18, 2011, 12:13:00 PM4/18/11
to lif...@googlegroups.com
Ticket created : Ticket, I am also going to try to fix this myself. I was thinking that I could create a MenuGroup type and make if work like LocGroup. I'm looking into it now, but if you already have something started or done just let me know.

Antonio Martinez

unread,
Apr 18, 2011, 12:18:53 PM4/18/11
to lif...@googlegroups.com
One thing that I was wondering about before I started, is LocGroup supposed to function like what I wanted to happen? Because from what I can tell it is only ever used for discriminating user access to menus. I was considering trying to refactor it to UserGroup (the group property and the group method) and then have a MenuGroup at least inside of the Menu snippet, renaming LocGroup is probably not an option at the moment.

David Pollak

unread,
Apr 18, 2011, 12:30:24 PM4/18/11
to lif...@googlegroups.com
On Mon, Apr 18, 2011 at 9:18 AM, Antonio Martinez <anty...@gmail.com> wrote:
One thing that I was wondering about before I started, is LocGroup supposed to function like what I wanted to happen? Because from what I can tell it is only ever used for discriminating user access to menus. I was considering trying to refactor it to UserGroup (the group property and the group method) and then have a MenuGroup at least inside of the Menu snippet, renaming LocGroup is probably not an option at the moment.

LocGroup is a String that denotes what "group" the menu and its submenus are part of.  This is used for displaying different groups of menus in different places or contexts.  I think this is what you want.  This is not access control.
 

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.

Viktor Hedefalk

unread,
Apr 18, 2011, 5:53:49 PM4/18/11
to lif...@googlegroups.com
>User.menus // Is it possible to attach a locgroup here?

Maybe I'm totally misunderstanding here, but if you only want to attach a LocGroup for the User.menus that could be done by extending MegaProtoUser and overriding some *MenuLocParams:

override def loginMenuLocParams: List[LocParam[Unit]] =

    LocGroup("public") :: super.loginMenuLocParams


Adding LocGroups to a list of Locs would be a nice feature though.


I probably am misunderstanding here, but


shows the admin link in the top bar regardless of superuser status


Is MustBeLoggedIn enough here? I'm asking since you're using the same LocParam for the normal user entries, right? Wouldn't you need something that checked if the user is admin or not?


Antonio Martinez

unread,
Apr 18, 2011, 6:09:09 PM4/18/11
to lif...@googlegroups.com
Yes that is what I needed to find for ProtoUser thanks, and yes for the second problem i realized that I would also need some sort of MustBeAdmin check. Thanks

Antonio Martinez

unread,
Apr 18, 2011, 6:10:32 PM4/18/11
to lif...@googlegroups.com
Ok I think that I may have been thinking about this the wrong way, I am going to try it a little differently and see how it works, but I take it that from your original reaction there is something wrong with how Menu builder locgroups work?

Jeppe Nejsum Madsen

unread,
Apr 19, 2011, 3:40:51 AM4/19/11
to lif...@googlegroups.com
Antonio Martinez <anty...@gmail.com> writes:

ProtoUser.superUser_?

/Jeppe

Antonio Martinez

unread,
Apr 19, 2011, 12:40:02 PM4/19/11
to lif...@googlegroups.com
Alright so I fixed up my access control so the admin and user links are all ok now, however I've come back around to the original problem. I know that you said, David, that Locgroup is what I was looking for but it does not seem to work entirely as I expect it to. I could very well just be doing something wrong but on my admin page which has a top bar menu built with lift:Menu.builder group="public" and a sidebar menu built with <span class="lift:Menu.builder" group="admin"> the top bar shows the correct group of menus but the sidebar displays the entire sitemap. I thought that perhaps admin was a magic group for everything so I changed it to control but got the same results. Any ideas about what could be wrong? the current sitemap definition is 

val entries = List(Menu("Home") / "index" >> LocGroup("public"),
                       Menu("News and Jobs") / "NewsJobs" >> LocGroup("public") >> MustBeLoggedIn,
                       Menu("Messages and People") / "MessagesPeople" >> LocGroup("public") >> MustBeLoggedIn,
                       Menu("Profile temp link") / "profile" / "profile" >> LocGroup("public") >> Hidden,
                       Menu("Even or Job Listing") / "Listing" >> LocGroup("public") >> Hidden,
                       Menu("Admin") / "admin" / "index" >> MustBeLoggedIn >> MustBeAdmin >> LocGroup("public"),
                       Menu("Message Control") / "admin" / "Message" >> MustBeLoggedIn >> LocGroup("control") submenus(Message.menus : _*)) :::
                       User.menus

Thanks a lot for all the help guys

David Pollak

unread,
May 19, 2011, 8:05:47 PM5/19/11
to lif...@googlegroups.com
On Tue, Apr 19, 2011 at 9:40 AM, Antonio Martinez <anty...@gmail.com> wrote:
Alright so I fixed up my access control so the admin and user links are all ok now, however I've come back around to the original problem. I know that you said, David, that Locgroup is what I was looking for but it does not seem to work entirely as I expect it to. I could very well just be doing something wrong but on my admin page which has a top bar menu built with lift:Menu.builder group="public" and a sidebar menu built with <span class="lift:Menu.builder" group="admin"> the top bar shows the correct group of menus but the sidebar displays the entire sitemap. I thought that perhaps admin was a magic group for everything so I changed it to control but got the same results. Any ideas about what could be wrong? the current sitemap definition is 

Please post an example of the undesirable behavior (See Posting example code | Lift Space | Assembla ) so we can see why the LocGroup isn't being honored.
 

val entries = List(Menu("Home") / "index" >> LocGroup("public"),
                       Menu("News and Jobs") / "NewsJobs" >> LocGroup("public") >> MustBeLoggedIn,
                       Menu("Messages and People") / "MessagesPeople" >> LocGroup("public") >> MustBeLoggedIn,
                       Menu("Profile temp link") / "profile" / "profile" >> LocGroup("public") >> Hidden,
                       Menu("Even or Job Listing") / "Listing" >> LocGroup("public") >> Hidden,
                       Menu("Admin") / "admin" / "index" >> MustBeLoggedIn >> MustBeAdmin >> LocGroup("public"),
                       Menu("Message Control") / "admin" / "Message" >> MustBeLoggedIn >> LocGroup("control") submenus(Message.menus : _*)) :::
                       User.menus

Thanks a lot for all the help guys

--
You received this message because you are subscribed to the Google Groups "Lift" group.
To post to this group, send email to lif...@googlegroups.com.
To unsubscribe from this group, send email to liftweb+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/liftweb?hl=en.



--
Lift, the simply functional web framework http://liftweb.net
Reply all
Reply to author
Forward
0 new messages