Using role lookup keys

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsUsing role lookup keys
(Created page with "### Tutorial Setting up role lookup keys. ### Background A lookup key is simply a key-value pair that can be used as a value for record-level access control settings in a r...")
 
Line 8: Line 8:
  
 
### Example - Use lookup keys for record-level access control
 
### Example - Use lookup keys for record-level access control
 +
 +
Say we have field in a Account table called 'amount'. We want to ensure that users for a particular role, call it the 'Sales' role, can only create, read, update, and delete records with amount between 10000 and 20000 (i.e. records where 'amount' >= 10000 and 'amount' < 20000). We'd rather not hardcode the values in the filter. Instead, we'll use lookup keys to map to human-readable values that we can easily change if business rules change.
  
 
1. Log into the DreamFactory admin console as an Admin.
 
1. Log into the DreamFactory admin console as an Admin.
 
2. Click on 'Roles' > 'Create'.
 
2. Click on 'Roles' > 'Create'.
3. In the 'Access' tab, select your SQL database API for 'Service', the table name for 'Component', HTTP verbs for 'Access', and both API and Script for 'Requestor'. Repeat for each table and script you are exposing to this role. <br><br>
+
3. In the 'Lookup Keys' tab, click the plus button icon twice to create two lookup keys. Create the first lookup key with Name 'min' and Value '10000' and second lookup key with Name 'max' and Value '20000'.
 +
4. In the 'Access' tab, select your API for 'Service', the table name for 'Component' (here the Account table), HTTP verbs for 'Access' (here GET, POST, PUT, PATCH, DELETE), and API for 'Requestor'.  
 +
5. Click on Show/Hide under 'Advanced Filters', then click on the plus button icon to create two server-side filters. Create the first filter with Field 'amount' (this is a field in your Account table), Operator '>=', and Value '{min}' (this is the name of the lookup key name 'min', make sure to use curly brackets around the lookup key name). Create the second filter with Field 'amount' , Operator '<', and Value '{max}'.
  
In this example, we've exposed API access to the Contact table itself and also allowed event scripts to run for API calls to the Contact table.  
+
This ensures that any user with the 'Sales' role must 1) first authenticate to access the Account table; 2) can only create, read, update, and delete records in the Account table where the 'amount' field is between the lookup key values for 'min' and 'mx'. Note that you can add as many lookup keys and filter rules as you need.
  
 
<br>
 
<br>
  
[[File:Roles-api-plus-script.png|1000px]]
+
[[File:Roles-lookup-keys.png|1000px]]
 
+
### Example - Enable HTTP access to only event scripts for a role.
+
 
+
1. Log into the DreamFactory admin console as an Admin.
+
2. Click on 'Roles' > 'Create'.
+
3. In the 'Access' tab, select your SQL database API for 'Service', the table name for 'Component', HTTP verbs for 'Access', and Script for 'Requestor'. Repeat for each table and script you are exposing to this role. <br><br>
+
 
+
In this example, we've not exposed API access to the Contact table itself but have allowed event scripts to run for API calls to the Contact table.
+
 
+
<br>
+
  
[[File:Roles-script.png|1000px]]
+
[[File:Roles-lookup-keys-filter.png|1000px]]

Revision as of 21:10, 11 December 2015

      1. Tutorial

Setting up role lookup keys.

      1. Background

A lookup key is simply a key-value pair that can be used as a value for record-level access control settings in a role.

      1. Example - Use lookup keys for record-level access control

Say we have field in a Account table called 'amount'. We want to ensure that users for a particular role, call it the 'Sales' role, can only create, read, update, and delete records with amount between 10000 and 20000 (i.e. records where 'amount' >= 10000 and 'amount' < 20000). We'd rather not hardcode the values in the filter. Instead, we'll use lookup keys to map to human-readable values that we can easily change if business rules change.

1. Log into the DreamFactory admin console as an Admin. 2. Click on 'Roles' > 'Create'. 3. In the 'Lookup Keys' tab, click the plus button icon twice to create two lookup keys. Create the first lookup key with Name 'min' and Value '10000' and second lookup key with Name 'max' and Value '20000'. 4. In the 'Access' tab, select your API for 'Service', the table name for 'Component' (here the Account table), HTTP verbs for 'Access' (here GET, POST, PUT, PATCH, DELETE), and API for 'Requestor'. 5. Click on Show/Hide under 'Advanced Filters', then click on the plus button icon to create two server-side filters. Create the first filter with Field 'amount' (this is a field in your Account table), Operator '>=', and Value '{min}' (this is the name of the lookup key name 'min', make sure to use curly brackets around the lookup key name). Create the second filter with Field 'amount' , Operator '<', and Value '{max}'.

This ensures that any user with the 'Sales' role must 1) first authenticate to access the Account table; 2) can only create, read, update, and delete records in the Account table where the 'amount' field is between the lookup key values for 'min' and 'mx'. Note that you can add as many lookup keys and filter rules as you need.


Roles-lookup-keys.png

Roles-lookup-keys-filter.png