Pass userid into Application sharing code


#1

Hi,

I have a web portal where I store information about have multiple physical sites. I have many users who are restricted to operate one or multiple sites. I want to create a dashboard that would restrict user access only to their sites.

I had an idea if it would be possible to pass programmatically userid from my portal where I embed the dashboard into Metabase custom SQL query. This query would look up sites available to user and would limit the data only to what access the user has. Is there a way to pass a filter param from my portal into custom SQL of the metabase?
Can I use param in the Sharing ->Application code to resolve this?
var payload = {
resource: { dashboard: 1 },
params: {}
};


#2

@Sergej
Yes, using params is one way to do it, since it is where filters would be placed.
More info about embedding: https://www.metabase.com/docs/latest/administration-guide/13-embedding.html
Code examples for a few languages: https://github.com/metabase/embedding-reference-apps


#3

Thanks for this.
One more related question, is there a way to limit the list of values in the Field Filter? I.e. I have the list of many sites, but I want user see in the filter dropdown box only sites the user has access to?


#4

@Sergej
You should embed the cards (the questions) and control them with a your own select-options.
If you want a final solution, then Metabase Enterprise has feature called Sandboxing, which sounds to do what you’re looking for.
https://github.com/metabase/metabase/blob/master/docs/enterprise-guide/data-sandboxes.md


Passing username or user email as parameter in query or ask question
#5

Hi @flamber. If I want to develop the solution on my own, do I code the select filters separately and then pass the values into Metabase? In this case every time the value changes, I would pass it as param into Metabase and force a refresh. In the free version, I can’t restrict the values in my list?


#6

@Sergej
Correct, you need to code the select filters separately (outside of Metabase) and pass the values.