From b9be186d2c08e4eb764f52513d76b7c0b18d8881 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 3 Apr 2019 12:13:34 +0200 Subject: [PATCH 1/2] Sentry should send environment information --- app/controllers/application_controller.rb | 22 +++++++------------ app/javascript/shared/track/sentry.js | 4 ++-- config/env.example | 1 + config/initializers/raven.rb | 1 + config/secrets.yml | 1 + .../application_controller_spec.rb | 6 ++--- 6 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 259fa6447..7551320aa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -118,16 +118,7 @@ class ApplicationController < ActionController::Base end def set_raven_context - user = logged_user - - context = { - ip_address: request.ip, - id: user&.id, - email: user&.email, - roles: logged_user_roles - }.compact - - Raven.user_context(context) + Raven.user_context(sentry_user) end def append_info_to_payload(payload) @@ -202,16 +193,19 @@ class ApplicationController < ActionController::Base end end + def sentry_user + user = logged_user + { id: user&.id, role: user&.class&.name || 'Guest' }.compact + end + def sentry_config sentry = Rails.application.secrets.sentry { key: sentry[:client_key], enabled: sentry[:enabled], - user: { - id: current_user&.id, - email: current_email - } + environment: sentry[:environment], + user: sentry_user } end diff --git a/app/javascript/shared/track/sentry.js b/app/javascript/shared/track/sentry.js index ffeb0b69e..5c3bafc17 100644 --- a/app/javascript/shared/track/sentry.js +++ b/app/javascript/shared/track/sentry.js @@ -1,10 +1,10 @@ import * as Sentry from '@sentry/browser'; -const { key, enabled, user } = gon.sentry || {}; +const { key, enabled, user, environment } = gon.sentry || {}; // We need to check for key presence here as we do not have a dsn for browser yet if (enabled && key) { - Sentry.init({ dsn: key }); + Sentry.init({ dsn: key, environment }); if (user.email) { Sentry.configureScope(scope => { diff --git a/config/env.example b/config/env.example index 865afd6df..0c2473e18 100644 --- a/config/env.example +++ b/config/env.example @@ -38,6 +38,7 @@ HELPSCOUT_CLIENT_SECRET="" HELPSCOUT_WEBHOOK_SECRET="" SENTRY_ENABLED="disabled" +SENTRY_CURRENT_ENV="development" SENTRY_DSN_RAILS="" SENTRY_DSN_JS="" diff --git a/config/initializers/raven.rb b/config/initializers/raven.rb index 18c449de4..f1c6fab27 100644 --- a/config/initializers/raven.rb +++ b/config/initializers/raven.rb @@ -3,5 +3,6 @@ if ENV['SENTRY_ENABLED'] == 'enabled' Raven.configure do |config| config.dsn = ENV['SENTRY_DSN_RAILS'] + config.environments = ['production', 'staging'] end end diff --git a/config/secrets.yml b/config/secrets.yml index f010c0392..9a035f676 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -60,6 +60,7 @@ defaults: &defaults sentry: enabled: <%= ENV['SENTRY_ENABLED'] == 'enabled' %> client_key: <%= ENV['SENTRY_DSN_JS'] %> + environment: <%= ENV['SENTRY_CURRENT_ENV'] %> development: <<: *defaults diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 71a72f483..f07bd8737 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -34,7 +34,7 @@ describe ApplicationController, type: :controller do context 'when no one is logged in' do it do expect(Raven).to have_received(:user_context) - .with({ ip_address: '0.0.0.0', roles: 'Guest' }) + .with({ role: 'Guest' }) end it do @@ -53,7 +53,7 @@ describe ApplicationController, type: :controller do it do expect(Raven).to have_received(:user_context) - .with({ ip_address: '0.0.0.0', email: current_user.email, id: current_user.id, roles: 'User' }) + .with({ id: current_user.id, role: 'User' }) end it do @@ -77,7 +77,7 @@ describe ApplicationController, type: :controller do it do expect(Raven).to have_received(:user_context) - .with({ ip_address: '0.0.0.0', email: current_user.email, id: current_user.id, roles: 'User, Gestionnaire, Administrateur, Administration' }) + .with({ id: current_user.id, role: 'User' }) end it do From 8157fd012768ab2daf6dd130d8f1ed6100e50ee0 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 3 Apr 2019 21:53:57 +0200 Subject: [PATCH 2/2] =?UTF-8?q?Fix=20type=20de=20champ=20menu=20d=C3=A9rou?= =?UTF-8?q?lant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/TypeDeChampDropDownOptions.js | 4 ++-- .../new_administrateur/types_de_champ_spec.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/javascript/components/TypesDeChampEditor/components/TypeDeChampDropDownOptions.js b/app/javascript/components/TypesDeChampEditor/components/TypeDeChampDropDownOptions.js index 61570058d..148e179ba 100644 --- a/app/javascript/components/TypesDeChampEditor/components/TypeDeChampDropDownOptions.js +++ b/app/javascript/components/TypesDeChampEditor/components/TypeDeChampDropDownOptions.js @@ -1,7 +1,7 @@ import React from 'react'; import PropTypes from 'prop-types'; -function TypeDeChampDropDownOptions({ isVisible, value, handler }) { +function TypeDeChampDropDownOptions({ isVisible, handler }) { if (isVisible) { return (
@@ -9,7 +9,7 @@ function TypeDeChampDropDownOptions({ isVisible, value, handler }) {