From d2566d649cbce159d46b78d8938b5cec5ae2f448 Mon Sep 17 00:00:00 2001 From: Henrik Nygren Date: Mon, 29 Jul 2024 14:07:22 +0300 Subject: [PATCH] Fixes --- Installation.md | 8 ++-- app/background_tasks/refresh_course_task.rb | 1 + .../migrate_to_other_course_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- app/models/available_point.rb | 2 + app/models/awarded_point.rb | 2 + app/models/submission.rb | 2 +- app/models/user.rb | 2 +- app/views/courses/_refresh_report.html.erb | 2 +- config/environments/development.rb | 3 ++ config/environments/production.rb | 2 + {app/models => lib}/point_comparison.rb | 0 lib/twitter_bootstrap_breadcrumbs.rb | 39 +++++++++++++++++++ 13 files changed, 58 insertions(+), 9 deletions(-) rename {app/models => lib}/point_comparison.rb (100%) create mode 100644 lib/twitter_bootstrap_breadcrumbs.rb diff --git a/Installation.md b/Installation.md index 2f2b864e1..2739c08b4 100644 --- a/Installation.md +++ b/Installation.md @@ -1,7 +1,7 @@ ## Setup ### Notices before installation -We assume you use [RVM](https://rvm.io/). If you don't, then replace `rvmsudo` with `sudo` during the installation process. +We assume you use [RVM](https://rvm.io/). If you don't, then replace `rvmsudo` with `sudo` during the installation process. > Note: Installation instructions works on WSL, but node needs to be installed according to [these](https://docs.microsoft.com/en-us/windows/nodejs/setup-on-wsl2) instructions. ### Installation instructions for Ubuntu We expect the user to be using account which name is tmc. @@ -24,7 +24,7 @@ RVM dependencies ```bash sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev ``` -ext/sandbox dependencies see [rage/sandbox](https://github.com/rage/sandbox) for latest deps +ext/sandbox dependencies see [rage/sandbox](https://github.com/rage/sandbox) for latest deps Requires docker to be installed aswell, read instructions [here](https://docs.docker.com/engine/install/ubuntu/). ``` sudo apt-get install tar zstd moreutils nodejs @@ -115,8 +115,8 @@ bundle install git submodule update --init --recursive ``` -You can view the site settings from the file `config/site.defaults.yml`. If you want to change the settings for the site, create a new file `config/site.yml` and define the changes there. -> Note: You do not need to copy the entire file. Settings not in `site.yml` will be looked up from `site.defaults.yml`. +You can view the site settings from the file `config/site.defaults.yml`. If you want to change the settings for the site, create a new file `config/site.yml` and define the changes there. +> Note: You do not need to copy the entire file. Settings not in `site.yml` will be looked up from `site.defaults.yml`. :exclamation: For development environment you can run command `cp config/site.dev.yml config/site.yml` Initialize the database with `bin/rails db:create db:migrate` diff --git a/app/background_tasks/refresh_course_task.rb b/app/background_tasks/refresh_course_task.rb index d9729b6b5..230194e1d 100644 --- a/app/background_tasks/refresh_course_task.rb +++ b/app/background_tasks/refresh_course_task.rb @@ -63,6 +63,7 @@ def wait_delay private def broadcast_to_channel(id, msg, percent, time, refresh_id = nil) + Rails.logger.info("Broadcasting message: #{msg} to channel CourseTemplateRefreshChannel-#{id}, Percent done: #{percent}, Time: #{time}, Course Template Refresh ID: #{refresh_id}") ActionCable.server.broadcast("CourseTemplateRefreshChannel-#{id}", { message: msg, percent_done: percent, diff --git a/app/controllers/migrate_to_other_course_controller.rb b/app/controllers/migrate_to_other_course_controller.rb index 29cce6f71..c293c84d0 100644 --- a/app/controllers/migrate_to_other_course_controller.rb +++ b/app/controllers/migrate_to_other_course_controller.rb @@ -11,7 +11,7 @@ def show @already_migrated = already_migrated @extra_alert_text = get_extra_text return respond_with_error('Please login to continue') if current_user.guest? - return respond_with_error('This migration is not allowed') unless StudentSubmissionMigrator.new(@old_course, @to_course, current_user).migration_is_allowed + respond_with_error('This migration is not allowed') unless StudentSubmissionMigrator.new(@old_course, @to_course, current_user).migration_is_allowed end def migrate diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f1c102983..acdc9ccef 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -80,7 +80,7 @@ def bs_labeled_field(label, field, options = {}) str << " #{field}#{label}" str << '' else - label_title = options[:label_title] ? options[:label_title] : nil + label_title = options[:label_title] || nil label = label_tag label, label_title, class: 'control-label' str += raw('
' + raw(label) + raw(field) + '
') end diff --git a/app/models/available_point.rb b/app/models/available_point.rb index 3a55f0e59..9a17b6636 100644 --- a/app/models/available_point.rb +++ b/app/models/available_point.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'point_comparison' + # Caches points that can be awarded from an exercise. # Awarded points don't have a hard reference to these because # these are recreated every time a course is refreshed. diff --git a/app/models/awarded_point.rb b/app/models/awarded_point.rb index 71af9c876..31bf1dbdd 100644 --- a/app/models/awarded_point.rb +++ b/app/models/awarded_point.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'point_comparison' + # Stores when a point (course_id, name) has been awared to a particular user. # # There is a reference to the submission that first awarded the point, but this diff --git a/app/models/submission.rb b/app/models/submission.rb index 7a7d25de7..178f909de 100644 --- a/app/models/submission.rb +++ b/app/models/submission.rb @@ -224,7 +224,7 @@ def test_case_records successful: tcr.successful?, message: tcr.message, exception: tcr.exception ? ActiveSupport::JSON.decode(tcr.exception) : nil, - detailed_message: tcr.detailed_message ? tcr.detailed_message : nil + detailed_message: tcr.detailed_message || nil } end end diff --git a/app/models/user.rb b/app/models/user.rb index 8989657bf..721e5c041 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -146,7 +146,7 @@ def self.authenticate(login, submitted_password) user = find_by(login: login) user ||= find_by('lower(email) = ?', login.downcase) return nil if user.nil? - return user if user.has_password?(submitted_password) + user if user.has_password?(submitted_password) end def password_reset_key diff --git a/app/views/courses/_refresh_report.html.erb b/app/views/courses/_refresh_report.html.erb index ee7ede2ea..e1d7c5d95 100644 --- a/app/views/courses/_refresh_report.html.erb +++ b/app/views/courses/_refresh_report.html.erb @@ -81,7 +81,7 @@ <% report.course_template_refresh_report['refresh_timings'].each do |k,v| %> <%= simple_format k.to_s.split("_").join(" ").capitalize(), {}, wrapper_tag: 'span' %> - <%= "%.3f" % v.real %> + <%= "%.3f" % v["real"] %> <% end %> diff --git a/config/environments/development.rb b/config/environments/development.rb index d9ecadd80..a3fe8ce12 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -58,4 +58,7 @@ else config.cache_store = :memory_store, { size: 64.megabytes } end + + + config.hosts << URI.parse(SiteSetting.value('baseurl_for_remote_sandboxes')).host end diff --git a/config/environments/production.rb b/config/environments/production.rb index b01a6f5f4..459bfdb5c 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -114,4 +114,6 @@ config.active_record.dump_schema_after_migration = false config.wkhtmltopdf = 'xvfb-run wkhtmltopdf' + + config.hosts << URI.parse(SiteSetting.value('baseurl_for_remote_sandboxes')).host end diff --git a/app/models/point_comparison.rb b/lib/point_comparison.rb similarity index 100% rename from app/models/point_comparison.rb rename to lib/point_comparison.rb diff --git a/lib/twitter_bootstrap_breadcrumbs.rb b/lib/twitter_bootstrap_breadcrumbs.rb new file mode 100644 index 000000000..1ed0cb7db --- /dev/null +++ b/lib/twitter_bootstrap_breadcrumbs.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +module BreadCrumbs + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def add_breadcrumb(name, url, options = {}) + class_name = self.name + before_action options do |controller| + name = controller.send :translate_breadcrumb, name, class_name if name.is_a?(Symbol) + controller.send :add_breadcrumb, name, url + end + end + end + + protected + def add_breadcrumb(name, url = '', options = {}) + @breadcrumbs ||= [] + name = translate_breadcrumb(name, self.class.name) if name.is_a?(Symbol) + url = eval(url.to_s) if url =~ /_path|_url|@/ # rubocop:disable Performance/RegexpMatch + @breadcrumbs << { name: name, url: url, options: options } + end + + def translate_breadcrumb(name, class_name) + scope = [:breadcrumbs] + namespace = class_name.underscore.split('/') + namespace.last.sub!('_controller', '') + scope += namespace + + I18n.t name, scope: scope + end + + def render_breadcrumbs(divider = '/') + s = render partial: 'twitter-bootstrap/breadcrumbs', locals: { divider: divider } + s.first + end +end