diff --git a/lib/api/entries/index.js b/lib/api/entries/index.js index 11e6033731e..6382e4fa2af 100644 --- a/lib/api/entries/index.js +++ b/lib/api/entries/index.js @@ -355,7 +355,7 @@ function configure (app, wares, ctx, env) { res.entries_err = err; return next(); }); - }, format_entries); + }, wares.obscure_device, format_entries); /** * @module get#/entries/:spec @@ -389,7 +389,7 @@ function configure (app, wares, ctx, env) { prepReqModel(req, req.params.model); query_models(req, res, next); } - }, format_entries); + }, wares.obscure_device, format_entries); /** * @module get#/entries @@ -400,7 +400,7 @@ function configure (app, wares, ctx, env) { * `find[date]`. * */ - api.get('/entries', ifModifiedSinceCTX, query_models, format_entries); + api.get('/entries', ifModifiedSinceCTX, query_models, wares.obscure_device, format_entries); /** * @function echo_query @@ -738,7 +738,7 @@ function configure (app, wares, ctx, env) { * @routed * @response 200 /definitions/Entries */ - api.get('/times/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, query_models, format_entries); + api.get('/times/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, prep_patterns, query_models, wares.obscure_device, format_entries); api.get('/count/:storage/where', prep_storage, count_records, format_results); @@ -753,7 +753,7 @@ function configure (app, wares, ctx, env) { /api/v1/slice/entries/dateString/mbg/2015.json ``` */ - api.get('/slice/:storage/:field/:type?/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, query_models, format_entries); + api.get('/slice/:storage/:field/:type?/:prefix?/:regex?', prep_storage, prep_pattern_field, prep_patterns, query_models, wares.obscure_device, format_entries); /** * @module post#/entries/preview @@ -765,7 +765,7 @@ function configure (app, wares, ctx, env) { // setting this flag tells insert_entries to not actually store the results req.persist_entries = false; next(); - }, insert_entries, format_entries); + }, insert_entries, wares.obscure_device, format_entries); // Protect endpoints with authenticated api. if (app.enabled('api')) { @@ -780,7 +780,7 @@ function configure (app, wares, ctx, env) { // setting this flag tells insert_entries to store the results req.persist_entries = true; next(); - }, insert_entries, format_entries); + }, insert_entries, wares.obscure_device, format_entries); /** * @module delete#/entries/:spec diff --git a/lib/data/dataloader.js b/lib/data/dataloader.js index 985ea259de5..dfb78eafde9 100644 --- a/lib/data/dataloader.js +++ b/lib/data/dataloader.js @@ -190,6 +190,7 @@ function loadEntries(ddata, ctx, callback) { } }; + var obscureDeviceProvenance = ctx.settings.obscureDeviceProvenance; ctx.entries.list(q, function(err, results) { if (err) { @@ -213,7 +214,7 @@ function loadEntries(ddata, ctx, callback) { _id: element._id, mgdl: Number(element.mbg), mills: element.date, - device: element.device, + device: obscureDeviceProvenance || element.device, type: 'mbg' }); } else if (element.sgv) { @@ -221,7 +222,7 @@ function loadEntries(ddata, ctx, callback) { _id: element._id, mgdl: Number(element.sgv), mills: element.date, - device: element.device, + device: obscureDeviceProvenance || element.device, direction: element.direction, filtered: element.filtered, unfiltered: element.unfiltered, diff --git a/lib/middleware/index.js b/lib/middleware/index.js index 7fea611fff0..7896d889a6d 100644 --- a/lib/middleware/index.js +++ b/lib/middleware/index.js @@ -3,7 +3,8 @@ var wares = { sendJSONStatus : require('./send-json-status'), bodyParser : require('body-parser'), - compression : require('compression') + compression : require('compression'), + obscureDeviceProvenance: require('./obscure-provenance') }; function extensions (list) { @@ -26,7 +27,8 @@ function configure (env) { limit: '1Mb' }), compression: wares.compression, - extensions: extensions + extensions: extensions, + obscure_device: wares.obscureDeviceProvenance(env) }; } diff --git a/lib/middleware/obscure-provenance.js b/lib/middleware/obscure-provenance.js new file mode 100644 index 00000000000..482cf20a8f0 --- /dev/null +++ b/lib/middleware/obscure-provenance.js @@ -0,0 +1,15 @@ +var _ = require('lodash'); + +module.exports = function create_device_obscurity (env) { + function obscure_device (req, res, next) { + if (res.entries && env.settings.obscureDeviceProvenance) { + var entries = _.cloneDeep(res.entries); + for (var i = 0; i < entries.length; i++) { + entries[i].device = env.settings.obscureDeviceProvenance; + } + res.entries = entries; + } + next( ); + } + return obscure_device; +} diff --git a/lib/sandbox.js b/lib/sandbox.js index c6bc20de0cf..85e0e86dc1d 100644 --- a/lib/sandbox.js +++ b/lib/sandbox.js @@ -235,10 +235,9 @@ function init () { }; sbx.displayBg = function displayBg (entry) { - var isDex = entry && (!entry.device || entry.device === 'dexcom' || entry.device === 'share2'); - if (isDex && Number(entry.mgdl) === 39) { + if (Number(entry.mgdl) === 39) { return 'LOW'; - } else if (isDex && Number(entry.mgdl) === 401) { + } else if (Number(entry.mgdl) === 401) { return 'HIGH'; } else { return sbx.scaleEntry(entry); diff --git a/lib/settings.js b/lib/settings.js index 32cf888e8c0..d538f226591 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -70,6 +70,8 @@ function init () { , frameName8: '' , authFailDelay: 5000 , adminNotifiesEnabled: true + , obscured: '' + , obscureDeviceProvenance: '' }; var secureSettings = [ @@ -78,6 +80,8 @@ function init () { , 'developerTeamId' , 'userName' , 'password' + , 'obscured' + , 'obscureDeviceProvenance' ]; var valueMappers = { @@ -129,6 +133,9 @@ function init () { function filteredSettings(settingsObject) { let so = _.cloneDeep(settingsObject); + if (so.obscured) { + so.enable = _.difference(so.enable, so.obscured); + } return filterObj(so, secureSettings); } @@ -244,6 +251,7 @@ function init () { var enable = getAndPrepare('enable'); var disable = getAndPrepare('disable'); + var obscured = getAndPrepare('obscured'); settings.alarmTypes = prepareAlarmTypes(); @@ -266,6 +274,7 @@ function init () { //all enabled feature, without any that have been disabled settings.enable = _.difference(enable, disable); + settings.obscured = obscured; var thresholds = settings.thresholds;