Skip to content

Commit

Permalink
[MNOE-362] - Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
clemoberti committed Mar 2, 2017
1 parent 19b8b02 commit 117b170
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
10 changes: 5 additions & 5 deletions api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<th>Username</th>
<th style="width: 100px;">Creation</th>
<th style="width: 140px;">Status</th>
<th style="width: 100px;" ng-if="!disable_impersonation"></th>
<th style="width: 100px;" ng-if="impersonation_enabled"></th>
</tr>
</thead>
<tbody>
Expand All @@ -34,7 +34,7 @@
</button>
<span ng-show="user.status === 'active'">Active</span>
</td>
<td ng-if="!disable_impersonation"><a href="" ng-click="impersonateUser(user)">Log In as...</a></td>
<td ng-if="impersonation_enabled"><a href="" ng-click="impersonateUser(user)">Log In as...</a></td>
</tr>
</tbody>
</table>
Expand Down
2 changes: 1 addition & 1 deletion frontend-admin/src/app/views/user/user.controller.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion frontend-admin/src/app/views/user/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ <h3 ng-show="!user.name && !user.surname" class="panel-title">{{::vm.user.email}
</div>
</div>
<div class="bs-row">
<div class="col-sm-4 col-sm-offset-4" ng-if="!vm.disable_impersonation">
<div class="col-sm-4 col-sm-offset-4" ng-if="vm.impersonation_enabled">
<button class="btn btn-primary center-block"
ng-click="vm.impersonateUser()">Log In as User</button>
</div>
Expand Down

0 comments on commit 117b170

Please sign in to comment.