How to get all the menus of a user through program?

28 views
Skip to first unread message

Velu Narasimman

unread,
Jan 15, 2020, 11:54:17 PM1/15/20
to Trac Users
Hi,

    I am using MenusPlugin for displaying submenus. I need to get all the menus that are about to be displayed for a user even before he logs into the site.  Is it possible? If yes, how shall I do it in a back-end program? Please share me your ideas.

    Thanks in advance.

Velu Narasimman

unread,
Jan 16, 2020, 1:34:32 AM1/16/20
to Trac Users
Well, I am getting menu as a dictionary as shown below,

{'mainnav': [{'active': False, 'name': 'project', 'label': <Element "a">}, {'active': False, 'name': 'added_common', 'label': <Element "a">}, {'active': False, 'name': 'admin', 'label': <Element "a">}, {'active': False, 'name': 'reports', 'label': <Element "a">}, {'active': False, 'name': 'metrics', 'label': <Element "a">}, {'active': False, 'name': 'mytimesheet', 'label': <Element "a">}, {'active': True, 'name': 'myprojects', 'label': <Element "a">}, {'active': False, 'name': 'timesheetapproval', 'label': <Element "a">}], 'metanav': [{'active': False, 'name': 'login', 'label': u'logged in as karthikeyan.nagaraja'}, {'active': False, 'name': 'logout', 'label': <Element "a">}, {'active': False, 'name': 'prefs', 'label': <Element "a">}, {'active': False, 'name': 'about', 'label': <Element "a">}]}

I get this, when I refresh the web page in my browser. These menus are dynamic, differs among different users based on the permissions that they have in system. But I wish to generate this without using a browser. So how can I make a web request handling in program itself and the above menus?

Steffen Hoffmann

unread,
Jan 16, 2020, 5:03:36 AM1/16/20
to trac-...@googlegroups.com
So you know about XML-RPC-Plugin [1]?

IMHO this is the most standardized non-browser access to enabled Trac sites.

[1] https://trac-hacks.org/wiki/XmlRpcPlugin

Mit freundlichem Gruß

Steffen Hoffmann

Velu Narasimman

unread,
Jan 16, 2020, 8:13:53 AM1/16/20
to Trac Users
well how to use this plugin? I am unable to view any documentation for this. Please direct me and how can I get the menus with help of this plugin? give me some thoughts.

RjOllos

unread,
Jan 16, 2020, 2:29:21 PM1/16/20
to Trac Users


On Wednesday, January 15, 2020 at 10:34:32 PM UTC-8, Velu Narasimman wrote:
Well, I am getting menu as a dictionary as shown below,

{'mainnav': [{'active': False, 'name': 'project', 'label': <Element "a">}, {'active': False, 'name': 'added_common', 'label': <Element "a">}, {'active': False, 'name': 'admin', 'label': <Element "a">}, {'active': False, 'name': 'reports', 'label': <Element "a">}, {'active': False, 'name': 'metrics', 'label': <Element "a">}, {'active': False, 'name': 'mytimesheet', 'label': <Element "a">}, {'active': True, 'name': 'myprojects', 'label': <Element "a">}, {'active': False, 'name': 'timesheetapproval', 'label': <Element "a">}], 'metanav': [{'active': False, 'name': 'login', 'label': u'logged in as karthikeyan.nagaraja'}, {'active': False, 'name': 'logout', 'label': <Element "a">}, {'active': False, 'name': 'prefs', 'label': <Element "a">}, {'active': False, 'name': 'about', 'label': <Element "a">}]}

I get this, when I refresh the web page in my browser. These menus are dynamic, differs among different users based on the permissions that they have in system. But I wish to generate this without using a browser. So how can I make a web request handling in program itself and the above menus?

Are you calling Chrome.get_navigation_items?

You'll need to make a MockRequest. For examples, I believe this is done in a few plugins, but I don't recall which off-hand.

I suppose you could use MockRequest from the test module:

- Ryan

RjOllos

unread,
Jan 16, 2020, 7:02:00 PM1/16/20
to Trac Users
Or better might be to extract and modify this code to meet your needs:

With regard to the mock Request object, navigation contributors only check permissions like "PERM in req.perm", so your mock could just return True for that case.

- Ryan 

Velu Narasimman

unread,
Jan 17, 2020, 5:18:19 AM1/17/20
to Trac Users
I want to achieve this without making a HTTP request from browser. I guess the chrome.get_navigation_items will work only if there is a web request. Isn't it? Otherwise, I wish to make it without authenticating/bypassing authentication and everything within a python script file. Is this possible? Please share me your ideas.

Ryan Ollos

unread,
Jan 17, 2020, 11:40:51 AM1/17/20
to Trac Users
On Fri, Jan 17, 2020 at 2:18 AM Velu Narasimman <velava...@gmail.com> wrote:
I want to achieve this without making a HTTP request from browser. I guess the chrome.get_navigation_items will work only if there is a web request. Isn't it? Otherwise, I wish to make it without authenticating/bypassing authentication and everything within a python script file. Is this possible? Please share me your ideas.

Yes, you can use from Python. The samples shown are part of the Trac API. You'll need to Mock out the Request object. 
Reply all
Reply to author
Forward
0 new messages