Question

Dashboard Filter Injection for Multi Tenant Deployments

  • 14 January 2015
  • 0 replies
  • 180 views

Userlevel 4
Badge

###Use Case

Imagine we have a customer facing campaign metrics dashboard, which is global for all customers. We also have access_filter_fields (doc here) set on campaigns.id so that our customers can only see their respective campaigns.


The issue is that some of our customers have multiple campaigns, and that suggest_filters are disabled when access_filter_fields are used for security reasons.


###The Solution

We will build a table into the dashboard which lists the available campaigns for the user’s set of model_access_filter values, and using the html: parameter, the user will be able to filter the dashboard on the desired campaign name by clicking on the value in the table.


###View LookML

Let’s assume we are in the campaigns view, then we can use campaigns.id and campaigns.name to create a campaigns.name_with_link dimension. This dimension will utilize the html: parameter to create a link to the desired dashboard with an injected filter value of campaigns.id.


  - view: campaigns
fields:
- dimension: id
type: int
sql: ${TABLE}.id

- dimension: name
type: string
sql: ${TABLE}.name

- dimension: name_with_link
label: "Available Campaigns"
sql: ${name}
html: |
<a href="/dashboards/model_name/dashboard_name?filter_name={{ row['campaigns.id'] }}"
target="_self" onClick="javascript:document.location.reload(true)">{{ value }}</a>
required_fields: [id]

The second part of the html tag target="_self" onClick="javascript:document.location.reload(true)" will open and refresh the dashboard in the same tab, forcing the new filter values to be applied.


For a row[‘campaigns.id’] reference see this document. Since we will not have campaigns.id in the query where this dimension is going to be used, we need required_fields: [id]


When translating the above example, replace model_name, dashboard_name, and filter_name with your respective model, dashboard, and filter names.


###Dashboard LookML

The best way to utilize this field is to create a dashboard element which is a table of name_with_link values. It is also important that the filter we use is pointing to the field inside of row[‘view.field’], which in this case is campaigns.id. Also, make sure the desired elements in the dashboard have a listen: that points to campaign_id: campaigns.id


- dashboard: campaign_statistics
title: Campaign Overview
layout: grid
tile_size: 100

rows:
- height: 150
elements: [available_campaigns]

filters:

- name: campaign_id
type: number_filter
explore: campaigns
dimension: campaigns.id
default_value: "Please Choose A Campaign"

elements:

# AVAILABLE CAMPAIGNS

- name: available_campaigns
title: "Choose a Campaign"
type: table
model: model_name
explore: explore_name
dimensions: [campaigns.name_with_link]
sorts: [campaigns.name_with_link]
limit: 500

0 replies

Be the first to reply!

Reply