From 117b170889391110e6433d7b94a48b27f26cecb9 Mon Sep 17 00:00:00 2001 From: Clement Date: Thu, 2 Mar 2017 13:33:53 +1100 Subject: [PATCH] [MNOE-362] - Code review --- api/config/routes.rb | 10 +++--- .../impersonate_controller_routing_spec.rb | 35 ++++++++++++++++--- .../install/templates/config/settings.yml | 6 +++- .../mnoe-users-local-list.coffee | 2 +- .../mnoe-users-local-list.html | 4 +-- .../src/app/views/user/user.controller.coffee | 2 +- frontend-admin/src/app/views/user/user.html | 2 +- 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/api/config/routes.rb b/api/config/routes.rb index 1fc42c80a..5bbb7da29 100644 --- a/api/config/routes.rb +++ b/api/config/routes.rb @@ -26,10 +26,10 @@ end end - - get "/impersonate/user/:user_id", to: "impersonate#create", as: :impersonate_user - get "/impersonate/revert", to: "impersonate#destroy", as: :revert_impersonate_user - + unless Settings.try(:admin_panel).try(:impersonation).try(:disabled) + get "/impersonate/user/:user_id", to: "impersonate#create", as: :impersonate_user + get "/impersonate/revert", to: "impersonate#destroy", as: :revert_impersonate_user + end #============================================================ # Devise/User Configuration @@ -95,7 +95,7 @@ member do %i(app_reviews app_feedbacks app_comments app_questions app_answers).each do |name| resources name, except: [:new, :edit], param: :review_id - end + end end end resource :current_user, only: [:show, :update] do diff --git a/api/spec/routing/mno_enterprise/impersonate_controller_routing_spec.rb b/api/spec/routing/mno_enterprise/impersonate_controller_routing_spec.rb index 68f255789..b210ce985 100644 --- a/api/spec/routing/mno_enterprise/impersonate_controller_routing_spec.rb +++ b/api/spec/routing/mno_enterprise/impersonate_controller_routing_spec.rb @@ -4,12 +4,39 @@ module MnoEnterprise RSpec.describe ImpersonateController, type: :routing do routes { MnoEnterprise::Engine.routes } - it "routes to #create" do - expect(get("/impersonate/user/1")).to route_to("mno_enterprise/impersonate#create", user_id: '1') + context "Impersonation is enabled" do + before(:all) do + Settings.merge!(admin_panel: {impersonation: {disabled: false}}) + Rails.application.reload_routes! + end + + + it "routes to #create" do + expect(get("/impersonate/user/1")).to route_to("mno_enterprise/impersonate#create", user_id: '1') + end + + it "routes to #destroy" do + expect(get("/impersonate/revert")).to route_to("mno_enterprise/impersonate#destroy") + end end - it "routes to #destroy" do - expect(get("/impersonate/revert")).to route_to("mno_enterprise/impersonate#destroy") + context "Impersonation is disabled" do + before(:all) do + Settings.merge!(admin_panel: {impersonation: {disabled: true}}) + Rails.application.reload_routes! + end + + it 'loads regular routes' do + expect(get('/ping')).to route_to('mno_enterprise/status#ping') + end + + it "does not route to #create" do + expect(get("/impersonate/user/1")).not_to be_routable + end + + it "does not route to #destroy" do + expect(get("/impersonate/revert")).not_to be_routable + end end end end diff --git a/core/lib/generators/mno_enterprise/install/templates/config/settings.yml b/core/lib/generators/mno_enterprise/install/templates/config/settings.yml index 9503ba874..c835a0890 100644 --- a/core/lib/generators/mno_enterprise/install/templates/config/settings.yml +++ b/core/lib/generators/mno_enterprise/install/templates/config/settings.yml @@ -24,7 +24,11 @@ developer: # Enable Reviews in the marketplace reviews: enabled: false - +# Enable comparison of apps marketplace: comparison: enabled: false +# Disable Impersonation +admin_panel: + impersonation: + disabled: false diff --git a/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.coffee b/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.coffee index 3d3f7f05c..d30dbea61 100644 --- a/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.coffee +++ b/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.coffee @@ -15,7 +15,7 @@ displayList: [] widgetTitle: 'Loading users...' search: '' - scope.disable_impersonation = ADMIN_PANEL_CONFIG.impersonation.disabled if ADMIN_PANEL_CONFIG.impersonation + scope.impersonation_enabled = if ADMIN_PANEL_CONFIG.impersonation then not ADMIN_PANEL_CONFIG.impersonation.disabled else true # Display all the users setAllUsersList = () -> diff --git a/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.html b/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.html index 7c64787e3..6c8a7cd94 100644 --- a/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.html +++ b/frontend-admin/src/app/components/mnoe-users-local-list/mnoe-users-local-list.html @@ -10,7 +10,7 @@ Username Creation Status - + @@ -34,7 +34,7 @@ Active - Log In as... + Log In as... diff --git a/frontend-admin/src/app/views/user/user.controller.coffee b/frontend-admin/src/app/views/user/user.controller.coffee index 17f0c60a8..cd36e2fa8 100644 --- a/frontend-admin/src/app/views/user/user.controller.coffee +++ b/frontend-admin/src/app/views/user/user.controller.coffee @@ -2,7 +2,7 @@ 'ngInject' vm = this - vm.disable_impersonation = ADMIN_PANEL_CONFIG.impersonation.disabled if ADMIN_PANEL_CONFIG.impersonation + vm.impersonation_enabled = if ADMIN_PANEL_CONFIG.impersonation then not ADMIN_PANEL_CONFIG.impersonation.disabled else true # Get the user MnoeUsers.get($stateParams.userId).then( diff --git a/frontend-admin/src/app/views/user/user.html b/frontend-admin/src/app/views/user/user.html index 91c511790..891fe3c3c 100644 --- a/frontend-admin/src/app/views/user/user.html +++ b/frontend-admin/src/app/views/user/user.html @@ -45,7 +45,7 @@

{{::vm.user.email}
-
+