Sha256: f2c81e41ff4796a68030059fb484077129c957adeac689c5c772e05a65d25f56

Contents?: true

Size: 1.26 KB

Versions: 5

Compression:

Stored size: 1.26 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
      @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
    # DELETE /impersonation/revert
    def destroy
      if current_impersonator
        user = current_user
        revert_impersonate
        if user
          flash[:notice] = "No longer impersonating #{user}"
        else
          flash[:notice] = "No longer impersonating a user"
        end
      else
        flash[:notice] = "You weren't impersonating anyone"
      end
      redirect_to '/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

5 entries across 5 versions & 1 rubygems

Version Path
mno-enterprise-api-2.0.4 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-2.0.3 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-2.0.2 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-2.0.1 app/controllers/mno_enterprise/impersonate_controller.rb
mno-enterprise-api-2.0.0 app/controllers/mno_enterprise/impersonate_controller.rb