feat(traitement): add browser information
This commit is contained in:
parent
92aab8e102
commit
d93c624164
10 changed files with 56 additions and 14 deletions
|
@ -3,6 +3,10 @@ class API::V2::BaseController < ApplicationController
|
|||
skip_before_action :setup_tracking
|
||||
before_action :authenticate_from_token
|
||||
|
||||
before_action do
|
||||
Current.browser = 'api'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def context
|
||||
|
|
|
@ -2,6 +2,10 @@ class APIController < ApplicationController
|
|||
before_action :default_format_json
|
||||
before_action :authenticate_from_token
|
||||
|
||||
before_action do
|
||||
Current.browser = 'api'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def default_format_json
|
||||
|
|
|
@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base
|
|||
before_action do
|
||||
Current.request_id = request.uuid
|
||||
Current.user = current_user
|
||||
Current.browser = browser
|
||||
end
|
||||
|
||||
def staging_authenticate
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
class Current < ActiveSupport::CurrentAttributes
|
||||
attribute :user, :request_id
|
||||
attribute :user, :request_id, :browser
|
||||
end
|
||||
|
|
|
@ -64,49 +64,56 @@ class Dossier < ApplicationRecord
|
|||
def passer_en_construction(instructeur: nil, processed_at: Time.zone.now)
|
||||
build(state: Dossier.states.fetch(:en_construction),
|
||||
instructeur_email: instructeur&.email,
|
||||
processed_at: processed_at)
|
||||
processed_at:,
|
||||
browser: Current.browser)
|
||||
end
|
||||
|
||||
def submit_en_construction(processed_at: Time.zone.now)
|
||||
build(state: Dossier.states.fetch(:en_construction), processed_at:)
|
||||
build(state: Dossier.states.fetch(:en_construction),
|
||||
processed_at:,
|
||||
browser: Current.browser)
|
||||
end
|
||||
|
||||
def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now)
|
||||
build(state: Dossier.states.fetch(:en_instruction),
|
||||
instructeur_email: instructeur&.email,
|
||||
processed_at: processed_at)
|
||||
processed_at:,
|
||||
browser: Current.browser)
|
||||
end
|
||||
|
||||
def accepter_automatiquement(processed_at: Time.zone.now)
|
||||
build(state: Dossier.states.fetch(:accepte),
|
||||
processed_at: processed_at)
|
||||
processed_at:)
|
||||
end
|
||||
|
||||
def accepter(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
||||
build(state: Dossier.states.fetch(:accepte),
|
||||
instructeur_email: instructeur&.email,
|
||||
motivation: motivation,
|
||||
processed_at: processed_at)
|
||||
motivation:,
|
||||
processed_at:,
|
||||
browser: Current.browser)
|
||||
end
|
||||
|
||||
def refuser(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
||||
build(state: Dossier.states.fetch(:refuse),
|
||||
instructeur_email: instructeur&.email,
|
||||
motivation: motivation,
|
||||
processed_at: processed_at)
|
||||
motivation:,
|
||||
processed_at:,
|
||||
browser: Current.browser)
|
||||
end
|
||||
|
||||
def refuser_automatiquement(processed_at: Time.zone.now, motivation:)
|
||||
build(state: Dossier.states.fetch(:refuse),
|
||||
motivation: motivation,
|
||||
processed_at: processed_at)
|
||||
motivation:,
|
||||
processed_at:)
|
||||
end
|
||||
|
||||
def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
||||
build(state: Dossier.states.fetch(:sans_suite),
|
||||
instructeur_email: instructeur&.email,
|
||||
motivation: motivation,
|
||||
processed_at: processed_at)
|
||||
motivation:,
|
||||
processed_at:,
|
||||
browser: Current.browser)
|
||||
end
|
||||
end
|
||||
has_one :traitement, -> { order(processed_at: :desc) }, inverse_of: false
|
||||
|
|
|
@ -13,4 +13,16 @@ class Traitement < ApplicationRecord
|
|||
.where.not(processed_at: nil)
|
||||
.order(:processed_at)
|
||||
end
|
||||
|
||||
def browser=(browser)
|
||||
if browser == 'api'
|
||||
self.browser_name = browser
|
||||
self.browser_version = 2
|
||||
self.browser_supported = true
|
||||
elsif browser.present?
|
||||
self.browser_name = browser.name
|
||||
self.browser_version = browser.version
|
||||
self.browser_supported = BrowserSupport.supported?(browser)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
7
db/migrate/20231017092437_add_browser_to_traitements.rb
Normal file
7
db/migrate/20231017092437_add_browser_to_traitements.rb
Normal file
|
@ -0,0 +1,7 @@
|
|||
class AddBrowserToTraitements < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :traitements, :browser_name, :string, null: true
|
||||
add_column :traitements, :browser_version, :integer, null: true
|
||||
add_column :traitements, :browser_supported, :boolean, null: true # rubocop:disable Rails/ThreeStateBooleanColumn
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_10_25_161609) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_10_26_161609) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -979,6 +979,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_25_161609) do
|
|||
end
|
||||
|
||||
create_table "traitements", force: :cascade do |t|
|
||||
t.string "browser_name"
|
||||
t.boolean "browser_supported"
|
||||
t.integer "browser_version"
|
||||
t.bigint "dossier_id"
|
||||
t.string "instructeur_email"
|
||||
t.string "motivation"
|
||||
|
|
|
@ -964,6 +964,9 @@ describe API::V2::GraphqlController do
|
|||
expect(gql_data[:dossierAccepter][:dossier][:state]).to eq('accepte')
|
||||
perform_enqueued_jobs
|
||||
expect(ActionMailer::Base.deliveries.size).to eq(1)
|
||||
|
||||
expect(dossier.traitements.last.browser_name).to eq('api')
|
||||
expect(dossier.traitements.last.browser_version).to eq(2)
|
||||
}
|
||||
|
||||
context 'without notifications' do
|
||||
|
|
|
@ -481,6 +481,7 @@ describe Users::DossiersController, type: :controller do
|
|||
expect(dossier).to be_en_instruction
|
||||
expect(dossier.pending_correction?).to be_falsey
|
||||
expect(dossier.en_instruction_at).to within(5.seconds).of(Time.current)
|
||||
expect(dossier.traitements.last.browser_name).to eq('Unknown Browser')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue