Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MNOE-360] - add flag for impersonating #239

Merged
merged 2 commits into from
Mar 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ angular.module('mnoEnterprise.configuration', [])
.constant('DEVELOPER_SECTION_CONFIG', <%= Hash(Settings.developer).to_json %>)
.constant('REVIEWS_CONFIG', <%= Hash(Settings.reviews).to_json %>)
.constant('MARKETPLACE_CONFIG', <%= Hash(Settings.marketplace).to_json %>)
.constant('ADMIN_PANEL_CONFIG', <%= Hash(Settings.admin_panel).to_json %>)
.constant('GOOGLE_TAG_CONTAINER_ID', <%= MnoEnterprise.google_tag_container.to_json %>)
.constant('INTERCOM_ID', <%= MnoEnterprise.intercom_app_id.to_json %>)
.constant('APP_NAME', <%= MnoEnterprise.app_name.to_json %>)
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,38 @@ 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
@@ -1,7 +1,7 @@
#
# Mnoe Users List
#
@App.directive('mnoeUsersLocalList', ($window, $filter, $log, toastr, MnoeUsers, MnoErrorsHandler) ->
@App.directive('mnoeUsersLocalList', ($window, $filter, $log, toastr, MnoeUsers, MnoErrorsHandler, ADMIN_PANEL_CONFIG) ->
restrict: 'E'
scope: {
list: '='
Expand All @@ -15,6 +15,7 @@
displayList: []
widgetTitle: 'Loading users...'
search: ''
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;"></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><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
4 changes: 3 additions & 1 deletion frontend-admin/src/app/views/user/user.controller.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@App.controller 'UserController', ($stateParams, $window, MnoeUsers) ->
@App.controller 'UserController', ($stateParams, $window, MnoeUsers, ADMIN_PANEL_CONFIG) ->
'ngInject'
vm = this

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(
(response) ->
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">
<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