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

@ -2,12 +2,12 @@
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require turbolinks

View File

@ -17,4 +17,4 @@
*
* app/assets
*= require_tree .
*/
*/

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

View File

@ -1,5 +1,5 @@
# frozen_string_literal: true
module ProformaXML
class ExerciseNotOwned < StandardError; end
class ExerciseNotOwned < ApplicationError; end
end

View File

@ -50,7 +50,7 @@ module ApplicationHelper
end
def render_markdown(markdown)
ActionController::Base.helpers.sanitize Kramdown::Document.new(markdown).to_html
ActionController::Base.helpers.sanitize Kramdown::Document.new(markdown).to_html.strip
end
def row(options = {}, &)

View File

@ -1,4 +0,0 @@
# frozen_string_literal: true
module ErrorTemplateAttributesHelper
end

View File

@ -1,4 +0,0 @@
# frozen_string_literal: true
module ErrorTemplatesHelper
end

View File

@ -0,0 +1,13 @@
# frozen_string_literal: true
# stolen from https://github.com/rails/rails/issues/25894#issuecomment-777516944
# this serializer can be used by a model to make sure the hash from a jsonb field can be accessed with symbols instead of string-keys.
class HashAsJsonbSerializer
def self.dump(hash)
hash
end
def self.load(hash)
hash.is_a?(Hash) ? hash.deep_symbolize_keys : {}
end
end

View File

@ -1,7 +1,7 @@
#flash-container.container
#flash.container.fixed_error_messages data-message-failure=t('shared.message_failure') data-websocket-failure=t('shared.websocket_failure')
- %w[alert danger info notice success warning].each do |severity|
- flash_mapping = {'alert' => 'warning', 'notice' => 'success'}
- ApplicationController._flash_types.each do |severity|
- flash_mapping = {alert: :warning, notice: :success}
div.alert.flash class="alert-#{flash_mapping.fetch(severity, severity)} alert-dismissible fade show"
p.mb-0 id="flash-#{severity}" == flash[severity]
button.btn-close type="button" data-bs-dismiss="alert" aria-label="Close"

View File

@ -9,10 +9,10 @@ html lang="#{I18n.locale || I18n.default_locale}" data-default-locale="#{I18n.de
= favicon_link_tag('/favicon.png', type: 'image/png')
= favicon_link_tag('/favicon.png', rel: 'apple-touch-icon', type: 'image/png')
= action_cable_meta_tag
= stylesheet_pack_tag('application', 'stylesheets', media: 'all', 'data-turbolinks-track': true, integrity: true, crossorigin: 'anonymous')
= stylesheet_link_tag('application', media: 'all', 'data-turbolinks-track': true, integrity: true, crossorigin: 'anonymous')
= javascript_pack_tag('application', 'data-turbolinks-track': true, defer: false, integrity: true, crossorigin: 'anonymous')
= javascript_include_tag('application', 'data-turbolinks-track': true, integrity: true, crossorigin: 'anonymous')
= stylesheet_pack_tag('application', 'stylesheets', media: 'all', 'data-turbolinks-track': 'reload', integrity: true, crossorigin: 'anonymous')
= stylesheet_link_tag('application', media: 'all', 'data-turbolinks-track': 'reload', integrity: true, crossorigin: 'anonymous')
= javascript_pack_tag('application', 'data-turbolinks-track': 'reload', defer: false, integrity: true, crossorigin: 'anonymous')
= javascript_include_tag('application', 'data-turbolinks-track': 'reload', integrity: true, crossorigin: 'anonymous')
= yield(:head)
= csrf_meta_tags
meta name='sentry' data-enabled=SentryJavascript.active?.to_s data-release=SentryJavascript.release data-dsn=SentryJavascript.dsn data-environment=SentryJavascript.environment
@ -25,7 +25,7 @@ html lang="#{I18n.locale || I18n.default_locale}" data-default-locale="#{I18n.de
.navbar-brand
i.fa-solid.fa-code
= application_name
button.navbar-toggler data-bs-target='#navbar-collapse' data-bs-toggle='collapse' type='button' aria-expanded='false' aria-label='Toggle navigation'
button.navbar-toggler data-bs-target='#navbar-collapse' data-bs-toggle='collapse' type='button' aria-expanded='false' aria-label='Toggle navigation' aria-controls='navbar-collapse'
span.navbar-toggler-icon
#navbar-collapse.collapse.navbar-collapse
= render('navigation', cached: true)