diff --git a/.rubocop.yml b/.rubocop.yml index 635cdb8b..bc599c40 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + require: - rubocop-rails - rubocop-rspec @@ -12,6 +14,9 @@ Style/StringLiterals: Style/Documentation: Enabled: false +Style/HashSyntax: + Enabled: false + # Do not complain about blocks that are too long. Metrics/BlockLength: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..9fc63691 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,41 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-05-26 16:27:21 UTC using RuboCop version 1.64.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 14 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, BlockForwardingName. +# SupportedStyles: anonymous, explicit +Naming/BlockForwarding: + Exclude: + - 'app/form_builders/formatted_form_builder.rb' + - 'app/helpers/application_helper.rb' + +# Offense count: 14 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowOnlyRestArgument, UseAnonymousForwarding, RedundantRestArgumentNames, RedundantKeywordRestArgumentNames, RedundantBlockArgumentNames. +# RedundantRestArgumentNames: args, arguments +# RedundantKeywordRestArgumentNames: kwargs, options, opts +# RedundantBlockArgumentNames: blk, block, proc +Style/ArgumentsForwarding: + Exclude: + - 'app/form_builders/formatted_form_builder.rb' + - 'app/helpers/application_helper.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AllowedReceivers. +# AllowedReceivers: Thread.current +Style/HashEachMethods: + Exclude: + - 'app/models/stock.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +Style/SuperArguments: + Exclude: + - 'app/form_builders/formatted_form_builder.rb' diff --git a/.ruby-version b/.ruby-version index b0f2dcb3..bea438e9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.4 +3.3.1 diff --git a/.simplecov b/.simplecov deleted file mode 100644 index 62f970a0..00000000 --- a/.simplecov +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -require "simplecov" -require "coveralls" - -SimpleCov.formatter = Coveralls::SimpleCov::Formatter -SimpleCov.start do - add_filter "config/" -end diff --git a/.tool-versions b/.tool-versions index 6e624cf0..f76d2631 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ -ruby 3.0.4 +ruby 3.3.1 yarn 1.22.19 nodejs 16.15.0 diff --git a/Gemfile b/Gemfile index b2afbe5e..2e8b6062 100644 --- a/Gemfile +++ b/Gemfile @@ -21,6 +21,9 @@ gem "sassc-rails", "~> 2.1" # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem "webpacker", "~> 5.0" +# Not sure why +gem "net-smtp", require: false + # Bulma gem "bulma-rails", "~> 0.9.1" gem "font-awesome-sass", "~> 5.15" @@ -74,6 +77,7 @@ gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw] # Sentry gem "sentry-rails" gem "sentry-ruby" +gem "stackprof" # Production dependencies group :production do @@ -82,8 +86,6 @@ end # Test dependencies group :test do - gem "codeclimate-test-reporter", require: nil - gem "coveralls", require: false gem "rspec-rails" gem "webmock" end diff --git a/Gemfile.lock b/Gemfile.lock index a16051fa..ed86bece 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -70,6 +70,7 @@ GEM ast (2.4.2) bcrypt (3.1.17) bcrypt_pbkdf (1.1.0) + bigdecimal (3.1.8) bootsnap (1.11.1) msgpack (~> 1.2) builder (3.2.4) @@ -98,15 +99,7 @@ GEM chartkick (4.1.3) chunky_png (1.4.0) climate_control (0.2.0) - codeclimate-test-reporter (1.0.9) - simplecov (<= 0.13) - concurrent-ruby (1.1.10) - coveralls (0.7.1) - multi_json (~> 1.3) - rest-client - simplecov (>= 0.7) - term-ansicolor - thor + concurrent-ruby (1.2.3) crack (0.4.5) rexml crass (1.0.6) @@ -123,15 +116,12 @@ GEM responders warden (~> 1.2.3) diff-lcs (1.5.0) - docile (1.1.5) - domain_name (0.5.20190701) - unf (>= 0.0.5, < 1.0.0) dotenv (2.8.1) dotenv-rails (2.8.1) dotenv (= 2.8.1) railties (>= 3.2) ed25519 (1.3.0) - erubi (1.10.0) + erubi (1.12.0) factory_bot (6.2.1) activesupport (>= 5.0.0) factory_bot_rails (6.2.0) @@ -152,17 +142,14 @@ GEM activesupport (>= 5.0) hashdiff (1.0.1) hashie (5.0.0) - http-accept (1.7.0) - http-cookie (1.0.4) - domain_name (~> 0.5) httparty (0.20.0) mime-types (~> 3.0) multi_xml (>= 0.5.2) - i18n (1.10.0) + i18n (1.14.5) concurrent-ruby (~> 1.0) identicon (0.0.5) chunky_png - json (2.6.1) + json (2.7.2) jwt (2.3.0) kt-paperclip (7.1.1) activemodel (>= 4.2.0) @@ -170,33 +157,39 @@ GEM marcel (~> 1.0.1) mime-types terrapin (~> 0.6.0) + language_server-protocol (3.17.0.3) listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.18.0) + loofah (2.22.0) crass (~> 1.0.2) - nokogiri (>= 1.5.9) + nokogiri (>= 1.12.0) mail (2.7.1) mini_mime (>= 0.1.1) marcel (1.0.2) - method_source (1.0.0) - mime-types (3.4.1) + method_source (1.1.0) + mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2022.0105) + mime-types-data (3.2024.0507) mini_mime (1.1.2) - minitest (5.15.0) + minitest (5.23.1) msgpack (1.5.1) multi_json (1.15.0) multi_xml (0.6.0) mysql2 (0.5.4) + net-protocol (0.2.2) + timeout net-scp (3.0.0) net-ssh (>= 2.6.5, < 7.0.0) + net-smtp (0.5.0) + net-protocol net-ssh (6.1.0) - netrc (0.11.0) - nio4r (2.5.8) - nokogiri (1.13.6-x86_64-darwin) + nio4r (2.7.3) + nokogiri (1.16.5-arm64-darwin) + racc (~> 1.4) + nokogiri (1.16.5-x86_64-darwin) racc (~> 1.4) - nokogiri (1.13.6-x86_64-linux) + nokogiri (1.16.5-x86_64-linux) racc (~> 1.4) oauth2 (1.4.9) faraday (>= 0.17.3, < 3.0) @@ -217,22 +210,23 @@ GEM omniauth-zeuswpi (1.0.0) omniauth-oauth2 (~> 1.7.1) orm_adapter (0.5.0) - parallel (1.22.1) - parser (3.1.2.0) + parallel (1.24.0) + parser (3.3.1.0) ast (~> 2.4.1) - psych (4.0.3) + racc + psych (5.1.2) stringio public_suffix (4.0.7) puma (5.5.2) nio4r (~> 2.0) - racc (1.6.0) - rack (2.2.3.1) + racc (1.8.0) + rack (2.2.9) rack-protection (2.2.0) rack rack-proxy (0.7.2) rack - rack-test (1.1.0) - rack (>= 1.0, < 3) + rack-test (2.1.0) + rack (>= 1.3) rails (6.1.6) actioncable (= 6.1.6) actionmailbox (= 6.1.6) @@ -252,11 +246,13 @@ GEM actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) + rails-dom-testing (2.2.0) + activesupport (>= 5.0.0) + minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) + rails-html-sanitizer (1.6.0) + loofah (~> 2.21) + nokogiri (~> 1.14) railties (6.1.6) actionpack (= 6.1.6) activesupport (= 6.1.6) @@ -264,22 +260,18 @@ GEM rake (>= 12.2) thor (~> 1.0) rainbow (3.1.1) - rake (13.0.6) + rake (13.2.1) rb-fsevent (0.11.1) rb-inotify (0.10.1) ffi (~> 1.0) - rdoc (6.4.0) + rdoc (6.7.0) psych (>= 4.0.0) - regexp_parser (2.4.0) + regexp_parser (2.9.2) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) - rest-client (2.1.0) - http-accept (>= 1.7.0, < 2.0) - http-cookie (>= 1.0.2, < 2.0) - mime-types (>= 1.16, < 4.0) - netrc (~> 0.8) - rexml (3.2.5) + rexml (3.2.8) + strscan (>= 3.0.9) rspec-core (3.11.0) rspec-support (~> 3.11.0) rspec-expectations (3.11.0) @@ -297,24 +289,26 @@ GEM rspec-mocks (~> 3.10) rspec-support (~> 3.10) rspec-support (3.11.0) - rubocop (1.30.0) + rubocop (1.64.0) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.1.0.0) + parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.18.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.18.0) - parser (>= 3.1.1.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) rubocop-rails (2.14.2) activesupport (>= 4.2.0) rack (>= 1.1) rubocop (>= 1.7.0, < 2.0) rubocop-rspec (2.11.1) rubocop (~> 1.19) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) sassc (2.4.0) ffi (~> 1.9) @@ -324,19 +318,15 @@ GEM sprockets (> 3.0) sprockets-rails tilt - sdoc (2.4.0) + sdoc (2.6.1) rdoc (>= 5.0) semantic_range (3.0.0) - sentry-rails (5.5.0) + sentry-rails (5.17.3) railties (>= 5.0) - sentry-ruby (~> 5.5.0) - sentry-ruby (5.5.0) + sentry-ruby (~> 5.17.3) + sentry-ruby (5.17.3) + bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) - simplecov (0.13.0) - docile (~> 1.1.0) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) spring (3.1.1) sprockets (4.0.3) concurrent-ruby (~> 1.0) @@ -345,27 +335,24 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.4.2) + sqlite3 (1.7.3-arm64-darwin) + sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) sshkit (1.21.2) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) - stringio (3.0.2) - sync (0.5.0) - term-ansicolor (1.7.1) - tins (~> 1.0) + stackprof (0.2.26) + stringio (3.1.0) + strscan (3.1.0) terrapin (0.6.0) climate_control (>= 0.0.3, < 1.0) - thor (1.2.1) + thor (1.3.1) tilt (2.0.10) - tins (1.31.1) - sync + timeout (0.4.1) tqdm (0.3.0) - tzinfo (2.0.4) + tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unf (0.1.4) - unf_ext - unf_ext (0.0.8.1) - unicode-display_width (2.1.0) + unicode-display_width (2.5.0) vanilla_nested (1.6.1) warden (1.2.9) rack (>= 2.0.9) @@ -384,9 +371,10 @@ GEM will_paginate (3.3.1) will_paginate-bulma (1.0.0) will_paginate (>= 3.0.3) - zeitwerk (2.5.4) + zeitwerk (2.6.15) PLATFORMS + arm64-darwin-23 x86_64-darwin-21 x86_64-linux @@ -403,8 +391,6 @@ DEPENDENCIES capistrano-rbenv (~> 2.2) capistrano-rvm (~> 0.1.2) chartkick (~> 4.0) - codeclimate-test-reporter - coveralls daemons (~> 1.4) delayed_job (~> 4.1) delayed_job_active_record @@ -421,6 +407,7 @@ DEPENDENCIES kt-paperclip (~> 7.0) listen (~> 3.7) mysql2 (~> 0.5.3) + net-smtp omniauth-rails_csrf_protection omniauth-zeuswpi puma (~> 5.5.0) @@ -436,6 +423,7 @@ DEPENDENCIES sentry-ruby spring (~> 3.0) sqlite3 (~> 1.4) + stackprof tqdm (~> 0.3.0) tzinfo-data vanilla_nested (~> 1.6) @@ -445,4 +433,4 @@ DEPENDENCIES will_paginate-bulma (~> 1.0) BUNDLED WITH - 2.2.33 + 2.5.10 diff --git a/README.md b/README.md index 2feb85ce..7d370570 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # [Tap](https://zeus.ugent.be/tap) -[![Code Climate](https://codeclimate.com/github/ZeusWPI/Tap/badges/gpa.svg)](https://codeclimate.com/github/ZeusWPI/Tap) [![Ruby](https://github.com/ZeusWPI/Tap/actions/workflows/ruby.yml/badge.svg)](https://github.com/ZeusWPI/Tap/actions/workflows/ruby.yml) [![Coverage Status](https://coveralls.io/repos/ZeusWPI/Tap/badge.svg?branch=master&service=github)](https://coveralls.io/github/ZeusWPI/Tap?branch=master) +[![Code Climate](https://codeclimate.com/github/ZeusWPI/Tap/badges/gpa.svg)](https://codeclimate.com/github/ZeusWPI/Tap) [![Ruby](https://github.com/ZeusWPI/Tap/actions/workflows/ruby.yml/badge.svg)](https://github.com/ZeusWPI/Tap/actions/workflows/ruby.yml) -:beer: Yes. We have to drink. But we also have to pay. This is the drinking part. +🍺 Yes. We have to drink. But we also have to pay. This is the drinking part. ## Development diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e7c56778..f6dabf6a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,9 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + + include SentryUserContext + skip_before_action :verify_authenticity_token, if: :api_request? before_action :authenticate_user_from_token! before_action :authenticate_user! diff --git a/app/controllers/concerns/sentry_user_context.rb b/app/controllers/concerns/sentry_user_context.rb new file mode 100644 index 00000000..f13a693a --- /dev/null +++ b/app/controllers/concerns/sentry_user_context.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module SentryUserContext + extend ActiveSupport::Concern + + included do + before_action :set_sentry_context + end + + private + + def sentry_user_context + {}.tap do |user| + next unless current_user + + user[:id] = current_user.id + user[:name] = current_user.name + end + end + + def set_sentry_context + Sentry.set_user(sentry_user_context) + end +end diff --git a/config/initializers/sentry.rb b/config/initializers/sentry.rb index 5c4cdb4d..08738dca 100644 --- a/config/initializers/sentry.rb +++ b/config/initializers/sentry.rb @@ -1,6 +1,7 @@ Sentry.init do |config| config.dsn = ENV["SENTRY_DSN"] config.breadcrumbs_logger = [:active_support_logger, :http_logger] + config.enable_tracing = true config.enabled_environments = %w[production] end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index b3f605aa..1c55cafc 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -37,7 +37,7 @@ end RSpec.configure do |config| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures - config.fixture_path = "#{::Rails.root}/spec/fixtures" + config.fixture_path = Rails.root.join("spec/fixtures") # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e3fa2692..ad28bec1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,8 +1,5 @@ # frozen_string_literal: true -require "coveralls" -Coveralls.wear! - # This file was generated by the `rails generate rspec:install` command. Conventionally, all # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. # The generated `.rspec` file contains `--require spec_helper` which will cause