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::ProjectsController, Api::V1::SprintTasksController, Api::V1::TicketTasksController, CommitsController, DeploysController, Github::PullsController, HomeController, HooksController, JobsController, OauthConsumersController, OmnibarController, ProjectExceptionsController, ProjectHooksController, ProjectOptionsController, ProjectPreticketsController, ProjectRolesController, ProjectTestsController, 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
#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, #releases_path
Instance Method Details
#after_sign_in_path_for(user) ⇒ Object
74
75
76
77
78
|
# File 'app/controllers/application_controller.rb', line 74
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'app/controllers/application_controller.rb', line 109
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
135
136
137
|
# File 'app/controllers/application_controller.rb', line 135
def current_project
@current_project ||= @project || (@default_project_slug ? Project[@default_project_slug] : (current_user && current_user.current_project))
end
|
#expire_revision! ⇒ Object
87
88
89
90
91
92
|
# File 'app/controllers/application_controller.rb', line 87
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
128
129
130
131
132
|
# File 'app/controllers/application_controller.rb', line 128
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
152
153
154
155
156
|
# File 'app/controllers/application_controller.rb', line 152
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
102
103
104
105
|
# File 'app/controllers/application_controller.rb', line 102
def read_revision
revision_path = Rails.root.join("REVISION")
File.exists?(revision_path) ? File.read(revision_path).chomp : ""
end
|
#require_login ⇒ Object
62
63
64
|
# File 'app/controllers/application_controller.rb', line 62
def require_login
redirect_to main_app.new_user_session_path
end
|
#return_or_cache_revision! ⇒ Object
94
95
96
97
98
99
100
|
# File 'app/controllers/application_controller.rb', line 94
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
82
83
84
85
|
# File 'app/controllers/application_controller.rb', line 82
def revision
expire_revision!
return_or_cache_revision!
end
|
#save_current_project ⇒ Object
143
144
145
146
147
148
|
# File 'app/controllers/application_controller.rb', line 143
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
139
140
141
|
# File 'app/controllers/application_controller.rb', line 139
def set_current_project
@default_project_slug = params[:project] if params[:project].is_a?(String)
end
|
#unfurling? ⇒ Boolean
68
69
70
|
# File 'app/controllers/application_controller.rb', line 68
def unfurling?
request.env["HTTP_USER_AGENT"] =~ /^Slackbot-LinkExpanding/
end
|