Merge pull request #9663 from tchak/legacy-browsers
feat(traitement): add browser information
This commit is contained in:
commit
a611852ebc
10 changed files with 56 additions and 14 deletions
|
@ -3,6 +3,10 @@ class API::V2::BaseController < ApplicationController
|
||||||
skip_before_action :setup_tracking
|
skip_before_action :setup_tracking
|
||||||
before_action :authenticate_from_token
|
before_action :authenticate_from_token
|
||||||
|
|
||||||
|
before_action do
|
||||||
|
Current.browser = 'api'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def context
|
def context
|
||||||
|
|
|
@ -2,6 +2,10 @@ class APIController < ApplicationController
|
||||||
before_action :default_format_json
|
before_action :default_format_json
|
||||||
before_action :authenticate_from_token
|
before_action :authenticate_from_token
|
||||||
|
|
||||||
|
before_action do
|
||||||
|
Current.browser = 'api'
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def default_format_json
|
def default_format_json
|
||||||
|
|
|
@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base
|
||||||
before_action do
|
before_action do
|
||||||
Current.request_id = request.uuid
|
Current.request_id = request.uuid
|
||||||
Current.user = current_user
|
Current.user = current_user
|
||||||
|
Current.browser = browser
|
||||||
end
|
end
|
||||||
|
|
||||||
def staging_authenticate
|
def staging_authenticate
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
class Current < ActiveSupport::CurrentAttributes
|
class Current < ActiveSupport::CurrentAttributes
|
||||||
attribute :user, :request_id
|
attribute :user, :request_id, :browser
|
||||||
end
|
end
|
||||||
|
|
|
@ -64,49 +64,56 @@ class Dossier < ApplicationRecord
|
||||||
def passer_en_construction(instructeur: nil, processed_at: Time.zone.now)
|
def passer_en_construction(instructeur: nil, processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:en_construction),
|
build(state: Dossier.states.fetch(:en_construction),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
processed_at: processed_at)
|
processed_at:,
|
||||||
|
browser: Current.browser)
|
||||||
end
|
end
|
||||||
|
|
||||||
def submit_en_construction(processed_at: Time.zone.now)
|
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
|
end
|
||||||
|
|
||||||
def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now)
|
def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:en_instruction),
|
build(state: Dossier.states.fetch(:en_instruction),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
processed_at: processed_at)
|
processed_at:,
|
||||||
|
browser: Current.browser)
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepter_automatiquement(processed_at: Time.zone.now)
|
def accepter_automatiquement(processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:accepte),
|
build(state: Dossier.states.fetch(:accepte),
|
||||||
processed_at: processed_at)
|
processed_at:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def accepter(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
def accepter(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:accepte),
|
build(state: Dossier.states.fetch(:accepte),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
motivation: motivation,
|
motivation:,
|
||||||
processed_at: processed_at)
|
processed_at:,
|
||||||
|
browser: Current.browser)
|
||||||
end
|
end
|
||||||
|
|
||||||
def refuser(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
def refuser(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:refuse),
|
build(state: Dossier.states.fetch(:refuse),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
motivation: motivation,
|
motivation:,
|
||||||
processed_at: processed_at)
|
processed_at:,
|
||||||
|
browser: Current.browser)
|
||||||
end
|
end
|
||||||
|
|
||||||
def refuser_automatiquement(processed_at: Time.zone.now, motivation:)
|
def refuser_automatiquement(processed_at: Time.zone.now, motivation:)
|
||||||
build(state: Dossier.states.fetch(:refuse),
|
build(state: Dossier.states.fetch(:refuse),
|
||||||
motivation: motivation,
|
motivation:,
|
||||||
processed_at: processed_at)
|
processed_at:)
|
||||||
end
|
end
|
||||||
|
|
||||||
def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
def classer_sans_suite(motivation: nil, instructeur: nil, processed_at: Time.zone.now)
|
||||||
build(state: Dossier.states.fetch(:sans_suite),
|
build(state: Dossier.states.fetch(:sans_suite),
|
||||||
instructeur_email: instructeur&.email,
|
instructeur_email: instructeur&.email,
|
||||||
motivation: motivation,
|
motivation:,
|
||||||
processed_at: processed_at)
|
processed_at:,
|
||||||
|
browser: Current.browser)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
has_one :traitement, -> { order(processed_at: :desc) }, inverse_of: false
|
has_one :traitement, -> { order(processed_at: :desc) }, inverse_of: false
|
||||||
|
|
|
@ -13,4 +13,16 @@ class Traitement < ApplicationRecord
|
||||||
.where.not(processed_at: nil)
|
.where.not(processed_at: nil)
|
||||||
.order(:processed_at)
|
.order(:processed_at)
|
||||||
end
|
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
|
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.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -979,6 +979,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_10_25_161609) do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "traitements", force: :cascade do |t|
|
create_table "traitements", force: :cascade do |t|
|
||||||
|
t.string "browser_name"
|
||||||
|
t.boolean "browser_supported"
|
||||||
|
t.integer "browser_version"
|
||||||
t.bigint "dossier_id"
|
t.bigint "dossier_id"
|
||||||
t.string "instructeur_email"
|
t.string "instructeur_email"
|
||||||
t.string "motivation"
|
t.string "motivation"
|
||||||
|
|
|
@ -964,6 +964,9 @@ describe API::V2::GraphqlController do
|
||||||
expect(gql_data[:dossierAccepter][:dossier][:state]).to eq('accepte')
|
expect(gql_data[:dossierAccepter][:dossier][:state]).to eq('accepte')
|
||||||
perform_enqueued_jobs
|
perform_enqueued_jobs
|
||||||
expect(ActionMailer::Base.deliveries.size).to eq(1)
|
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
|
context 'without notifications' do
|
||||||
|
|
|
@ -481,6 +481,7 @@ describe Users::DossiersController, type: :controller do
|
||||||
expect(dossier).to be_en_instruction
|
expect(dossier).to be_en_instruction
|
||||||
expect(dossier.pending_correction?).to be_falsey
|
expect(dossier.pending_correction?).to be_falsey
|
||||||
expect(dossier.en_instruction_at).to within(5.seconds).of(Time.current)
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue