Module: ZuoraConnect::Controllers::Helpers
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/zuora_connect/controllers/helpers.rb
Instance Method Summary collapse
- #authenticate_app_api_request ⇒ Object
- #authenticate_connect_app_request ⇒ Object
- #check_connect_admin ⇒ Object
- #check_connect_admin! ⇒ Object
- #persist_connect_app_session ⇒ Object
Instance Method Details
#authenticate_app_api_request ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/zuora_connect/controllers/helpers.rb', line 7 def authenticate_app_api_request #Skip session for api requests Thread.current[:appinstance] = nil request.[:skip] = true start_time = Time.now if request.headers["API-Token"].present? @appinstance = ZuoraConnect::AppInstance.where(:api_token => request.headers["API-Token"]).first Rails.logger.debug("[#{@appinstance.id}] API REQUEST - API token") if @appinstance.present? check_instance else authenticate_or_request_with_http_basic do |username, password| @appinstance = ZuoraConnect::AppInstance.where(:token => password).first @appinstance ||= ZuoraConnect::AppInstance.where(:api_token => password).first Rails.logger.debug("[#{@appinstance.id}] API REQUEST - Basic Auth") if @appinstance.present? check_instance end end Rails.logger.info("[#{@appinstance.blank? ? "N/A" : @appinstance.id}] Authenticate App API Request Completed In - #{(Time.now - start_time).round(2)}s") end |
#authenticate_connect_app_request ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/zuora_connect/controllers/helpers.rb', line 27 def authenticate_connect_app_request Thread.current[:appinstance] = nil start_time = Time.now if ZuoraConnect.configuration.mode == "Production" if request["data"] setup_instance_via_data else setup_instance_via_session end else setup_instance_via_dev_mode end #Call .data_lookup with the current session to retrieve session. In some cases session may be stored/cache in redis #so data lookup provides a model method that can be overriden per app. if params[:controller] != 'zuora_connect/api/v1/app_instance' && params[:action] != 'drop' if @appinstance.new_session_for_ui_requests(:params => params) @appinstance.new_session(:session => @appinstance.data_lookup(:session => session)) end end PaperTrail.whodunnit = session["#{@appinstance.id}::user::email"] if defined?(PaperTrail) && session["#{@appinstance.id}::user::email"].present? begin I18n.locale = session["#{@appinstance.id}::user::locale"] ? session["#{@appinstance.id}::user::locale"] : @appinstance.locale rescue I18n::InvalidLocale => ex Rails.logger.error("Invalid Locale: #{ex.}") end Time.zone = session["#{@appinstance.id}::user::timezone"] ? session["#{@appinstance.id}::user::timezone"] : @appinstance.timezone Rails.logger.info("[#{@appinstance.blank? ? "N/A" : @appinstance.id}] Authenticate App Request Completed In - #{(Time.now - start_time).round(2)}s") end |
#check_connect_admin ⇒ Object
70 71 72 |
# File 'lib/zuora_connect/controllers/helpers.rb', line 70 def check_connect_admin return session["#{@appinstance.id}::admin"] end |
#check_connect_admin! ⇒ Object
66 67 68 |
# File 'lib/zuora_connect/controllers/helpers.rb', line 66 def check_connect_admin! raise ZuoraConnect::Exceptions::AccessDenied.new("User is not an authorized admin for this application") if !session["#{@appinstance.id}::admin"] end |
#persist_connect_app_session ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/zuora_connect/controllers/helpers.rb', line 56 def persist_connect_app_session if @appinstance.present? if defined?(Redis.current) @appinstance.cache_app_instance else session.merge!(@appinstance.save_data) end end end |