Node field level security

From DreamFactory
Jump to: navigation, search
DreamFactoryTutorialsNode field level security
(Created page with "Always remove some fields depending on the current role. API call returns 'tax_identifier' and 'date_of_birth' from the database. Before returning JSON content to the client,...")
 
Line 12: Line 12:
 
     var lodash = require('lodash.min.js');
 
     var lodash = require('lodash.min.js');
  
     event.response.content.resource.forEachfunction (record) {
+
     event.response.content.resource.forEach(function (record) {
  
 
         if (record.hasOwnProperty('tax_identifier')) {
 
         if (record.hasOwnProperty('tax_identifier')) {

Revision as of 14:13, 7 September 2016

Always remove some fields depending on the current role. API call returns 'tax_identifier' and 'date_of_birth' from the database. Before returning JSON content to the client, remove tax_identifier and date_of_birth.

For this change to take effect, you have to enable modification of response in the Admin Console script editor. Check the box 'Allow script to modify request (pre-process) or response (post-process)'.

// get.post_process
 
// check for your special role name that allows access
 
if (platform.sesssion.role.name !== 'admin') {
 
    var lodash = require('lodash.min.js');
 
    event.response.content.resource.forEach(function (record) {
 
        if (record.hasOwnProperty('tax_identifier')) {
            delete record.tax_identifier;
        }
 
        if (record.hasOwnProperty('date_of_birth')) {
            delete record.date_of_birth;
        }
    });
}