Align project files with CodeHarbor

Since both projects are developed together and by the same team, we also want to have the same code structure and utility methods available in both projects. Therefore, this commit changes many files, but without a functional change.
This commit is contained in:
Sebastian Serth
2023-10-10 23:25:02 +02:00
parent fb3e8972d9
commit 99bd46af1a
112 changed files with 433 additions and 320 deletions

View File

@ -33,6 +33,31 @@ class ApplicationController < ActionController::Base
end
helper_method :current_contributor
def welcome
# Show root page
redirect_to ping_index_path if MONITORING_USER_AGENT.match?(request.user_agent)
end
private
def require_user!
raise Pundit::NotAuthorizedError unless current_user
end
def deny_access_from_render_host
raise Pundit::NotAuthorizedError if RENDER_HOST.present? && request.host == RENDER_HOST
end
def load_embed_options
@embed_options = if session[:embed_options].present? && session[:embed_options].is_a?(Hash)
session[:embed_options].symbolize_keys
else
{}
end
Sentry.set_extras(@embed_options)
@embed_options
end
def find_or_login_current_user
login_from_authentication_token ||
login_from_lti_session ||
@ -40,21 +65,6 @@ class ApplicationController < ActionController::Base
login_from_other_sources ||
nil
end
private :find_or_login_current_user
def require_user!
raise Pundit::NotAuthorizedError unless current_user
end
def mnemosyne_trace
yield
ensure
if ::Mnemosyne::Instrumenter.current_trace.present?
::Mnemosyne::Instrumenter.current_trace.meta['session_id'] = session[:session_id]
::Mnemosyne::Instrumenter.current_trace.meta['csrf_token'] = session[:_csrf_token]
::Mnemosyne::Instrumenter.current_trace.meta['external_user_id'] = session[:external_user_id]
end
end
def login_from_lti_session
return unless session[:external_user_id]
@ -81,12 +91,6 @@ class ApplicationController < ActionController::Base
end
end
def set_document_policy
# Instruct browsers to capture profiling data
response.set_header('Document-Policy', 'js-profiling')
end
private :set_document_policy
def set_sentry_context
return if current_user.blank?
@ -96,17 +100,19 @@ class ApplicationController < ActionController::Base
consumer: current_user.consumer&.name
)
end
private :set_sentry_context
def set_document_policy
# Instruct browsers to capture profiling data
response.set_header('Document-Policy', 'js-profiling')
end
def render_csrf_error
render_error t('sessions.expired'), :unprocessable_entity
end
private :render_csrf_error
def render_not_authorized
render_error t('application.not_authorized'), :unauthorized
end
private :render_not_authorized
def render_not_found
if current_user&.admin?
@ -115,7 +121,6 @@ class ApplicationController < ActionController::Base
render_not_authorized
end
end
private :render_not_authorized
def render_error(message, status)
set_sentry_context
@ -134,7 +139,16 @@ class ApplicationController < ActionController::Base
format.json { render json: {error: message}, status: }
end
end
private :render_error
def mnemosyne_trace
yield
ensure
if ::Mnemosyne::Instrumenter.current_trace.present?
::Mnemosyne::Instrumenter.current_trace.meta['session_id'] = session[:session_id]
::Mnemosyne::Instrumenter.current_trace.meta['csrf_token'] = session[:_csrf_token]
::Mnemosyne::Instrumenter.current_trace.meta['external_user_id'] = session[:external_user_id]
end
end
def switch_locale(&)
session[:locale] = sanitize_locale(params[:custom_locale] || params[:locale] || session[:locale])
@ -142,27 +156,6 @@ class ApplicationController < ActionController::Base
Sentry.set_extras(locale:)
I18n.with_locale(locale, &)
end
private :switch_locale
def deny_access_from_render_host
raise Pundit::NotAuthorizedError if RENDER_HOST.present? && request.host == RENDER_HOST
end
def welcome
# Show root page
redirect_to ping_index_path if MONITORING_USER_AGENT.match?(request.user_agent)
end
def load_embed_options
@embed_options = if session[:embed_options].present? && session[:embed_options].is_a?(Hash)
session[:embed_options].symbolize_keys
else
{}
end
Sentry.set_extras(@embed_options)
@embed_options
end
private :load_embed_options
# Sanitize given locale.
#
@ -176,5 +169,4 @@ class ApplicationController < ActionController::Base
locale
end
private :sanitize_locale
end