current user in plugin example

50 views
Skip to first unread message

SydRa

unread,
May 19, 2021, 10:35:28 PM5/19/21
to trac-hacks
Hi everyone, 
I'm writing a plugin that is meant to show statistics specific to the current user. Everything works fine, but I cannot figure out how to determine the currently logged in user to filter the results. Is there a builtin user class of env variable that contains the current user ID?

Alternatively, I'm using ODIC authentication to get SSO with Office 365 on this trac, and it might be possible to get the user ID from a server environment variable. In php I'd do this with    usr = strstr($_SERVER['OIDC_CLAIM_upn'],'@',true);

Is there an equivalent in python?

Thanks!
Ralph

SydRa

unread,
May 20, 2021, 12:20:58 PM5/20/21
to trac-hacks
I figured it out... from the main macro call in: 

   def expand_macro(self, formatter, name, content):

formatter contains the session, and the session id is the login of the current user:

   user  = formatter.req.session.sid

Reply all
Reply to author
Forward
0 new messages