Class: ApplicationController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- ApplicationController
show all
- Includes:
- UrlHelper
- Defined in:
- app/controllers/application_controller.rb
Direct Known Subclasses
Api::V1::SprintTasksController, Api::V1::TicketTasksController, CommitsController, DeploysController, HomeController, HooksController, JobsController, OauthConsumersController, OmnibarController, ProjectExceptionsController, ProjectHooksController, ProjectOptionsController, ProjectPreticketsController, ProjectRolesController, ProjectTicketsController, ProjectTicketsSyncController, ProjectsController, ReleasesController, ReportsController, SettingsController, SprintTaskLocksController, SprintsController, TasksController, TestRunsController, TesterBarController, TestingNotesController, TestingReportController, TicketsController, UploadsController, UserCredentialsController, UserOptionsController, UsersController, WelcomeController
Instance Method Summary
collapse
Methods included from UrlHelper
#edit_release_path, #edit_release_url, #feature_path, #github_commit_range_url, #github_commit_url, #github_project_url, #github_url?, #goldmine_case_number_url, #link_to_project_feature, #new_release_url, #release_path, #release_url, #releases_path
Instance Method Details
#after_sign_in_path_for(user) ⇒ Object
71
72
73
74
75
|
# File 'app/controllers/application_controller.rb', line 71
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'app/controllers/application_controller.rb', line 106
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
132
133
134
|
# File 'app/controllers/application_controller.rb', line 132
def current_project
@current_project ||= @project || (@default_project_slug ? Project[@default_project_slug] : (current_user && current_user.current_project))
end
|
#expire_revision! ⇒ Object
84
85
86
87
88
89
|
# File 'app/controllers/application_controller.rb', line 84
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
125
126
127
128
129
|
# File 'app/controllers/application_controller.rb', line 125
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
149
150
151
152
153
|
# File 'app/controllers/application_controller.rb', line 149
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
|
#read_revision ⇒ Object
99
100
101
102
|
# File 'app/controllers/application_controller.rb', line 99
def read_revision
revision_path = Rails.root.join("REVISION")
File.exists?(revision_path) ? File.read(revision_path).chomp : ""
end
|
#require_login ⇒ Object
59
60
61
|
# File 'app/controllers/application_controller.rb', line 59
def require_login
redirect_to main_app.new_user_session_path
end
|
#return_or_cache_revision! ⇒ Object
91
92
93
94
95
96
97
|
# File 'app/controllers/application_controller.rb', line 91
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
79
80
81
82
|
# File 'app/controllers/application_controller.rb', line 79
def revision
expire_revision!
return_or_cache_revision!
end
|
#save_current_project ⇒ Object
140
141
142
143
144
145
|
# File 'app/controllers/application_controller.rb', line 140
def save_current_project
return unless current_user && current_project
current_user.current_project_id = current_project.id
current_user.save if current_user.current_project_id_changed?
end
|
#set_current_project ⇒ Object
136
137
138
|
# File 'app/controllers/application_controller.rb', line 136
def set_current_project
@default_project_slug = params[:project] if params[:project].is_a?(String)
end
|
#unfurling? ⇒ Boolean
65
66
67
|
# File 'app/controllers/application_controller.rb', line 65
def unfurling?
request.env["HTTP_USER_AGENT"] =~ /^Slackbot-LinkExpanding/
end
|