diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 909e1650..22562e79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: DATABASE_URL: "postgresql://postgres:postgres@localhost:5432" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: bundler-cache: true @@ -46,7 +46,10 @@ jobs: SCHEDULE_BACKUPS: 0 ISOLATE_ROOT: / ISOLATE_CGROUPS: false - ISOLATE_BRANCH: master + ISOLATE_BRANCH: v1.10.1 + + - name: Back up db/schema.rb # it will be overwritten when install.bash runs migrate.bash; back up the original so we can check if it's up to date + run: cp db/schema.rb db/schema.rb.git - run: AUTOCONFIRM=true script/install.bash env: @@ -57,12 +60,17 @@ jobs: #- run: bundle exec rake db:test:load # not required because script/install.bash runs db:migrate - run: bundle exec rspec + - name: Check that db/schema.rb is up to date + run: | + diff -u db/schema.rb.git db/schema.rb >&2 || + { echo "Error: db/schema.rb is out of date" >&2; exit 1; } + - uses: coverallsapp/github-action@v2 lint: runs-on: ubuntu-20.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: ruby/setup-ruby@v1 with: bundler-cache: true diff --git a/app/controllers/filelinks/roots_controller.rb b/app/controllers/filelinks/roots_controller.rb index 326333e4..eeb2dc75 100644 --- a/app/controllers/filelinks/roots_controller.rb +++ b/app/controllers/filelinks/roots_controller.rb @@ -80,11 +80,11 @@ def create self.model = load_model authorize model, :update? authorize FileAttachment.find(filelink_params[:file_attachment_id]), :use? - @new_file = model.filelinks.build(filelink_params) - if @new_file.save + @new_filelink = model.filelinks.build(filelink_params) + if @new_filelink.save redirect_to(index_path, :notice => "File attachment added") else - @files = model.filelinks.order(:filepath) + @filelinks = model.filelinks.order(:filepath) render :action => :index end end diff --git a/config/environments/production.rb b/config/environments/production.rb index a0951a24..28ed0955 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -33,7 +33,7 @@ # Disable Rails's static asset server # In production, Apache or nginx will already do this - config.serve_static_assets = true # true so Webrick testing of production mode works + config.serve_static_files = true # true so Webrick testing of production mode works # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" @@ -49,7 +49,7 @@ config.i18n.fallbacks = true # Send deprecation notices to registered listeners - config.active_support.deprecation = :notify + config.active_support.deprecation = :log # Compress JavaScript and CSS config.assets.compress = true diff --git a/config/environments/test.rb b/config/environments/test.rb index bfd1db47..05fc3f0d 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -34,7 +34,7 @@ config.active_support.deprecation = :stderr # Configure static asset server for tests with Cache-Control for performance - config.serve_static_assets = true + config.serve_static_files = true config.static_cache_control = "public, max-age=3600" # Raise exception on mass assignment protection for Active Record models diff --git a/db/schema.rb b/db/schema.rb index 29dea819..a096daf6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -16,7 +16,7 @@ # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" - create_table "contest_relations", force: true do |t| + create_table "contest_relations", force: :cascade do |t| t.integer "user_id" t.integer "contest_id" t.datetime "started_at" @@ -40,7 +40,7 @@ add_index "contest_relations", ["contest_id", "user_id"], name: "index_contest_relations_on_contest_id_and_user_id", unique: true, using: :btree add_index "contest_relations", ["user_id", "started_at"], name: "index_contest_relations_on_user_id_and_started_at", using: :btree - create_table "contest_scores", force: true do |t| + create_table "contest_scores", force: :cascade do |t| t.integer "contest_relation_id", null: false t.integer "problem_id", null: false t.integer "score" @@ -52,7 +52,7 @@ add_index "contest_scores", ["contest_relation_id", "problem_id"], name: "index_contest_scores_on_contest_relation_id_and_problem_id", using: :btree - create_table "contest_supervisors", force: true do |t| + create_table "contest_supervisors", force: :cascade do |t| t.integer "contest_id" t.integer "user_id" t.string "site_type" @@ -62,7 +62,7 @@ t.datetime "scheduled_start_time" end - create_table "contests", force: true do |t| + create_table "contests", force: :cascade do |t| t.string "name" t.datetime "start_time" t.datetime "end_time" @@ -80,13 +80,13 @@ t.boolean "only_rank_official_contestants", default: false end - create_table "entities", force: true do |t| + create_table "entities", force: :cascade do |t| t.string "name" t.integer "entity_id" t.string "entity_type" end - create_table "evaluators", force: true do |t| + create_table "evaluators", force: :cascade do |t| t.string "name", null: false t.text "description", default: "", null: false t.text "source", default: "", null: false @@ -95,7 +95,7 @@ t.datetime "updated_at" end - create_table "file_attachments", force: true do |t| + create_table "file_attachments", force: :cascade do |t| t.string "name" t.string "file_attachment" t.integer "owner_id" @@ -103,7 +103,7 @@ t.datetime "updated_at", null: false end - create_table "filelinks", force: true do |t| + create_table "filelinks", force: :cascade do |t| t.integer "root_id" t.integer "file_attachment_id" t.datetime "created_at" @@ -115,7 +115,7 @@ add_index "filelinks", ["file_attachment_id"], name: "index_filelinks_on_file_attachment_id", using: :btree add_index "filelinks", ["root_id", "filepath"], name: "index_filelinks_on_root_id_and_filepath", using: :btree - create_table "group_contests", force: true do |t| + create_table "group_contests", force: :cascade do |t| t.integer "group_id" t.integer "contest_id" end @@ -123,13 +123,13 @@ add_index "group_contests", ["contest_id", "group_id"], name: "index_group_contests_on_contest_id_and_group_id", using: :btree add_index "group_contests", ["group_id", "contest_id"], name: "index_group_contests_on_group_id_and_contest_id", using: :btree - create_table "group_memberships", force: true do |t| + create_table "group_memberships", force: :cascade do |t| t.integer "group_id" t.integer "member_id" t.datetime "created_at" end - create_table "group_problem_sets", force: true do |t| + create_table "group_problem_sets", force: :cascade do |t| t.integer "group_id" t.integer "problem_set_id" t.string "name" @@ -138,7 +138,7 @@ add_index "group_problem_sets", ["group_id", "problem_set_id"], name: "index_group_problem_sets_on_group_id_and_problem_set_id", using: :btree add_index "group_problem_sets", ["problem_set_id", "group_id"], name: "index_group_problem_sets_on_problem_set_id_and_group_id", using: :btree - create_table "groups", force: true do |t| + create_table "groups", force: :cascade do |t| t.string "name" t.datetime "created_at" t.datetime "updated_at" @@ -147,7 +147,7 @@ t.integer "membership", default: 0, null: false end - create_table "item_histories", force: true do |t| + create_table "item_histories", force: :cascade do |t| t.integer "item_id" t.boolean "active" t.integer "action" @@ -158,7 +158,7 @@ t.datetime "updated_at" end - create_table "items", force: true do |t| + create_table "items", force: :cascade do |t| t.integer "product_id" t.integer "owner_id" t.integer "organisation_id" @@ -170,7 +170,7 @@ t.integer "scan_token" end - create_table "language_groups", force: true do |t| + create_table "language_groups", force: :cascade do |t| t.string "identifier" t.string "name" t.integer "current_language_id" @@ -180,7 +180,7 @@ add_index "language_groups", ["identifier"], name: "index_language_groups_on_identifier", unique: true, using: :btree - create_table "languages", force: true do |t| + create_table "languages", force: :cascade do |t| t.string "identifier" t.string "compiler" t.boolean "interpreted" @@ -201,17 +201,17 @@ add_index "languages", ["identifier"], name: "index_languages_on_identifier", unique: true, using: :btree - create_table "organisations", force: true do |t| + create_table "organisations", force: :cascade do |t| end - create_table "problem_series", force: true do |t| + create_table "problem_series", force: :cascade do |t| t.string "name" t.string "identifier" t.string "importer_type" t.text "index_yaml" end - create_table "problem_set_problems", force: true do |t| + create_table "problem_set_problems", force: :cascade do |t| t.integer "problem_set_id" t.integer "problem_id" t.integer "problem_set_order" @@ -221,7 +221,7 @@ add_index "problem_set_problems", ["problem_id", "problem_set_id"], name: "index_problem_set_problems_on_problem_id_and_problem_set_id", using: :btree add_index "problem_set_problems", ["problem_set_id", "problem_id"], name: "index_problem_set_problems_on_problem_set_id_and_problem_id", using: :btree - create_table "problem_sets", force: true do |t| + create_table "problem_sets", force: :cascade do |t| t.string "name" t.integer "owner_id" t.datetime "created_at" @@ -229,7 +229,7 @@ t.integer "finalized_contests_count", default: 0 end - create_table "problems", force: true do |t| + create_table "problems", force: :cascade do |t| t.string "name" t.text "statement" t.string "input" @@ -246,44 +246,44 @@ t.integer "test_status", default: 0 end - create_table "products", force: true do |t| + create_table "products", force: :cascade do |t| t.string "name" t.integer "gtin", limit: 8 t.text "description" t.string "image" end - create_table "requests", force: true do |t| + create_table "requests", force: :cascade do |t| t.integer "requester_id" t.integer "subject_id" t.string "subject_type" - t.string "verb", null: false - t.integer "target_id", null: false - t.string "target_type", null: false - t.integer "status", default: 0, null: false + t.string "verb", null: false + t.integer "target_id", null: false + t.string "target_type", null: false + t.integer "status", default: 0, null: false t.integer "requestee_id" - t.datetime "expired_at", default: Infinity, null: false - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "expired_at", default: 'Infinity', null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "roles", force: true do |t| + create_table "roles", force: :cascade do |t| t.string "name" end - create_table "roles_users", id: false, force: true do |t| + create_table "roles_users", id: false, force: :cascade do |t| t.integer "role_id" t.integer "user_id" end - create_table "schools", force: true do |t| + create_table "schools", force: :cascade do |t| t.string "name" t.string "country_code", limit: 2 t.integer "users_count" t.integer "synonym_id" end - create_table "sessions", force: true do |t| + create_table "sessions", force: :cascade do |t| t.string "session_id", null: false t.text "data" t.datetime "created_at" @@ -294,14 +294,14 @@ add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree add_index "sessions", ["updated_at"], name: "index_sessions_on_updated_at", using: :btree - create_table "settings", force: true do |t| + create_table "settings", force: :cascade do |t| t.string "key" t.string "value" end add_index "settings", ["key"], name: "index_settings_on_key", unique: true, using: :btree - create_table "submissions", force: true do |t| + create_table "submissions", force: :cascade do |t| t.text "source" t.integer "score" t.integer "user_id" @@ -325,7 +325,7 @@ add_index "submissions", ["problem_id", "created_at"], name: "index_submissions_on_problem_id_and_created_at", using: :btree add_index "submissions", ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id", using: :btree - create_table "test_case_relations", force: true do |t| + create_table "test_case_relations", force: :cascade do |t| t.integer "test_case_id" t.integer "test_set_id" t.datetime "created_at", null: false @@ -335,7 +335,7 @@ add_index "test_case_relations", ["test_case_id"], name: "index_test_case_relations_on_test_case_id", using: :btree add_index "test_case_relations", ["test_set_id"], name: "index_test_case_relations_on_test_set_id", using: :btree - create_table "test_cases", force: true do |t| + create_table "test_cases", force: :cascade do |t| t.text "input" t.text "output" t.string "name" @@ -348,7 +348,7 @@ add_index "test_cases", ["problem_id", "name"], name: "index_test_cases_on_problem_id_and_name", unique: true, using: :btree - create_table "test_sets", force: true do |t| + create_table "test_sets", force: :cascade do |t| t.integer "problem_id" t.integer "points" t.string "name" @@ -360,7 +360,7 @@ add_index "test_sets", ["problem_id", "name"], name: "index_test_sets_on_problem_id_and_name", unique: true, using: :btree - create_table "user_problem_relations", force: true do |t| + create_table "user_problem_relations", force: :cascade do |t| t.integer "problem_id" t.integer "user_id" t.integer "submissions_count" @@ -376,7 +376,7 @@ add_index "user_problem_relations", ["problem_id", "ranked_score"], name: "index_user_problem_relations_on_problem_id_and_ranked_score", using: :btree add_index "user_problem_relations", ["user_id", "problem_id"], name: "index_user_problem_relations_on_user_id_and_problem_id", unique: true, using: :btree - create_table "users", force: true do |t| + create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" diff --git a/script/install.bash b/script/install.bash index 55139df6..ce1f17f9 100755 --- a/script/install.bash +++ b/script/install.bash @@ -40,8 +40,6 @@ bash script/install/nztrain.bash || exit 1 # fix files & directory structure bash script/install/bundler.bash || exit 1 -bash script/install/nokogiri.bash || exit 1 # nokogiri dependencies - bash script/install/jre.bash || exit 1 # required by yui-compressor sudo bash script/install/isolate.bash || exit 1 # install isolate diff --git a/script/install/config.bash b/script/install/config.bash index 62d830dd..250231f4 100644 --- a/script/install/config.bash +++ b/script/install/config.bash @@ -203,7 +203,7 @@ declare -p ISOLATE_CGROUPS &> /dev/null || while [ -z "$ISOLATE_CGROUPS" ] ; do else ISOLATE_CGROUPS=false; fi done -declare -p ISOLATE_BRANCH &> /dev/null || ISOLATE_BRANCH=master # no prompt +declare -p ISOLATE_BRANCH &> /dev/null || ISOLATE_BRANCH=v1.10.1 # no prompt shopt -u nocasematch; diff --git a/script/install/debootstrap.bash b/script/install/debootstrap.bash index 187415dc..4fa725a3 100644 --- a/script/install/debootstrap.bash +++ b/script/install/debootstrap.bash @@ -113,17 +113,20 @@ chroot "$ISOLATE_ROOT" apt-get install ruby # Ruby (ruby) # LD_ORIGIN_PATH.) } -if ! chroot "$ISOLATE_ROOT" apt-cache show openjdk-11-jdk &>/dev/null; then - # add java ppa - echo "$chroot_cmd add-apt-repository ppa:openjdk-r/ppa -y" - chroot "$ISOLATE_ROOT" add-apt-repository ppa:openjdk-r/ppa -y - - echo "$chroot_cmd apt-get update" - chroot "$ISOLATE_ROOT" apt-get update -fi +[ -z "$CI" ] && { # if not in CI + # Java + if ! chroot "$ISOLATE_ROOT" apt-cache show openjdk-11-jdk-headless &>/dev/null; then + # add java ppa + echo "$chroot_cmd add-apt-repository ppa:openjdk-r/ppa -y" + chroot "$ISOLATE_ROOT" add-apt-repository ppa:openjdk-r/ppa -y + + echo "$chroot_cmd apt-get update" + chroot "$ISOLATE_ROOT" apt-get update + fi -echo "$chroot_install openjdk-11-jdk" -chroot "$ISOLATE_ROOT" apt-get install openjdk-11-jdk # Java + echo "$chroot_install openjdk-11-jdk-headless" + chroot "$ISOLATE_ROOT" apt-get install openjdk-11-jdk-headless # Java +} [ -z "$CI" ] && { # if not in CI @@ -145,20 +148,21 @@ chroot "$ISOLATE_ROOT" apt-get install openjdk-11-jdk # Java chroot "$ISOLATE_ROOT" apt-get install ruby2.2 - ## INSTALL J - chroot "$ISOLATE_ROOT" mkdir /home/j -p - J_TAG="J803" - J_DEB="j803_amd64.deb" - J_SAVE="/home/j/$J_DEB" - [ -f "$ISOLATE_ROOT/$J_SAVE" ] || { - echo "wget -O \"$ISOLATE_ROOT/$J_SAVE\" https://github.com/NZOI/J-install/releases/download/$J_TAG/$J_DEB" - wget -O "$ISOLATE_ROOT/$J_SAVE" "https://github.com/NZOI/J-install/releases/download/$J_TAG/$J_DEB" - } + # install J + bash script/confirm.bash 'Install J' && { + chroot "$ISOLATE_ROOT" mkdir /home/j -p + J_TAG="J803" + J_DEB="j803_amd64.deb" + J_SAVE="/home/j/$J_DEB" + [ -f "$ISOLATE_ROOT/$J_SAVE" ] || { + echo "wget -O \"$ISOLATE_ROOT/$J_SAVE\" https://github.com/NZOI/J-install/releases/download/$J_TAG/$J_DEB" + wget -O "$ISOLATE_ROOT/$J_SAVE" "https://github.com/NZOI/J-install/releases/download/$J_TAG/$J_DEB" + } - echo "$chroot_cmd dpkg -i $J_SAVE" - chroot "$ISOLATE_ROOT" dpkg -i "$J_SAVE" + echo "$chroot_cmd dpkg -i $J_SAVE" + chroot "$ISOLATE_ROOT" dpkg -i "$J_SAVE" - cat << EOF > "$ISOLATE_ROOT"/home/j/install.ijs + cat << EOF > "$ISOLATE_ROOT"/home/j/install.ijs load 'pacman' 'update' jpkg '' 'install' jpkg 'format/printf' @@ -168,9 +172,10 @@ load 'pacman' exit 0 EOF - echo "$chroot_cmd ijconsole /home/j/install.ijs" - chroot "$ISOLATE_ROOT" ijconsole /home/j/install.ijs - ## END INSTALL J + echo "$chroot_cmd ijconsole /home/j/install.ijs" + chroot "$ISOLATE_ROOT" ijconsole /home/j/install.ijs + } + # end install J } diff --git a/script/install/isolate.bash b/script/install/isolate.bash index d8d3dc8c..a6ecc154 100644 --- a/script/install/isolate.bash +++ b/script/install/isolate.bash @@ -9,7 +9,7 @@ cd $srclocation if [ -d "isolate" ]; then cd isolate done=true - git pull --force | grep -q -v 'Already up-to-date.' && done=false + # git pull --force | grep -q -v 'Already up-to-date.' && done=false if $done; then exit fi diff --git a/script/install/nokogiri.bash b/script/install/nokogiri.bash deleted file mode 100644 index 0934922b..00000000 --- a/script/install/nokogiri.bash +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -cmd="sudo apt-get install libxslt-dev libxml2-dev" - -echo "$ $cmd" -$cmd - diff --git a/spec/controllers/file_attachments_controller_spec.rb b/spec/controllers/file_attachments_controller_spec.rb new file mode 100644 index 00000000..80038384 --- /dev/null +++ b/spec/controllers/file_attachments_controller_spec.rb @@ -0,0 +1,11 @@ +require "spec_helper" + +RSpec.describe FileAttachmentsController do + describe "GET /file_attachments" do + before do + sign_in users(:superadmin) + end + + can_index :file_attachments + end +end