From 1e969a750657e655076bcbfdcc2c6efb746f86ea Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Mon, 28 Nov 2016 15:06:05 +0100 Subject: [PATCH 01/13] added customization for logo and title --- client/configuration/config.js | 2 +- client/js/app.js | 5 ++++- client/js/controllers/loginController.js | 2 ++ client/js/controllers/sideBarController.js | 3 ++- client/views/login.pug | 8 ++++---- client/views/main.pug | 6 +++--- client/views/sidebar.pug | 2 +- config/default.json | 6 +++++- 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/client/configuration/config.js b/client/configuration/config.js index b808e1d..19ce507 100644 --- a/client/configuration/config.js +++ b/client/configuration/config.js @@ -1,5 +1,5 @@ angular.module('config', []) -.constant('ENV', {RequiresAuth:false,etcdHost:'127.0.0.1',etcdPort:'4001',hobknobHost:'localhost',hobknobPort:'3006',categories:[{id:0,name:'Simple Features',description:'Use when you want your feature to be either on or off'},{id:1,name:'Domain Features',description:'Use when you want your features to be toggled separately for different domains (e.g. com, couk, fr, ...)',values:['com','couk','de','fr']},{id:2,name:'Locale Features',description:'Use when you want your features to be toggled separately for different locales (e.g. en-GB, en-US, fr-FR, ...)',values:['en-GB','en-US','fr-FR','de-DE']}],plugin:{path:'../server/examplePlugin.js'},hooks:['server/exampleHook.js']}) +.constant('ENV', {RequiresAuth:false,dataSource:'etcd',etcdHost:'127.0.0.1',etcdPort:'4001',hobknobHost:'localhost',hobknobPort:'3006',loadBalancerFile:'/etc/lbstatus/hobknob',categories:[{id:0,name:'Simple Features',description:'Use when you want your feature to be either on or off'},{id:1,name:'Domain Features',description:'Use when you want your features to be toggled separately for different domains (e.g. com, couk, fr, ...)',values:['com','couk','de','fr']},{id:2,name:'Locale Features',description:'Use when you want your features to be toggled separately for different locales (e.g. en-GB, en-US, fr-FR, ...)',values:['en-GB','en-US','fr-FR','de-DE']}],plugin:{path:'../server/examplePlugin.js'},hooks:['server/exampleHook.js'],customization:{logo:'/img/veinteractive-hr-mono.png',title:'Opentable Feature Toggles'}}) ; \ No newline at end of file diff --git a/client/js/app.js b/client/js/app.js index 26678d8..83b65b0 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -26,6 +26,9 @@ featureToggleFrontend.config(function ($routeProvider, $locationProvider, $httpP $httpProvider.defaults.headers.post = {'Content-Type': 'application/json'}; }); -featureToggleFrontend.run(function (editableOptions) { +featureToggleFrontend.run(function ($rootScope, editableOptions, ENV) { editableOptions.theme = 'bs3'; + $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { + $rootScope.title = current.$$route.title ? current.$$route.title : ENV.customization.title; + }); }); diff --git a/client/js/controllers/loginController.js b/client/js/controllers/loginController.js index f60fb64..3002a94 100644 --- a/client/js/controllers/loginController.js +++ b/client/js/controllers/loginController.js @@ -1,6 +1,8 @@ 'use strict'; featureToggleFrontend.controller('LoginController', ['$scope', '$window', 'ENV', function ($scope, $window, ENV) { + $scope.logo = ENV.customization.logo; + if (ENV.RequiresAuth) { var authProvider = Object.keys(ENV.AuthProviders)[0]; diff --git a/client/js/controllers/sideBarController.js b/client/js/controllers/sideBarController.js index d8fa8ea..8d53c6f 100644 --- a/client/js/controllers/sideBarController.js +++ b/client/js/controllers/sideBarController.js @@ -1,10 +1,11 @@ 'use strict'; -featureToggleFrontend.controller('SideBarController', ['$scope', 'applicationService', 'authorisationService', '$location', 'focus', 'CurrentUser', function ($scope, applicationService, authorisationService, $location, focus, CurrentUser) { +featureToggleFrontend.controller('SideBarController', ['$scope', 'applicationService', 'authorisationService', '$location', 'focus', 'CurrentUser', 'ENV', function ($scope, applicationService, authorisationService, $location, focus, CurrentUser, ENV) { $scope.applications = []; $scope.newApplicationName = ''; $scope.adding = false; $scope.CurrentUser = CurrentUser; + $scope.logo = ENV.customization.logo; var loadApplications = function () { applicationService.getApplications( diff --git a/client/views/login.pug b/client/views/login.pug index 3a5dbe6..39eb8da 100644 --- a/client/views/login.pug +++ b/client/views/login.pug @@ -1,21 +1,21 @@ doctype html -html(lang='en') +html(lang='en' ng-app='featureToggleFrontend' ng-cloak) head meta(name='viewport', content='width=device-width, initial-scale=1') - title Hobknob Dashboard + title(ng-bind="$root.title") link(href='/bower_components/bootstrap/dist/css/bootstrap.min.css', media='all', rel='stylesheet') link(href='/css/dashboard.css', media='all', rel='stylesheet') link(href='/css/toggleswitch.css', media='all', rel='stylesheet') link(href='/bower_components/bootstrap-social/bootstrap-social.css', media='all', rel='stylesheet') link(href='/bower_components/font-awesome/css/font-awesome.css', media='all', rel='stylesheet') script(src='/bower_components/jquery/dist/jquery.min.js') - body(ng-app='featureToggleFrontend' ng-cloak) + body #wrapper #sidebar-wrapper ul.sidebar-nav(ng-controller="LoginController") li.sidebar-brand a.navbar-brand.logo(href='/') - img(src='/img/opentable-hr-mono.png') + img(ng-src='{{logo}}') a(href='/auth/google',ng-if="authProvider == 'GoogleAuth'", id="loginwithgoogle").btn.btn-block.btn-social.btn-google-plus.sign-in i.fa.fa-google-plus | Sign in with Google diff --git a/client/views/main.pug b/client/views/main.pug index cf85370..8b08094 100644 --- a/client/views/main.pug +++ b/client/views/main.pug @@ -1,8 +1,8 @@ doctype html -html(lang='en') +html(lang='en' ng-app='featureToggleFrontend') head meta(name='viewport', content='width=device-width, initial-scale=1') - title Hobknob Dashboard + title(ng-bind="$root.title") link(href='/bower_components/bootstrap/dist/css/bootstrap.min.css', media='all', rel='stylesheet') link(href='/css/dashboard.css', media='all', rel='stylesheet') link(href='/bower_components/angular-xeditable/dist/css/xeditable.css' rel='stylesheet') @@ -11,7 +11,7 @@ html(lang='en') script(src='/bower_components/jquery/dist/jquery.min.js') script(type="text/javascript"). window.user = !{JSON.stringify(user || {}, null, 2)}; - body(ng-app='featureToggleFrontend') + body #wrapper include ./sidebar.pug #page-content-wrapper diff --git a/client/views/sidebar.pug b/client/views/sidebar.pug index 0a1ad6a..837d11e 100644 --- a/client/views/sidebar.pug +++ b/client/views/sidebar.pug @@ -2,7 +2,7 @@ ul.sidebar-nav li.sidebar-brand a.navbar-brand.logo(href='/') - img(src='/img/opentable-hr-mono.png') + img(ng-src='{{logo}}') li .profile img.media-object.img-circle(ng-src='{{CurrentUser.getPicture()}}', alt='avatar') diff --git a/config/default.json b/config/default.json index 6f545ab..5a98bae 100644 --- a/config/default.json +++ b/config/default.json @@ -40,5 +40,9 @@ }, "hooks": [ "server/exampleHook.js" - ] + ], + "customization": { + "logo": "/img/veinteractive-hr-mono.png", + "title": "Opentable Feature Toggles" + } } From e591bbfc8be152611e950b95e08ff3356c8a3298 Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Mon, 28 Nov 2016 15:20:36 +0100 Subject: [PATCH 02/13] changed image path to the default one --- client/configuration/config.js | 2 +- config/default.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/configuration/config.js b/client/configuration/config.js index 19ce507..9fc6b97 100644 --- a/client/configuration/config.js +++ b/client/configuration/config.js @@ -1,5 +1,5 @@ angular.module('config', []) -.constant('ENV', {RequiresAuth:false,dataSource:'etcd',etcdHost:'127.0.0.1',etcdPort:'4001',hobknobHost:'localhost',hobknobPort:'3006',loadBalancerFile:'/etc/lbstatus/hobknob',categories:[{id:0,name:'Simple Features',description:'Use when you want your feature to be either on or off'},{id:1,name:'Domain Features',description:'Use when you want your features to be toggled separately for different domains (e.g. com, couk, fr, ...)',values:['com','couk','de','fr']},{id:2,name:'Locale Features',description:'Use when you want your features to be toggled separately for different locales (e.g. en-GB, en-US, fr-FR, ...)',values:['en-GB','en-US','fr-FR','de-DE']}],plugin:{path:'../server/examplePlugin.js'},hooks:['server/exampleHook.js'],customization:{logo:'/img/veinteractive-hr-mono.png',title:'Opentable Feature Toggles'}}) +.constant('ENV', {RequiresAuth:false,dataSource:'etcd',etcdHost:'127.0.0.1',etcdPort:'4001',hobknobHost:'localhost',hobknobPort:'3006',loadBalancerFile:'/etc/lbstatus/hobknob',categories:[{id:0,name:'Simple Features',description:'Use when you want your feature to be either on or off'},{id:1,name:'Domain Features',description:'Use when you want your features to be toggled separately for different domains (e.g. com, couk, fr, ...)',values:['com','couk','de','fr']},{id:2,name:'Locale Features',description:'Use when you want your features to be toggled separately for different locales (e.g. en-GB, en-US, fr-FR, ...)',values:['en-GB','en-US','fr-FR','de-DE']}],plugin:{path:'../server/examplePlugin.js'},hooks:['server/exampleHook.js'],customization:{logo:'/img/opentable-hr-mono.png',title:'Opentable Feature Toggles'}}) ; \ No newline at end of file diff --git a/config/default.json b/config/default.json index 5a98bae..8299693 100644 --- a/config/default.json +++ b/config/default.json @@ -42,7 +42,7 @@ "server/exampleHook.js" ], "customization": { - "logo": "/img/veinteractive-hr-mono.png", + "logo": "/img/opentable-hr-mono.png", "title": "Opentable Feature Toggles" } } From 14ef5e3ca1e0a8614c5d37343316d2f1d2377afe Mon Sep 17 00:00:00 2001 From: Ricardo Devis Agullo Date: Tue, 29 Nov 2016 09:03:26 +0100 Subject: [PATCH 03/13] shortened ternary --- client/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/js/app.js b/client/js/app.js index 83b65b0..82a2396 100644 --- a/client/js/app.js +++ b/client/js/app.js @@ -29,6 +29,6 @@ featureToggleFrontend.config(function ($routeProvider, $locationProvider, $httpP featureToggleFrontend.run(function ($rootScope, editableOptions, ENV) { editableOptions.theme = 'bs3'; $rootScope.$on('$routeChangeSuccess', function (event, current, previous) { - $rootScope.title = current.$$route.title ? current.$$route.title : ENV.customization.title; + $rootScope.title = current.$$route.title || ENV.customization.title; }); }); From b9b513aaed90846d5ae13398f792aa36841565d3 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 13:23:31 +0000 Subject: [PATCH 04/13] Formatting the config --- client/configuration/config.js | 35 +++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/client/configuration/config.js b/client/configuration/config.js index 9fc6b97..679e42a 100644 --- a/client/configuration/config.js +++ b/client/configuration/config.js @@ -1,5 +1,34 @@ angular.module('config', []) -.constant('ENV', {RequiresAuth:false,dataSource:'etcd',etcdHost:'127.0.0.1',etcdPort:'4001',hobknobHost:'localhost',hobknobPort:'3006',loadBalancerFile:'/etc/lbstatus/hobknob',categories:[{id:0,name:'Simple Features',description:'Use when you want your feature to be either on or off'},{id:1,name:'Domain Features',description:'Use when you want your features to be toggled separately for different domains (e.g. com, couk, fr, ...)',values:['com','couk','de','fr']},{id:2,name:'Locale Features',description:'Use when you want your features to be toggled separately for different locales (e.g. en-GB, en-US, fr-FR, ...)',values:['en-GB','en-US','fr-FR','de-DE']}],plugin:{path:'../server/examplePlugin.js'},hooks:['server/exampleHook.js'],customization:{logo:'/img/opentable-hr-mono.png',title:'Opentable Feature Toggles'}}) - -; \ No newline at end of file +.constant('ENV', { + RequiresAuth: false, + dataSource: 'etcd', + etcdHost: '127.0.0.1', + etcdPort: '4001', + hobknobHost: 'localhost', + hobknobPort: '3006', + loadBalancerFile: '/etc/lbstatus/hobknob', + categories: [{ + id: 0, + name: 'Simple Features', + description: 'Use when you want your feature to be either on or off' + }, { + id: 1, + name: 'Domain Features', + description: 'Use when you want your features to be toggled separately for different domains (e.g. com, couk, fr, ...)', + values: ['com', 'couk', 'de', 'fr'] + }, { + id: 2, + name: 'Locale Features', + description: 'Use when you want your features to be toggled separately for different locales (e.g. en-GB, en-US, fr-FR, ...)', + values: ['en-GB', 'en-US', 'fr-FR', 'de-DE'] + }], + plugin: { + path: '../server/examplePlugin.js' + }, + hooks: ['server/exampleHook.js'], + customization: { + logo: '/img/opentable-hr-mono.png', + title: 'Opentable Feature Toggles' + } +}); From a7264ab5bf5f3c608ce3a1ec7083e0a92f8075bf Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:26:23 +0000 Subject: [PATCH 05/13] Updating the etcd port / fixing the test --- config/default.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/default.json b/config/default.json index 8299693..27fc7e7 100644 --- a/config/default.json +++ b/config/default.json @@ -2,7 +2,7 @@ "RequiresAuth": false, "dataSource": "etcd", "etcdHost": "127.0.0.1", - "etcdPort": "4001", + "etcdPort": "2379", "hobknobHost": "localhost", "hobknobPort": "3006", "loadBalancerFile": "/etc/lbstatus/hobknob", @@ -43,6 +43,6 @@ ], "customization": { "logo": "/img/opentable-hr-mono.png", - "title": "Opentable Feature Toggles" + "title": "Hobknob Dashboard" } } From 2be97241f371e0ae95e5224e88db25c0fc5bd5b9 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:06:26 +0000 Subject: [PATCH 06/13] Moving the audit trail up a level --- server/domain/application.js | 33 ++++++++++++++++++++++++++++++- server/domain/etcd/application.js | 28 ++------------------------ 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/server/domain/application.js b/server/domain/application.js index 1bc75c8..ed3cd70 100644 --- a/server/domain/application.js +++ b/server/domain/application.js @@ -1,6 +1,9 @@ 'use strict'; var config = require('config'); +var audit = require('./audit'); +var acl = require('./acl'); + var application = function() { switch (config.dataSource.toLowerCase()) { case 'etcd': @@ -11,13 +14,41 @@ var application = function() { } }; +var getUserDetails = function (req) { + return config.RequiresAuth ? req.user._json : {name: 'Anonymous'}; +}; + module.exports = { getApplications: function (cb) { application().getApplications(cb); }, addApplication: function (applicationName, req, cb) { - application().addApplication(applicationName, req, cb); + application().addApplication(applicationName, req, function(err) { + if (err) { + return cb(err); + } + + audit.addApplicationAudit(getUserDetails(req), applicationName, 'Created', function () { + if (err) { + cb(err); + return; + } + }); + + if (config.RequiresAuth) { + var userEmail = getUserDetails(req).email.toLowerCase(); // todo: need better user management + acl.grant(userEmail, applicationName, function (grantErr) { + if (grantErr) { + cb(grantErr); + return; + } + cb(); + }); + } else { + cb(); + } + }); }, deleteApplication: function (applicationName, req, cb) { diff --git a/server/domain/etcd/application.js b/server/domain/etcd/application.js index 606c7b0..7b2f49c 100644 --- a/server/domain/etcd/application.js +++ b/server/domain/etcd/application.js @@ -31,32 +31,8 @@ module.exports = { }, addApplication: function (applicationName, req, cb) { - var path = 'v1/toggles/' + applicationName; - etcd.client.mkdir(path, function (err) { - if (err) { - return cb(err); - } - - audit.addApplicationAudit(getUserDetails(req), applicationName, 'Created', function () { - if (err) { - console.log(err); // todo: better logging - } - }); - - // todo: not sure if this is correct - if (config.RequiresAuth) { - var userEmail = getUserDetails(req).email.toLowerCase(); // todo: need better user management - acl.grant(userEmail, applicationName, function (grantErr) { - if (grantErr) { - cb(grantErr); - return; - } - cb(); - }); - } else { - cb(); - } - }); + var path = 'v1/toggles/' + applicationName; + etcd.client.mkdir(path, cb); }, deleteApplication: function (applicationName, req, cb) { From e9394ba0a8e63307a9b3eafd3f59d29ce75a6db6 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:08:07 +0000 Subject: [PATCH 07/13] Moving delete up.. --- server/domain/application.js | 23 ++++++++++++++++++++++- server/domain/etcd/application.js | 23 +---------------------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/server/domain/application.js b/server/domain/application.js index ed3cd70..6022c2c 100644 --- a/server/domain/application.js +++ b/server/domain/application.js @@ -52,7 +52,28 @@ module.exports = { }, deleteApplication: function (applicationName, req, cb) { - application().deleteApplication(applicationName, req, cb); + application().deleteApplication(applicationName, req, function (err) { + if (err) { + return cb(err); + } + + audit.addApplicationAudit(getUserDetails(req), applicationName, 'Deleted', function () { + if (err) { + console.log(err); + } + }); + + if (config.RequiresAuth) { + acl.revokeAll(applicationName, function (revokeErr) { + if (revokeErr) { + return cb(revokeErr); + } + cb(); + }); + } else { + cb(); + } + }); }, getApplicationMetaData: function (applicationName, cb) { diff --git a/server/domain/etcd/application.js b/server/domain/etcd/application.js index 7b2f49c..fe21096 100644 --- a/server/domain/etcd/application.js +++ b/server/domain/etcd/application.js @@ -37,28 +37,7 @@ module.exports = { deleteApplication: function (applicationName, req, cb) { var path = 'v1/toggles/' + applicationName; - etcd.client.delete(path, {recursive: true}, function (err) { - if (err) { - return cb(err); - } - - audit.addApplicationAudit(getUserDetails(req), applicationName, 'Deleted', function () { - if (err) { - console.log(err); - } - }); - - if (config.RequiresAuth) { - acl.revokeAll(applicationName, function (revokeErr) { - if (revokeErr) { - return cb(revokeErr); - } - cb(); - }); - } else { - cb(); - } - }); + etcd.client.delete(path, {recursive: true}, cb); }, getApplicationMetaData: function (applicationName, cb) { From 4f51efa7203a408b1a7e4b03bbd02dd27faa006b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:11:59 +0000 Subject: [PATCH 08/13] Adding a todo --- server/domain/etcd/feature.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/domain/etcd/feature.js b/server/domain/etcd/feature.js index 297b25c..ba47c3a 100644 --- a/server/domain/etcd/feature.js +++ b/server/domain/etcd/feature.js @@ -45,7 +45,7 @@ var getSimpleFeature = function (name, node, description) { description: description, values: [value], categoryId: 0, - fullPath: etcdBaseUrl + 'v1/toggles/' + name + fullPath: etcdBaseUrl + 'v1/toggles/' + name // TODO: determine why this is needed }; }; @@ -62,7 +62,7 @@ var getMultiFeature = function (name, node, metaData, categories, description) { description: description, values: values, categoryId: metaData.categoryId, - fullPath: etcdBaseUrl + 'v1/toggles/' + name + fullPath: etcdBaseUrl + 'v1/toggles/' + name // TODO: determine why this is needed }; }; From baa4bba95ae8aa414f80271f499778f165fadf78 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:22:27 +0000 Subject: [PATCH 09/13] Refactoring out the common logic --- server/domain/application.js | 13 ++++++------- server/domain/common.js | 7 +++++++ server/domain/etcd/application.js | 4 ---- 3 files changed, 13 insertions(+), 11 deletions(-) create mode 100644 server/domain/common.js diff --git a/server/domain/application.js b/server/domain/application.js index 6022c2c..de2a4b6 100644 --- a/server/domain/application.js +++ b/server/domain/application.js @@ -1,6 +1,7 @@ 'use strict'; var config = require('config'); +var common = require('./common'); var audit = require('./audit'); var acl = require('./acl'); @@ -14,10 +15,6 @@ var application = function() { } }; -var getUserDetails = function (req) { - return config.RequiresAuth ? req.user._json : {name: 'Anonymous'}; -}; - module.exports = { getApplications: function (cb) { application().getApplications(cb); @@ -29,7 +26,9 @@ module.exports = { return cb(err); } - audit.addApplicationAudit(getUserDetails(req), applicationName, 'Created', function () { + var userDetails = common.getUserDetails(req) + + audit.addApplicationAudit(userDetails, applicationName, 'Created', function () { if (err) { cb(err); return; @@ -37,7 +36,7 @@ module.exports = { }); if (config.RequiresAuth) { - var userEmail = getUserDetails(req).email.toLowerCase(); // todo: need better user management + var userEmail = userDetails.email.toLowerCase(); // todo: need better user management acl.grant(userEmail, applicationName, function (grantErr) { if (grantErr) { cb(grantErr); @@ -57,7 +56,7 @@ module.exports = { return cb(err); } - audit.addApplicationAudit(getUserDetails(req), applicationName, 'Deleted', function () { + audit.addApplicationAudit(common.getUserDetails(req), applicationName, 'Deleted', function () { if (err) { console.log(err); } diff --git a/server/domain/common.js b/server/domain/common.js new file mode 100644 index 0000000..6393237 --- /dev/null +++ b/server/domain/common.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + getUserDetails: function (req) { + return config.RequiresAuth ? req.user._json : {name: 'Anonymous'}; + } +}; diff --git a/server/domain/etcd/application.js b/server/domain/etcd/application.js index fe21096..074827f 100644 --- a/server/domain/etcd/application.js +++ b/server/domain/etcd/application.js @@ -7,10 +7,6 @@ var acl = require('../acl'); var audit = require('../audit'); var etcdBaseUrl = 'http://' + config.etcdHost + ':' + config.etcdPort + '/v2/keys/'; -var getUserDetails = function (req) { - return config.RequiresAuth ? req.user._json : {name: 'Anonymous'}; -}; - module.exports = { getApplications: function (cb) { etcd.client.get('v1/toggles/', {recursive: false}, function (err, result) { From 1549141152054c50e8e3cdd0260a9bde5ce43ab6 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:23:06 +0000 Subject: [PATCH 10/13] adding a todo --- server/app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/app.js b/server/app.js index a16cd37..a1d1778 100644 --- a/server/app.js +++ b/server/app.js @@ -95,6 +95,8 @@ var passportGoogleAuthenticateParams = function () { app.use(express.static(path.join(__dirname, '/../client'))); + +// TODO: all this can be moved out into routes/handlers app.get('/login', authenticateRoutes.login); app.get('/', ensureAuthenticatedOrRedirectToLogin, dashboardRoutes.dashboard); app.get('/partials/:name', dashboardRoutes.partials); From 908dce6c6d5f3f93645dfa0c0dd7826de7478fda Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:24:29 +0000 Subject: [PATCH 11/13] Consolidation --- server/domain/etcd/feature.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/server/domain/etcd/feature.js b/server/domain/etcd/feature.js index ba47c3a..2fdebd9 100644 --- a/server/domain/etcd/feature.js +++ b/server/domain/etcd/feature.js @@ -3,6 +3,7 @@ var etcd = require('./etcd'); var _ = require('underscore'); var config = require('config'); +var common = require('../common'); var acl = require('../acl'); var category = require('../category'); var etcdBaseUrl = 'http://' + config.etcdHost + ':' + config.etcdPort + '/v2/keys/'; @@ -13,10 +14,6 @@ var isMetaNode = function (node) { return s(node.key).endsWith('@meta'); }; -var getUserDetails = function (req) { - return config.RequiresAuth ? req.user._json : {name: 'Anonymous'}; -}; - var getMetaData = function (featureNode) { var metaNode = _.find(featureNode.nodes, function (n) { return isMetaNode(n); @@ -268,7 +265,7 @@ var addMultiFeature = function (path, applicationName, featureName, featureDescr hooks.run({ fn: 'addFeature', - user: getUserDetails(req), + user: common.getUserDetails(req), applicationName: applicationName, featureName: featureName, value: false @@ -288,7 +285,7 @@ var addSimpleFeature = function (path, applicationName, featureName, featureDesc hooks.run({ fn: 'addFeatureToggle', - user: getUserDetails(req), + user: common.getUserDetails(req), applicationName: applicationName, featureName: featureName, toggleName: null, @@ -325,7 +322,7 @@ module.exports.updateFeatureToggle = function (applicationName, featureName, val hooks.run({ fn: 'updateFeatureToggle', - user: getUserDetails(req), + user: common.getUserDetails(req), applicationName: applicationName, featureName: featureName, toggleName: null, @@ -350,7 +347,7 @@ module.exports.addFeatureToggle = function (applicationName, featureName, toggle hooks.run({ fn: 'addFeatureToggle', - user: getUserDetails(req), + user: common.getUserDetails(req), applicationName: applicationName, featureName: featureName, toggleName: toggleName, @@ -371,7 +368,7 @@ module.exports.updateFeatureMultiToggle = function (applicationName, featureName hooks.run({ fn: 'updateFeatureToggle', - user: getUserDetails(req), + user: common.getUserDetails(req), applicationName: applicationName, featureName: featureName, toggleName: toggleName, @@ -389,7 +386,7 @@ module.exports.deleteFeature = function (applicationName, featureName, req, cb) hooks.run({ fn: 'deleteFeature', - user: getUserDetails(req), + user: common.getUserDetails(req), applicationName: applicationName, featureName: featureName }); From a96e9dae1929de8ae87b58761cedcd7206b67c2c Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:30:17 +0000 Subject: [PATCH 12/13] Making the audit routes data source agnostic --- server/domain/etcd/audit.js | 10 ++++++++++ server/routes/auditRoutes.js | 8 -------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/server/domain/etcd/audit.js b/server/domain/etcd/audit.js index ab60054..45c8ef1 100644 --- a/server/domain/etcd/audit.js +++ b/server/domain/etcd/audit.js @@ -9,6 +9,11 @@ module.exports = { var path = 'v1/audit/application/' + applicationName; etcd.client.get(path, {recursive: true}, function (err, result) { if (err) { + if (err.errorCode === 100) { // key not found + callback(null, []); + return; + } + callback(err); return; } @@ -26,6 +31,11 @@ module.exports = { var path = 'v1/audit/feature/' + applicationName + '/' + featureName; etcd.client.get(path, {recursive: true}, function (err, result) { if (err) { + if (err.errorCode === 100) { // key not found + callback(null, []); + return; + } + callback(err); return; } diff --git a/server/routes/auditRoutes.js b/server/routes/auditRoutes.js index 9097178..e2def39 100644 --- a/server/routes/auditRoutes.js +++ b/server/routes/auditRoutes.js @@ -9,10 +9,6 @@ module.exports = { audit.getFeatureAuditTrail(applicationName, featureName, function (err, auditTrail) { if (err) { - if (err.errorCode === 100) { // key not found - res.send([]); - return; - } throw err; } res.send(auditTrail); @@ -24,10 +20,6 @@ module.exports = { audit.getApplicationAuditTrail(applicationName, function (err, auditTrail) { if (err) { - if (err.errorCode === 100) { // key not found - res.send([]); - return; - } throw err; } res.send(auditTrail); From fe1e3d6a8d5e7300d64ae03ad5f1dc9b462d23ee Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Sat, 31 Dec 2016 14:32:41 +0000 Subject: [PATCH 13/13] Helps if you include the library tbh --- server/domain/common.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/domain/common.js b/server/domain/common.js index 6393237..f8cda2f 100644 --- a/server/domain/common.js +++ b/server/domain/common.js @@ -1,5 +1,7 @@ 'use strict'; +var config = require('config'); + module.exports = { getUserDetails: function (req) { return config.RequiresAuth ? req.user._json : {name: 'Anonymous'};