Class: ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ApplicationController
show all
- Includes:
- UrlHelper
- Defined in:
- app/controllers/application_controller.rb
Direct Known Subclasses
ActionsController, Api::V1::MeasurementsController, Api::V1::ProjectsController, AuthorizationsController, ErrorsController, HomeController, HooksController, ProjectFollowsController, ProjectHooksController, ProjectOptionsController, ProjectsController, TeamsController, TriggersController, UploadsController, UserOptionsController, UsersController
Instance Method Summary
collapse
Methods included from UrlHelper
#feature_path, #link_to_project_feature
Instance Method Details
#after_sign_in_path_for(user) ⇒ Object
52
53
54
55
56
|
# File 'app/controllers/application_controller.rb', line 52
def after_sign_in_path_for(user)
path = session["user.redirect_to"] || stored_location_for(user) || root_path
path = root_path if path =~ /\/users\/(sign_in|password)/
path
end
|
#api_authenticate! ⇒ Object
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'app/controllers/application_controller.rb', line 87
def api_authenticate!
return if current_user
allow_params_authentication!
authenticate_or_request_with_http_basic do |username, password|
params["user"] ||= {}
params["user"].merge!(email: username, password: password)
user = warden.authenticate(scope: :user)
if user
sign_in(:user, user)
else
head :unauthorized
end
end
end
|
#current_project ⇒ Object
113
114
115
|
# File 'app/controllers/application_controller.rb', line 113
def current_project
@current_project ||= @project || (@default_project_slug ? Project[@default_project_slug] : (current_user && current_user.current_project))
end
|
#expire_revision! ⇒ Object
65
66
67
68
69
70
|
# File 'app/controllers/application_controller.rb', line 65
def expire_revision!
if session[:revision_expiration].blank? || session[:revision_expiration] < Time.now.utc
session[:revision] = nil
Rails.logger.info "[revision] expiring"
end
end
|
#followed_projects ⇒ Object
106
107
108
109
110
|
# File 'app/controllers/application_controller.rb', line 106
def followed_projects
return @followed_projects if defined?(@followed_projects)
return @followed_projects = [] unless current_user
@followed_projects = current_user.followed_projects.to_a
end
|
#no_cache ⇒ Object
139
140
141
142
143
|
# File 'app/controllers/application_controller.rb', line 139
def no_cache
response.["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
response.["Pragma"] = "no-cache"
response.["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
end
|
#oauth_authorize!(klass, scope:, redirect_to: nil) ⇒ Object
130
131
132
133
134
135
|
# File 'app/controllers/application_controller.rb', line 130
def oauth_authorize!(klass, scope:, redirect_to: nil)
authorization = klass.for(current_user).find_or_create_by!(scope: scope)
raise ArgumentError, "authorization already exists" if authorization.granted?
session["#{authorization.id}_granted_redirect_url"] = redirect_to if redirect_to
redirect_to authorization.url
end
|
#read_revision ⇒ Object
80
81
82
83
|
# File 'app/controllers/application_controller.rb', line 80
def read_revision
revision_path = Rails.root.join("REVISION")
File.exists?(revision_path) ? File.read(revision_path).chomp : ""
end
|
#require_login ⇒ Object
40
41
42
|
# File 'app/controllers/application_controller.rb', line 40
def require_login
redirect_to main_app.new_user_session_path
end
|
#return_or_cache_revision! ⇒ Object
72
73
74
75
76
77
78
|
# File 'app/controllers/application_controller.rb', line 72
def return_or_cache_revision!
session[:revision] || read_revision.tap do |sha|
session[:revision] = sha
session[:revision_expiration] = 3.minutes.from_now
Rails.logger.info "[revision] sha: #{sha[0..8]}, expiration: #{session[:revision_expiration]}"
end
end
|
#revision ⇒ Object
60
61
62
63
|
# File 'app/controllers/application_controller.rb', line 60
def revision
expire_revision!
return_or_cache_revision!
end
|
#unfurling? ⇒ Boolean
46
47
48
|
# File 'app/controllers/application_controller.rb', line 46
def unfurling?
request.env["HTTP_USER_AGENT"] =~ /^Slackbot-LinkExpanding/
end
|
#with_current_project ⇒ Object
117
118
119
120
121
122
123
124
125
126
|
# File 'app/controllers/application_controller.rb', line 117
def with_current_project
@default_project_slug = params[:project] if params[:project].is_a?(String)
yield
if current_user && current_project
current_user.current_project_id = current_project.id
current_user.save if current_user.current_project_id_changed?
end
end
|