From 9e0c23fd62e5db2cd7b196818d35a101e3d3c5ed Mon Sep 17 00:00:00 2001 From: Tom Naessens Date: Sun, 26 May 2024 19:24:37 +0200 Subject: [PATCH] Ruby and Sentry bump --- .ruby-version | 2 +- .tool-versions | 2 +- Gemfile | 3 ++- Gemfile.lock | 20 +++++++++------- app/controllers/application_controller.rb | 2 ++ .../concerns/sentry_user_context.rb | 24 +++++++++++++++++++ 6 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 app/controllers/concerns/sentry_user_context.rb diff --git a/.ruby-version b/.ruby-version index ef538c28..bea438e9 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.1.2 +3.3.1 diff --git a/.tool-versions b/.tool-versions index ce2852a1..f76d2631 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,3 +1,3 @@ -ruby 3.1.2 +ruby 3.3.1 yarn 1.22.19 nodejs 16.15.0 diff --git a/Gemfile b/Gemfile index f9f00559..2d78227e 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -ruby "3.1.2" +ruby "3.3.1" # ed25519 ssh key support gem "bcrypt_pbkdf", ">= 1.0", "< 2.0" @@ -78,6 +78,7 @@ gem "rswag-ui" # Sentry gem "sentry-rails" gem "sentry-ruby" +gem "stackprof" group :development, :test do gem "factory_bot_rails" diff --git a/Gemfile.lock b/Gemfile.lock index 42fff176..5d4f2723 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -171,6 +171,7 @@ GEM matrix (0.4.2) method_source (1.0.0) mini_mime (1.1.2) + mini_portile2 (2.8.6) minitest (5.16.3) msgpack (1.6.0) multi_xml (0.6.0) @@ -192,10 +193,9 @@ GEM net-protocol timeout net-ssh (7.0.1) - nio4r (2.5.8) - nokogiri (1.13.9-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.13.9-x86_64-linux) + nio4r (2.7.3) + nokogiri (1.13.9) + mini_portile2 (~> 2.8.0) racc (~> 1.4) oauth2 (2.0.2) faraday (>= 0.17.3, < 3.0) @@ -336,11 +336,13 @@ GEM actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) - sqlite3 (1.5.3-x86_64-darwin) - sqlite3 (1.5.3-x86_64-linux) + sqlite3 (1.7.3-arm64-darwin) + sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) sshkit (1.21.3) net-scp (>= 1.1.2) net-ssh (>= 2.8.0) + stackprof (0.2.26) stimulus-rails (1.1.0) railties (>= 6.0.0) strscan (3.0.4) @@ -374,6 +376,7 @@ GEM zeitwerk (2.6.1) PLATFORMS + arm64-darwin-23 x86_64-darwin-21 x86_64-linux @@ -418,6 +421,7 @@ DEPENDENCIES sentry-ruby sprockets-rails sqlite3 (~> 1.5) + stackprof stimulus-rails turbo-rails tzinfo-data @@ -425,7 +429,7 @@ DEPENDENCIES webdrivers RUBY VERSION - ruby 3.1.2p20 + ruby 3.3.1p55 BUNDLED WITH - 2.3.18 + 2.5.10 diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f824400c..cb983d44 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,8 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. protect_from_forgery with: :exception + include SentryUserContext + rescue_from CanCan::AccessDenied do |exception| redirect_to root_url, alert: exception.message end 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