diff --git a/.github/workflows/rubyonrails.yml b/.github/workflows/rubyonrails.yml new file mode 100644 index 00000000..0365e34a --- /dev/null +++ b/.github/workflows/rubyonrails.yml @@ -0,0 +1,72 @@ +# This workflow uses actions that are not certified by GitHub. They are +# provided by a third-party and are governed by separate terms of service, +# privacy policy, and support documentation. +# +# This workflow will install a prebuilt Ruby version, install dependencies, and +# run tests and linters. +name: "Ruby on Rails CI" +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] +jobs: + test: + runs-on: ubuntu-18.04 + services: + redis: + image: redis:3 + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + postgres: + image: postgres:11 + ports: + - "5432:5432" + env: + POSTGRES_DB: nztrain_test + POSTGRES_USER: rails + POSTGRES_PASSWORD: password + env: + RAILS_ENV: test + DATABASE_URL: "postgres://rails:password@127.0.0.1:5432/nztrain_test" + NZIC_DATABASE_URL: "postgres://rails:password@127.0.0.1:5432/nzic_test" + REDIS_HOST: redis + PGGSSENCMODE: "disable" # Workaround for https://www.postgresql.org/message-id/93f7379b-2e2f-db0c-980e-07ebd5de92ff%40crunchydata.com, remove after upgrading pg > 1.0 + steps: + - name: Install libmaxmind + run: | + sudo add-apt-repository ppa:maxmind/ppa + sudo apt-get update + sudo apt-get install -y libmaxminddb0 libmaxminddb-dev mmdb-bin + - name: Checkout code + uses: actions/checkout@v3 + # Add or replace dependency steps here + - name: Install Ruby and gems + uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0 + with: + bundler-cache: true + - name: Setup database schema + run: bundle exec rake db:schema:load + # Add or replace test runners here + - name: Run tests + run: bundle exec rspec + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Install Ruby and gems + uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4 # v1.127.0 + with: + bundler-cache: true + # Add or replace any other lints here + # - name: Security audit dependencies + # run: bin/bundler-audit --update + # - name: Security audit application code + # run: bin/brakeman -q -w2 + # - name: Lint Ruby files + # run: bin/rubocop --parallel diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 00000000..461ab3c0 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 2.4.10 diff --git a/Gemfile b/Gemfile index be67045e..56c65dac 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,6 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } gem 'rails', '~> 4.0.0' -gem 'nzic_models', github: 'NZOI/nzic_models' -#gem 'nzic_models', path: '../../nzic/nzic_models' - gem 'devise', '~> 3.2.2' gem 'psych', '~> 2.0.2' # part of stdlib, need newer version for safe_load @@ -19,9 +16,6 @@ gem 'jquery-ui-rails', '4.0.5' gem 'jquery-historyjs', '0.2.3' gem 'superfish-rails', '~> 1.6.0' -gem 'forem', github: 'radar/forem', branch: 'rails4' -gem 'forem-redcarpet', github: 'NZOI/forem-redcarpet' - gem "nokogiri", '~> 1.10.8' gem 'redcarpet' #gem 'rmagick', '2.13.2' @@ -40,7 +34,6 @@ gem 'simple_form', '3.0.1' gem 'facebox-rails' gem 'strong_presenter', '~> 0.2.2' gem 'render_anywhere' -gem 'pygments.rb', '0.5.4' gem 'ranked-model', :github => 'mixonic/ranked-model' gem 'pdf-reader' gem 'mechanize' @@ -56,7 +49,7 @@ gem 'world-flags' gem 'jquery-final_countdown-rails' gem 'ruby-duration' -gem 'pg' +gem 'pg', '<1.0' gem 'backup' # Redis and Background Processing @@ -89,10 +82,9 @@ group :development, :test do gem 'capybara' gem 'capybara-email' - gem 'factory_girl_rails' + gem 'factory_bot_rails' gem 'byebug' - gem 'factory_girl'#, '~> 4.0' gem 'ruby_parser' # for declarative_authorization end diff --git a/Gemfile.lock b/Gemfile.lock index fa379b53..c680d1d2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,21 +1,3 @@ -GIT - remote: https://github.com/NZOI/forem-redcarpet.git - revision: b9908439463723071d9f2f50290af84ca37042a4 - specs: - forem-redcarpet (1.0.2) - nokogiri - pygments.rb (= 0.5.4) - redcarpet (~> 3.2.2) - -GIT - remote: https://github.com/NZOI/nzic_models.git - revision: 0afa31e8bb8b045d12951a36032b15a768a3c868 - specs: - nzic_models (0.0.2) - loofah - rails (~> 4.0) - redcarpet - GIT remote: https://github.com/mixonic/ranked-model.git revision: 5fd725bb07a331e0fb10ba3f1b0bee15dad8a47f @@ -23,22 +5,6 @@ GIT ranked-model (0.4.0) activerecord (>= 3.1.12) -GIT - remote: https://github.com/radar/forem.git - revision: fb37858a51cfc8fe2ccd113e61af42546091fd27 - branch: rails4 - specs: - forem (1.0.0.beta1) - cancancan (~> 1.7) - decorators (~> 1.0.2) - friendly_id (~> 5.0.0) - gemoji (= 2.1.0) - rails (~> 4.0, != 4.2.3, != 4.2.2, != 4.2.1, != 4.2.0) - sanitize (= 2.0.6) - select2-rails (~> 3.5.4) - simple_form (~> 3.0) - workflow (= 1.0.0) - GEM remote: https://rubygems.org/ specs: @@ -92,7 +58,6 @@ GEM debug_inspector (>= 0.0.1) builder (3.1.4) byebug (9.1.0) - cancancan (1.17.0) capybara (2.17.0) addressable mini_mime (>= 0.1.3) @@ -136,8 +101,6 @@ GEM crass (1.0.5) daemons (1.3.1) debug_inspector (0.0.3) - decorators (1.0.5) - railties (>= 3.0.19) devise (3.2.4) bcrypt (~> 3.0) orm_adapter (~> 0.1) @@ -155,19 +118,16 @@ GEM facebox-rails (0.2.0) railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) - factory_girl (4.9.0) + factory_bot (4.11.1) activesupport (>= 3.0.0) - factory_girl_rails (4.9.0) - factory_girl (~> 4.9.0) + factory_bot_rails (4.11.1) + factory_bot (~> 4.11.1) railties (>= 3.0.0) faraday (0.15.4) multipart-post (>= 1.2, < 3) ffi (1.12.2) foreman (0.84.0) thor (~> 0.19.1) - friendly_id (5.0.5) - activerecord (>= 4.0.0) - gemoji (2.1.0) geocoder (1.4.5) has_scope (0.6.0) actionpack (>= 3.2, < 5) @@ -240,9 +200,9 @@ GEM ttfunk pdfkit (0.8.2) pg (0.21.0) + pkg-config (1.5.1) polyamorous (1.1.0) activerecord (>= 3.0) - posix-spawn (0.3.13) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) @@ -250,9 +210,6 @@ GEM public_suffix (3.0.1) pundit (0.2.1) activesupport (>= 3.0.0) - pygments.rb (0.5.4) - posix-spawn (~> 0.3.6) - yajl-ruby (~> 1.1.0) qless (0.12.0) metriks (~> 0.9) redis (>= 2.2, < 4.0.0.rc1) @@ -293,7 +250,8 @@ GEM render_anywhere (0.0.12) rails (>= 3.0.7) request_store (1.0.8) - rmagick (2.16.0) + rmagick (5.1.0) + pkg-config (~> 1.4) rqrcode (0.10.1) chunky_png (~> 1.0) rspec-collection_matchers (1.1.3) @@ -320,8 +278,6 @@ GEM sexp_processor (~> 4.9) rubyzip (1.3.0) rusage (0.2.0) - sanitize (2.0.6) - nokogiri (>= 1.4.4) sass (3.5.5) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -333,8 +289,6 @@ GEM sprockets (>= 2.8, < 4.0) sprockets-rails (>= 2.0, < 4.0) tilt (>= 1.1, < 3) - select2-rails (3.5.10) - thor (~> 0.14) sentry-raven (0.15.6) faraday (>= 0.7.6) sexp_processor (4.10.0) @@ -406,13 +360,11 @@ GEM whenever (0.10.0) chronic (>= 0.6.3) will_paginate (3.1.6) - workflow (1.0.0) world-flags (0.6.5) hashie (>= 1.2) i18n (>= 0.6) xpath (2.1.0) nokogiri (~> 1.3) - yajl-ruby (1.1.0) yui-compressor (0.12.0) PLATFORMS @@ -434,10 +386,7 @@ DEPENDENCIES coveralls devise (~> 3.2.2) facebox-rails - factory_girl - factory_girl_rails - forem! - forem-redcarpet! + factory_bot_rails foreman geocoder has_scope @@ -451,14 +400,12 @@ DEPENDENCIES mechanize newrelic_rpm nokogiri (~> 1.10.8) - nzic_models! pdf-reader pdfkit - pg + pg (< 1.0) prawn psych (~> 2.0.2) pundit (= 0.2.1) - pygments.rb (= 0.5.4) qless rails (~> 4.0.0) rake (< 11.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index accdf347..16ce7f5d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -11,7 +11,6 @@ //= require history //= require jquery.facebox //= require jquery.facebox.adapter -//= require forem //= require_self diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 29621572..c5efe221 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -2,7 +2,6 @@ *= require jquery.ui.datepicker *= require jquery.ui.slider *= require scaffold -*= require pygments *= require code *= require sample *= require jquery.facebox @@ -15,7 +14,6 @@ *= require messagebox *= require message *= require fontello -*= require forem/base *= require forum *= require flags/basic *= require flags/flags24 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 70120ad4..cb9b146e 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,12 +1,7 @@ class ApplicationController < ActionController::Base - - def forem_user - current_user - end - helper_method :forem_user - include ApplicationHelper include Pundit + layout "scaffold" before_filter :update_last_seen_at @@ -15,6 +10,7 @@ def forem_user before_filter :check_su_loss before_filter :wrong_site before_filter :configure_permitted_parameters, if: :devise_controller? + protect_from_forgery #helper ApplicationHelper diff --git a/app/controllers/nzic/info_controller.rb b/app/controllers/nzic/info_controller.rb deleted file mode 100644 index c8c75823..00000000 --- a/app/controllers/nzic/info_controller.rb +++ /dev/null @@ -1,64 +0,0 @@ -class NZIC::InfoController < ApplicationController - helper NZIC::InfoHelper - #helper 'nzic/info' - - def permitted_params - params.require(:nzic_info).permit(:name, :title, :text) - end - - def index - authorize NZIC::Info, :index? - @infos = policy_scope(NZIC::Info).order(:name) - end - - def show - @info = NZIC::Info.find(params[:name]) - authorize @info, :show? - end - - def new - @info = NZIC::Info.new - authorize @info, :new? - end - - def create - @info = NZIC::Info.new(permitted_params) - authorize @info, :create? - - respond_to do |format| - if @info.save - format.html { redirect_to @info, notice: "Info page created." } - else - format.html { render action: "new" } - end - end - end - - def edit - @info = NZIC::Info.find(params[:name]) - authorize @info, :edit? - end - - def update - @info = NZIC::Info.find(params[:name]) - authorize @info, :update? - - respond_to do |format| - if @info.update_attributes(permitted_params) - format.html { redirect_to @info, notice: "Info page updated." } - else - format.html { render action: "edit" } - end - end - end - - def destroy - @info = NZIC::Info.find(params[:name]) - authorize @info, :destroy? - @info.destroy - - respond_to do |format| - format.html { redirect_to nzic_info_path, notice: "NZIC info page destroyed." } - end - end -end diff --git a/app/controllers/nzic/menu_items_controller.rb b/app/controllers/nzic/menu_items_controller.rb deleted file mode 100644 index 5df20d0f..00000000 --- a/app/controllers/nzic/menu_items_controller.rb +++ /dev/null @@ -1,62 +0,0 @@ -class NZIC::MenuItemsController < ApplicationController - - def permitted_params - params.require(:nzic_menu_item).permit(:name, :link) - end - - def index - authorize NZIC::MenuItem, :index? - @menu_items = policy_scope(NZIC::MenuItem).order(:id) - end - - def show - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :show? - end - - def new - @menu_item = NZIC::MenuItem.new - authorize @menu_item, :new? - end - - def create - @menu_item = NZIC::MenuItem.new(permitted_params) - authorize @menu_item, :create? - - respond_to do |format| - if @menu_item.save - format.html { redirect_to @menu_item, notice: "Menu item created." } - else - format.html { render action: "new" } - end - end - end - - def edit - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :edit? - end - - def update - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :update? - - respond_to do |format| - if @menu_item.update_attributes(permitted_params) - format.html { redirect_to @menu_item, notice: "Menu item updated." } - else - format.html { render action: "edit" } - end - end - end - - def destroy - @menu_item = NZIC::MenuItem.find(params[:id]) - authorize @menu_item, :destroy? - @menu_item.destroy - - respond_to do |format| - format.html { redirect_to nzic_menu_item_path, notice: "Menu item destroyed." } - end - end -end diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb new file mode 100644 index 00000000..1807a2ff --- /dev/null +++ b/app/controllers/pages_controller.rb @@ -0,0 +1,4 @@ +class PagesController < ApplicationController + def forum + end +end diff --git a/app/models/user.rb b/app/models/user.rb index c50b77c0..cbc169f8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -52,50 +52,6 @@ def self.find_for_authentication(conditions={}) self.where("email = ?", conditions[:email]).limit(1).first end - def forem_name - username - end - - def forem_admin? - is_admin? || self.has_role?(:forum_admin) - end - - def forem_avatar - avatar.small.url - end - - def can_read_forem_category?(category) - true - end - - def can_read_forem_forums? - true - end - - def can_read_forem_forum?(forum) - true - end - - def can_create_forem_topics?(forum) - if forum.category.name == "Announcements" - forem_admin? - else - persisted? - end - end - - def can_reply_to_forem_topic?(topic) - persisted? - end - - def can_edit_forem_posts?(forum) - persisted? - end - - def can_destroy_forem_posts?(forum) - persisted? - end - def get_solved solved = [] @solved_problems = Problem.select("problems.*, (SELECT MAX(score) FROM submissions WHERE problem_id = problems.id AND user_id = #{self.id}) as score") diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 80be8e43..1db12a95 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -123,20 +123,11 @@ <% if policy(User.new).inspect? %>
  • online
  • <% end %> -
  • forum
  • <% if current_user && current_user.is_admin? %>
  • admin