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

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 (resource_or_scope)
  resource = resource_or_scope.class.name.downcase
  stored_location_for(resource) || 
end

#after_sign_up_path_for(resource_or_scope) ⇒ Object



63
64
65
66
# File 'app/controllers/concerns/controllers/base.rb', line 63

def (resource_or_scope)
  resource = resource_or_scope.class.name.downcase
  stored_location_for(resource) || 
end

#current_localeObject



76
77
78
# File 'app/controllers/concerns/controllers/base.rb', line 76

def current_locale
  helpers.current_locale
end

#current_membershipObject



72
73
74
# File 'app/controllers/concerns/controllers/base.rb', line 72

def current_membership
  helpers.current_membership
end

#current_teamObject



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_onlyObject



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_resourceObject

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\/*+/
  scheme = URI.parse(path).scheme
  return nil unless path.match?() && scheme != "javascript"
  path
end

#permitted_arraysObject



129
130
131
# File 'app/controllers/concerns/controllers/base.rb', line 129

def permitted_arrays
  {}
end

#permitted_fieldsObject



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_contextObject

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