Sha256: c053d2f0effc08c3a57ebcb4552c27a93731506620bb5921f3638f974354cb82

Contents?: true

Size: 1.16 KB

Versions: 8

Compression:

Stored size: 1.16 KB

Contents

module MnoEnterprise
  class ImpersonateController < ApplicationController
    include MnoEnterprise::ImpersonateHelper

    before_filter :authenticate_user!, except: [:destroy]
    before_filter :current_user_must_be_admin!, except: [:destroy]

    # Perform the user impersonate action
    # GET /impersonate/user/123
    def create
      session[:impersonator_redirect_path] = params[:redirect_path].presence
      @user = MnoEnterprise::User.find(params[:user_id])
      if @user.present?
        impersonate(@user)
      else
        flash[:notice] = "User doesn't exist"
      end
      redirect_to mnoe_home_path
    end

    # Revert the user impersonation
    # GET /impersonation/revert
    def destroy
      if current_impersonator
        # user = current_user
        revert_impersonate
      end
      redirect_to session.delete(:impersonator_redirect_path).presence || '/admin/'
    end

    private

    def current_user_must_be_admin!
      unless current_user.admin_role.present?
        flash[:error] = "You don't have access to this section."
        redirect_to :back
      end
    rescue ActionController::RedirectBackError
      redirect_to '/'
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
mno-enterprise-api-3.2.1 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-3.2.0 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-3.1.4 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-3.0.7 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-3.1.3 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-3.0.6 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-3.1.2 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-3.0.5 app/controllers/mno_enterprise/impersonate_controller.rb