Pentaho

 View Only

 Get User Roles in RequireJs dashboards.

  • Pentaho
  • Ctools
  • Pentaho
David Martinez's profile image
David Martinez posted 07-30-2018 12:16

I need to get logged User info (name & roles) in RequireJs Dashboards.

It was so easy in non RequireJs ones, like this:

user = Dashboards.context.user; roles = Dashboards.context.roles;

But with requireJs checked I only can find user name:

user = requireCfg.config["pentaho/context"].user.id

How can I get user roles?


#Ctools
#Pentaho
Duarte Cunha Leao's profile image
Duarte Cunha Leao

Hi David,

it's equally as easy with a RequireJS dashboard, imo.

In a component method (e.g. preExecution), you can do, to get the user:

this.dashboard.context.user

To get the roles, you get the roles property instead:

this.dashboard.context.roles

See Dashboard - Pentaho Documentation  for more information.

Cheers

David Martinez's profile image
David Martinez

Hi Duarte,

It works fine from a component method as you said.

But, I was trying to get it from a javascript resource file, we will have a lot of dashboards and I don't want to have the same code in all of them.

I tried  to create a new Dashboard Object, expecting to have same session data in it without success.

 

require(["cdf/Dashboard"], function(Dashboard) {         var newDashboard = new Dashboard();         globalConf.roles = newDashboard.context.roles;     });

 

Another workarround, call a global function from a component method, I'm not happy at all with this because we still need to replicate call in all dashboards, find a component to hold in the call in every single dashboard and be carefull with execution order.

 

globalConf.requirejsGetRoles = function(dashboard){     globalConf.roles = dashboard.context.roles; }

 

¿alternatives?

Duarte Cunha Leao's profile image
Duarte Cunha Leao

Hi David,

You can have a shared utilities file.

The utility methods which need access to a dashboard or a component need to receive it as an argument (or as the JS this context).

In principle, this works because everywhere else you might need and call those utility methods you will be in the context of a method of a component or of a dashboard itself.

Cheers