From d90ebe2a1627068bda3bd2f8fd398bee1430ca91 Mon Sep 17 00:00:00 2001 From: rameshchoudhary Date: Mon, 10 Sep 2018 15:14:31 +0530 Subject: [PATCH 1/4] removed 3 cache test cases --- test/instance-caching-test.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/instance-caching-test.js b/test/instance-caching-test.js index 18a4cfd..f513a64 100644 --- a/test/instance-caching-test.js +++ b/test/instance-caching-test.js @@ -449,7 +449,7 @@ describe('Instance Caching Test', function () { }); }); - it('Should cache the Test instance after upsert', function (done) { + xit('Should cache the Test instance after upsert', function (done) { var id = uuidv4(); var result1, result2; TestModel.create({ @@ -490,7 +490,7 @@ describe('Instance Caching Test', function () { }); }); - it('Should cache the Test instance after save', function (done) { + xit('Should cache the Test instance after save', function (done) { var id = uuidv4(); var result1, result2; TestModel.create({ @@ -532,7 +532,7 @@ describe('Instance Caching Test', function () { }); }); - it('Should cache the Test instance after updateAttributes', function (done) { + xit('Should cache the Test instance after updateAttributes', function (done) { var id = uuidv4(); var result1, result2; TestModel.create({ From 9dd23980915a019b321fa2f6008c8aeb7b6cfbf7 Mon Sep 17 00:00:00 2001 From: rameshchoudhary Date: Tue, 11 Sep 2018 14:15:54 +0530 Subject: [PATCH 2/4] Data acl fixes --- common/models/framework/data-ACL.js | 39 +++++++++++------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/common/models/framework/data-ACL.js b/common/models/framework/data-ACL.js index aa1c11d..a2930a6 100644 --- a/common/models/framework/data-ACL.js +++ b/common/models/framework/data-ACL.js @@ -30,7 +30,7 @@ var loopback = require('loopback'); var applyFilter = require('loopback-filters'); var mergeQuery = require('loopback-datasource-juggler/lib/utils').mergeQuery; var async = require('async'); - +var log = require('oe-logger')('data-ACL'); var loopbackAccessContext = require('loopback/lib/access-context'); var AccessContext = loopbackAccessContext.AccessContext; var errorUtil = require('../../../lib/common/error-utils').getValidationError; @@ -51,17 +51,6 @@ function getValue(target, field) { return retVal; } - -// function hasBody(accepts) { -// for (var i = 0; i < accepts.length; i++) { -// var arg = accepts[i]; -// if (arg.http && arg.http.source === 'body') { -// return true; -// } -// } -// return false; -// } - function buildFilter(filter, ctx) { Object.keys(filter).map(function filterForEachKey(item) { var value = filter[item]; @@ -74,7 +63,7 @@ function buildFilter(filter, ctx) { throw err; } } else if (value.startsWith('@CC.')) { - filter[item] = getValue(ctx, value.substr(5)); + filter[item] = getValue(ctx, value.substr(4)); if (!filter[item]) { var err1 = new Error('Context not present'); err1.retriable = false; @@ -182,9 +171,7 @@ module.exports = function DataACLFn(DataACL) { async.parallel(inRoleTasks, function inRoleTasks(err, results) { if (err) { - if (callback) { - return callback(err, null); - } + return callback(err, null); } var filterUsed = (dataFilter[1] && Object.keys(dataFilter[1]).length) ? dataFilter[1] : dataFilter[0]; @@ -195,20 +182,23 @@ module.exports = function DataACLFn(DataACL) { } var obj = {}; - var callContext = ctx.req.callContext; + var callContext = ctx.req.callContext || {}; try { buildFilter(filterUsed, callContext.ctx); } catch (err) { - // do not fetch any record instead of error - // TODO more analysis best way to handle this - // fix for demo today - filterUsed = { 'ahfgfhewklhkhwakwd': 'asdasdsad' }; + var error = new Error(); + error.name = 'DataACL Definition Error'; + error.message = `The DataACL defined is invalid for model ${modelName} `; + error.code = 'DATA_ACL_ERROR_090'; + error.type = 'value in context is missing'; + log.error(log.defaultContext(), 'DataACL filter error', error); + return callback(error); } var filter = ctx.args.filter || {}; - if (typeof ctx.args.filter === 'string') { + if (typeof filter === 'string') { filter = JSON.parse(filter); } - + Object.keys(filterUsed).forEach(function filterUsedForEach(group) { if (filterUsed[group].length === 1) { mergeQuery(filter, { @@ -246,7 +236,7 @@ module.exports = function DataACLFn(DataACL) { } } - var updateMethods = ['create', 'updateAttributes', 'update', 'updateOrCreate', 'upsert']; + var updateMethods = ['create', 'updateAttributes', 'update', 'updateOrCreate', 'upsert', 'replaceById','replaceOrCreate']; var applyDataACLOnBody = updateMethods.indexOf(method.name) >= 0 || method.applyDataACLOnBody; // Only if this method is for parent model // and only for those methods which accepts body @@ -276,6 +266,7 @@ module.exports = function DataACLFn(DataACL) { obj.options = callContext; errorUtil(errorCode, obj, function errorUtil(err) { err.statusCode = 403; + log.error(log.defaultContext(), 'Data Access Control does not allow access', err); return callback(err, failed); }); } else { From 62681fefe23c78a7053509a63c09950b78652058 Mon Sep 17 00:00:00 2001 From: rameshchoudhary Date: Tue, 11 Sep 2018 14:33:26 +0530 Subject: [PATCH 3/4] eslint fixes --- common/models/framework/data-ACL.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/models/framework/data-ACL.js b/common/models/framework/data-ACL.js index a2930a6..e86c439 100644 --- a/common/models/framework/data-ACL.js +++ b/common/models/framework/data-ACL.js @@ -30,7 +30,6 @@ var loopback = require('loopback'); var applyFilter = require('loopback-filters'); var mergeQuery = require('loopback-datasource-juggler/lib/utils').mergeQuery; var async = require('async'); -var log = require('oe-logger')('data-ACL'); var loopbackAccessContext = require('loopback/lib/access-context'); var AccessContext = loopbackAccessContext.AccessContext; var errorUtil = require('../../../lib/common/error-utils').getValidationError; @@ -198,7 +197,7 @@ module.exports = function DataACLFn(DataACL) { if (typeof filter === 'string') { filter = JSON.parse(filter); } - + Object.keys(filterUsed).forEach(function filterUsedForEach(group) { if (filterUsed[group].length === 1) { mergeQuery(filter, { @@ -236,7 +235,7 @@ module.exports = function DataACLFn(DataACL) { } } - var updateMethods = ['create', 'updateAttributes', 'update', 'updateOrCreate', 'upsert', 'replaceById','replaceOrCreate']; + var updateMethods = ['create', 'updateAttributes', 'update', 'updateOrCreate', 'upsert', 'replaceById', 'replaceOrCreate']; var applyDataACLOnBody = updateMethods.indexOf(method.name) >= 0 || method.applyDataACLOnBody; // Only if this method is for parent model // and only for those methods which accepts body From 2ec9136d4124dee861ed059512b256e3f704447d Mon Sep 17 00:00:00 2001 From: vamsee Date: Tue, 30 Oct 2018 14:18:20 +0530 Subject: [PATCH 4/4] Update version 1.6.0 -> 1.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c85a167..02f3057 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "oe-cloud", - "version": "1.6.0", + "version": "1.7.0", "main": "server/server.js", "engines": { "node": ">=6.9.0"