Module: Controllers::Base
- Extended by:
- ActiveSupport::Concern
- Included in:
- Account::Teams::ControllerBase, ApplicationController
- Defined in:
- app/controllers/concerns/controllers/base.rb
Instance Method Summary collapse
- #after_sign_in_path_for(resource_or_scope) ⇒ Object
- #after_sign_up_path_for(resource_or_scope) ⇒ Object
- #current_locale ⇒ Object
- #current_membership ⇒ Object
- #current_team ⇒ Object
- #delegate_json_to_api(&block) ⇒ Object
- #enforce_invitation_only ⇒ Object
-
#layout_by_resource ⇒ Object
this is an ugly hack, but it’s what is recommended at github.com/plataformatec/devise/wiki/How-To:-Create-custom-layouts.
-
#only_allow_path(path) ⇒ Object
Whitelist the account namespace and prevent JavaScript embedding when passing paths as parameters in links.
- #permitted_arrays ⇒ Object
- #permitted_fields ⇒ Object
- #process_params(strong_params) ⇒ Object
- #set_locale(&action) ⇒ Object
-
#set_sentry_context ⇒ Object
TODO Extract this into an optional ‘bullet_train-sentry` package.
Instance Method Details
#after_sign_in_path_for(resource_or_scope) ⇒ Object
58 59 60 61 |
# File 'app/controllers/concerns/controllers/base.rb', line 58 def after_sign_in_path_for(resource_or_scope) resource = resource_or_scope.class.name.downcase stored_location_for(resource) || account_dashboard_path end |
#after_sign_up_path_for(resource_or_scope) ⇒ Object
63 64 65 66 |
# File 'app/controllers/concerns/controllers/base.rb', line 63 def after_sign_up_path_for(resource_or_scope) resource = resource_or_scope.class.name.downcase stored_location_for(resource) || account_dashboard_path end |
#current_locale ⇒ Object
76 77 78 |
# File 'app/controllers/concerns/controllers/base.rb', line 76 def current_locale helpers.current_locale end |
#current_membership ⇒ Object
72 73 74 |
# File 'app/controllers/concerns/controllers/base.rb', line 72 def current_membership helpers.current_membership end |
#current_team ⇒ Object
68 69 70 |
# File 'app/controllers/concerns/controllers/base.rb', line 68 def current_team helpers.current_team end |
#delegate_json_to_api(&block) ⇒ Object
136 137 138 139 140 141 |
# File 'app/controllers/concerns/controllers/base.rb', line 136 def delegate_json_to_api(&block) respond_to do |format| format.html(&block) format.json { render "#{params[:controller].gsub(/^account\//, "api/#{BulletTrain::Api.current_version}/")}/#{params[:action]}" } end end |
#enforce_invitation_only ⇒ Object
80 81 82 83 84 85 86 |
# File 'app/controllers/concerns/controllers/base.rb', line 80 def enforce_invitation_only if invitation_only? unless helpers.invited? redirect_to [:account, :teams], notice: t("teams.notifications.invitation_only") end end end |
#layout_by_resource ⇒ Object
this is an ugly hack, but it’s what is recommended at github.com/plataformatec/devise/wiki/How-To:-Create-custom-layouts
50 51 52 53 54 55 56 |
# File 'app/controllers/concerns/controllers/base.rb', line 50 def layout_by_resource if devise_controller? "devise" else "public" end end |
#only_allow_path(path) ⇒ Object
Whitelist the account namespace and prevent JavaScript embedding when passing paths as parameters in links.
100 101 102 103 104 105 106 |
# File 'app/controllers/concerns/controllers/base.rb', line 100 def only_allow_path(path) return if path.nil? account_namespace_regexp = /^\/account\/*+/ scheme = URI.parse(path).scheme return nil unless path.match?(account_namespace_regexp) && scheme != "javascript" path end |
#permitted_arrays ⇒ Object
129 130 131 |
# File 'app/controllers/concerns/controllers/base.rb', line 129 def permitted_arrays {} end |
#permitted_fields ⇒ Object
125 126 127 |
# File 'app/controllers/concerns/controllers/base.rb', line 125 def permitted_fields [] end |
#process_params(strong_params) ⇒ Object
133 134 |
# File 'app/controllers/concerns/controllers/base.rb', line 133 def process_params(strong_params) end |
#set_locale(&action) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'app/controllers/concerns/controllers/base.rb', line 88 def set_locale(&action) locale = [ current_user&.locale, current_user&.current_team&.locale, http_accept_language.compatible_language_from(I18n.available_locales), I18n.default_locale.to_s ].compact.find { |potential_locale| I18n.available_locales.include?(potential_locale.to_sym) } I18n.with_locale(locale, &action) end |
#set_sentry_context ⇒ Object
TODO Extract this into an optional ‘bullet_train-sentry` package.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/controllers/concerns/controllers/base.rb', line 109 def set_sentry_context return unless ENV["SENTRY_DSN"] Sentry.configure_scope do |scope| scope.set_user(id: current_user.id, email: current_user.email) if current_user scope.set_context( "request", { url: request.url, params: params.to_unsafe_h } ) end end |