Merge pull request #5602 from betagouv/dev

2020-09-21-01
This commit is contained in:
Keirua 2020-09-21 20:49:23 +02:00 committed by GitHub
commit 216485a5b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 60 additions and 101 deletions

View file

@ -117,7 +117,7 @@ group :development, :test do
gem 'graphql-schema_comparator'
gem 'mina', git: 'https://github.com/mina-deploy/mina.git', require: false # Deploy
gem 'pry-byebug'
gem 'rspec-rails', '~> 4.0.0.beta'
gem 'rspec-rails'
gem 'rspec_junit_formatter', require: false
gem 'ruby-debug-ide', require: false
gem 'simple_xlsx_reader'

View file

@ -83,7 +83,7 @@ GEM
zeitwerk (~> 2.2, >= 2.2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
administrate (0.13.0)
administrate (0.14.0)
actionpack (>= 4.2)
actionview (>= 4.2)
activerecord (>= 4.2)
@ -149,7 +149,7 @@ GEM
selenium-webdriver
case_transform (0.2)
activesupport
caxlsx (3.0.1)
caxlsx (3.0.2)
htmlentities (~> 4.3, >= 4.3.4)
mimemagic (~> 0.3)
nokogiri (~> 1.10, >= 1.10.4)
@ -195,7 +195,7 @@ GEM
sinatra (>= 1.4.4)
descendants_tracker (0.0.4)
thread_safe (~> 0.3, >= 0.3.1)
devise (4.7.2)
devise (4.7.3)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
@ -206,7 +206,7 @@ GEM
devise (>= 4.0)
devise-i18n (1.9.2)
devise (>= 4.7.1)
diff-lcs (1.3)
diff-lcs (1.4.4)
discard (1.2.0)
activerecord (>= 4.2, < 7)
domain_name (0.5.20190701)
@ -398,7 +398,7 @@ GEM
method_source (1.0.0)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.1009)
mime-types-data (3.2020.0512)
mimemagic (0.3.5)
mini_mime (1.0.2)
mini_portile2 (2.4.0)
@ -466,7 +466,7 @@ GEM
prawn (>= 0.11.1, < 3)
prawn-table (0.2.2)
prawn (>= 1.3.0, < 3.0.0)
premailer (1.13.1)
premailer (1.14.1)
addressable
css_parser (>= 1.6.0)
htmlentities (>= 4.0.0)
@ -518,10 +518,10 @@ GEM
bundler (>= 1.3.0)
railties (= 6.0.3.3)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.4)
actionpack (>= 5.0.1.x)
actionview (>= 5.0.1.x)
activesupport (>= 5.0.1.x)
rails-controller-testing (1.0.5)
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)
nokogiri (>= 1.6)
@ -577,15 +577,15 @@ GEM
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.1)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-rails (4.0.0)
rspec-rails (4.0.1)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
@ -593,7 +593,7 @@ GEM
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.9.2)
rspec-support (3.9.3)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.81.0)
@ -746,10 +746,10 @@ GEM
xray-rails (0.3.2)
rails (>= 3.1.0)
zeitwerk (2.4.0)
zip_tricks (5.0.0)
zipline (1.1.1)
zip_tricks (5.3.1)
zipline (1.2.1)
rails (>= 3.2.1, < 6.1)
zip_tricks (>= 4.2.1, <= 5.0.0)
zip_tricks (>= 4.2.1, < 6.0)
zxcvbn-ruby (1.1.0)
PLATFORMS
@ -842,7 +842,7 @@ DEPENDENCIES
rake-progressbar
react-rails
rgeo-geojson
rspec-rails (~> 4.0.0.beta)
rspec-rails
rspec_junit_formatter
rubocop
rubocop-rails_config

View file

@ -0,0 +1,4 @@
require "administrate/base_dashboard"
class DemandeDashboard < Administrate::BaseDashboard
end

View file

@ -42,7 +42,7 @@ module DossierHelper
end
def autosave_available?(dossier)
dossier.brouillon? && Flipper.enabled?(:autosave_dossier_draft, dossier.user)
dossier.brouillon?
end
def dossier_submission_is_closed?(dossier)

View file

@ -288,17 +288,7 @@ class Dossier < ApplicationRecord
scope :for_procedure, -> (procedure) { includes(:user, :groupe_instructeur).where(groupe_instructeurs: { procedure: procedure }) }
scope :for_api_v2, -> { includes(procedure: [:administrateurs], etablissement: [], individual: [], traitements: []) }
# todo: once we are sure with_cached_notifications does not introduce regressions, remove with_unoptimized_notifications
# and use with_cached_notifications instead
scope :with_notifications, -> (instructeur) do
if Flipper.enabled?(:cached_notifications, instructeur)
return with_cached_notifications
else
return with_unoptimized_notifications
end
end
scope :with_cached_notifications, -> do
scope :with_notifications, -> do
joins(:follows)
.where('last_champ_updated_at > follows.demande_seen_at' \
' OR groupe_instructeur_updated_at > follows.demande_seen_at' \
@ -308,33 +298,6 @@ class Dossier < ApplicationRecord
.distinct
end
scope :with_unoptimized_notifications, -> do
# This scope is meant to be composed, typically with Instructeur.followed_dossiers, which means that the :follows table is already INNER JOINed;
# it will fail otherwise
# rubocop:disable DS/ApplicationName
joined_dossiers = joins('LEFT OUTER JOIN "champs" ON "champs" . "dossier_id" = "dossiers" . "id" AND "champs" . "parent_id" IS NULL AND "champs" . "private" = FALSE AND "champs"."updated_at" > "follows"."demande_seen_at"')
.joins('LEFT OUTER JOIN "champs" "champs_privates_dossiers" ON "champs_privates_dossiers" . "dossier_id" = "dossiers" . "id" AND "champs_privates_dossiers" . "parent_id" IS NULL AND "champs_privates_dossiers" . "private" = TRUE AND "champs_privates_dossiers"."updated_at" > "follows"."annotations_privees_seen_at"')
.joins('LEFT OUTER JOIN "avis" ON "avis" . "dossier_id" = "dossiers" . "id" AND avis.updated_at > follows.avis_seen_at')
.joins('LEFT OUTER JOIN "commentaires" ON "commentaires" . "dossier_id" = "dossiers" . "id" and commentaires.updated_at > follows.messagerie_seen_at and "commentaires"."email" != \'contact@tps.apientreprise.fr\' AND "commentaires"."email" != \'contact@demarches-simplifiees.fr\'')
# rubocop:enable DS/ApplicationName
updated_demandes = joined_dossiers
.where('champs.updated_at > follows.demande_seen_at OR groupe_instructeur_updated_at > follows.demande_seen_at')
updated_annotations = joined_dossiers
.where('champs_privates_dossiers.updated_at > follows.annotations_privees_seen_at')
updated_avis = joined_dossiers
.where('avis.updated_at > follows.avis_seen_at')
updated_messagerie = joined_dossiers
.where('commentaires.updated_at > follows.messagerie_seen_at')
.where.not(commentaires: { email: OLD_CONTACT_EMAIL })
.where.not(commentaires: { email: CONTACT_EMAIL })
updated_demandes.or(updated_annotations).or(updated_avis).or(updated_messagerie).distinct
end
accepts_nested_attributes_for :individual
delegate :siret, :siren, to: :etablissement, allow_nil: true

View file

@ -141,14 +141,14 @@ class Instructeur < ApplicationRecord
.where(groupe_instructeur: target_groupes)
.send(scope) # :en_cours or :termine or :not_archived (or any other Dossier scope)
.merge(followed_dossiers)
.with_notifications(self)
.with_notifications
end
def procedure_ids_with_notifications(scope)
groupe_instructeur_ids = Dossier
.send(scope) # :en_cours or :termine (or any other Dossier scope)
.merge(followed_dossiers)
.with_notifications(self)
.with_notifications
.select(:groupe_instructeur_id)
GroupeInstructeur.where(id: groupe_instructeur_ids).pluck(:procedure_id)

View file

@ -91,7 +91,7 @@ class ProcedurePresentation < ApplicationRecord
case table
when 'notifications'
dossiers_id_with_notification = dossiers.merge(instructeur.followed_dossiers).with_notifications(instructeur).ids
dossiers_id_with_notification = dossiers.merge(instructeur.followed_dossiers).with_notifications.ids
if order == 'desc'
return dossiers_id_with_notification +
(dossiers.order('dossiers.updated_at desc').ids - dossiers_id_with_notification)

View file

@ -47,8 +47,8 @@
= link_to "Créez une démarche de test",
new_demande_path,
= link_to "Créer votre compte administrateur",
DEMANDE_INSCRIPTION_ADMIN_PAGE_URL,
class: "role-panel-button-primary",
rel: "noopener noreferrer"
%br
@ -204,8 +204,8 @@
.half.first-half
%h1.cta-panel-title Vous êtes prêt pour dématérialiser ?
%p.cta-panel-explanation Réduisez vos temps d'instruction de 50 %
= link_to "Créer une démarche de test",
new_demande_path,
= link_to "Créer votre compte administrateur",
DEMANDE_INSCRIPTION_ADMIN_PAGE_URL,
class: "cta-panel-button-blue"
.half

View file

@ -28,7 +28,6 @@ features = [
:administrateur_web_hook,
:insee_api_v3,
:instructeur_bypass_email_login_token,
:autosave_dossier_draft,
:maintenance_mode,
:mini_profiler,
:xray,

View file

@ -40,6 +40,7 @@ FAQ_OU_EN_EST_MON_DOSSIER_URL = [FAQ_URL, "article", "11-je-veux-savoir-ou-en-es
FAQ_ERREUR_SIRET_URL = [FAQ_URL, "article", "4-erreur-siret"].join("/")
STATUS_PAGE_URL = ENV.fetch("STATUS_PAGE_URL", "https://status.demarches-simplifiees.fr")
DEMANDE_INSCRIPTION_ADMIN_PAGE_URL = ENV.fetch("DEMANDE_INSCRIPTION_ADMIN_PAGE_URL", "https://www.demarches-simplifiees.fr/commencer/demande-d-inscription-a-demarches-simplifiees")
MATOMO_IFRAME_URL = "https://stats.data.gouv.fr/index.php?module=CoreAdminHome&action=optOut&language=fr&&fontColor=333333&fontSize=16px&fontFamily=Muli"
# rubocop:enable DS/ApplicationName

View file

@ -454,9 +454,9 @@ describe Instructeurs::DossiersController, type: :controller do
before { follower.follow(dossier) }
it 'the follower has a notification' do
expect(follower.followed_dossiers.with_notifications(follower)).to eq([])
expect(follower.followed_dossiers.with_notifications).to eq([])
subject
expect(follower.followed_dossiers.with_notifications(follower)).to eq([dossier.reload])
expect(follower.followed_dossiers.with_notifications).to eq([dossier.reload])
end
end
end
@ -671,8 +671,8 @@ describe Instructeurs::DossiersController, type: :controller do
it 'updates the annotations' do
Timecop.travel(now + 1.hour)
expect(instructeur.followed_dossiers.with_notifications(instructeur)).to eq([])
expect(another_instructeur.followed_dossiers.with_notifications(instructeur)).to eq([dossier.reload])
expect(instructeur.followed_dossiers.with_notifications).to eq([])
expect(another_instructeur.followed_dossiers.with_notifications).to eq([dossier.reload])
end
end

View file

@ -693,9 +693,9 @@ describe Users::DossiersController, type: :controller do
end
it 'the follower has a notification' do
expect(instructeur.reload.followed_dossiers.with_notifications(instructeur)).to eq([])
expect(instructeur.reload.followed_dossiers.with_notifications).to eq([])
subject
expect(instructeur.reload.followed_dossiers.with_notifications(instructeur)).to eq([dossier.reload])
expect(instructeur.reload.followed_dossiers.with_notifications).to eq([dossier.reload])
end
end
@ -887,8 +887,6 @@ describe Users::DossiersController, type: :controller do
before do
Timecop.freeze(now)
sign_in(user)
# Flipper.enable(:cached_notifications, instructeur_with_instant_message)
# Flipper.enable(:cached_notifications, instructeur_without_instant_message)
allow(ClamavService).to receive(:safe_file?).and_return(scan_result)
allow(DossierMailer).to receive(:notify_new_commentaire_to_instructeur).and_return(double(deliver_later: nil))
instructeur_with_instant_message.follow(dossier)
@ -913,15 +911,15 @@ describe Users::DossiersController, type: :controller do
context 'notification' do
before 'instructeurs have no notification before the message' do
expect(instructeur_with_instant_message.followed_dossiers.with_notifications(instructeur_with_instant_message)).to eq([])
expect(instructeur_without_instant_message.followed_dossiers.with_notifications(instructeur_without_instant_message)).to eq([])
expect(instructeur_with_instant_message.followed_dossiers.with_notifications).to eq([])
expect(instructeur_without_instant_message.followed_dossiers.with_notifications).to eq([])
Timecop.travel(now + 1.day)
subject
end
it 'adds them a notification' do
expect(instructeur_with_instant_message.reload.followed_dossiers.with_notifications(instructeur_with_instant_message)).to eq([dossier.reload])
expect(instructeur_without_instant_message.reload.followed_dossiers.with_notifications(instructeur_without_instant_message)).to eq([dossier.reload])
expect(instructeur_with_instant_message.reload.followed_dossiers.with_notifications).to eq([dossier.reload])
expect(instructeur_without_instant_message.reload.followed_dossiers.with_notifications).to eq([dossier.reload])
end
end
end

View file

@ -42,8 +42,8 @@ feature 'The user' do
fill_in('dossier_link', with: '123')
find('.editable-champ-piece_justificative input[type=file]').attach_file(Rails.root + 'spec/fixtures/files/file.pdf')
click_on 'Enregistrer le brouillon'
expect(page).to have_content('Votre brouillon a bien été sauvegardé')
blur
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
# check data on the dossier
expect(user_dossier.brouillon?).to be true
@ -116,7 +116,8 @@ feature 'The user' do
expect(page).to have_content('Supprimer', count: 2)
click_on 'Enregistrer le brouillon'
blur
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
expect(page).to have_content('Supprimer', count: 2)
@ -124,13 +125,17 @@ feature 'The user' do
click_on 'Supprimer lélément'
end
click_on 'Enregistrer le brouillon'
blur
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
expect(page).to have_content('Supprimer', count: 1)
end
let(:simple_procedure) do
tdcs = [build(:type_de_champ, mandatory: true, libelle: 'texte obligatoire')]
tdcs = [
build(:type_de_champ, mandatory: true, libelle: 'texte obligatoire'),
build(:type_de_champ, mandatory: false, libelle: 'texte optionnel')
]
create(:procedure, :published, :for_individual, types_de_champ: tdcs)
end
@ -139,9 +144,9 @@ feature 'The user' do
fill_individual
# Check an incomplete dossier can be saved as a draft, even when mandatory fields are missing
click_on 'Enregistrer le brouillon'
expect(user_dossier.reload.brouillon?).to be(true)
expect(page).to have_content('Votre brouillon a bien été sauvegardé')
fill_in('texte optionnel', with: 'ça ne suffira pas')
blur
expect(page).to have_css('span', text: 'Brouillon enregistré', visible: true)
expect(page).to have_current_path(brouillon_dossier_path(user_dossier))
# Check an incomplete dossier cannot be submitted when mandatory fields are missing
@ -185,7 +190,6 @@ feature 'The user' do
expect(page).to have_text('RIB.pdf')
# Expect the submit buttons to be enabled
expect(page).to have_button('Enregistrer le brouillon', disabled: false)
expect(page).to have_button('Déposer le dossier', disabled: false)
# Reload the current page
@ -226,7 +230,6 @@ feature 'The user' do
attach_file('Pièce justificative 1', Rails.root + 'spec/fixtures/files/file.pdf')
expect(page).to have_text('Une erreur sest produite pendant lenvoi du fichier')
expect(page).to have_button('Ré-essayer', visible: true)
expect(page).to have_button('Enregistrer le brouillon', disabled: false)
expect(page).to have_button('Déposer le dossier', disabled: false)
# Test that retrying after a failure works
@ -234,7 +237,6 @@ feature 'The user' do
click_on('Ré-essayer', visible: true)
expect(page).to have_text('analyse antivirus en cours')
expect(page).to have_text('file.pdf')
expect(page).to have_button('Enregistrer le brouillon', disabled: false)
expect(page).to have_button('Déposer le dossier', disabled: false)
# Reload the current page
@ -244,11 +246,7 @@ feature 'The user' do
expect(page).to have_text('file.pdf')
end
context 'when the draft autosave is enabled' do
before do
Flipper.enable_actor(:autosave_dossier_draft, user)
end
context 'draft autosave' do
scenario 'autosave a draft', js: true do
log_in(user, simple_procedure)
fill_individual

View file

@ -53,8 +53,7 @@ feature 'Invitations' do
expect(page).to have_no_selector('.button.invite-user-action')
fill_in 'Texte obligatoire', with: 'Some edited value'
click_button 'Enregistrer le brouillon'
expect(page).to have_text('Votre brouillon a bien été sauvegardé')
blur
expect(page).to have_field('Texte obligatoire', with: 'Some edited value')
end

View file

@ -103,10 +103,9 @@ describe Dossier do
before do
create(:follow, dossier: dossier, instructeur: instructeur, messagerie_seen_at: 2.hours.ago)
Flipper.enable_actor(:cached_notifications, instructeur)
end
subject { instructeur.followed_dossiers.with_notifications(instructeur) }
subject { instructeur.followed_dossiers.with_notifications }
context('without changes') do
it { is_expected.to eq [] }

View file

@ -8,7 +8,6 @@ describe Instructeur, type: :model do
before do
assign(procedure_2)
Flipper.enable_actor(:cached_notifications, instructeur)
end
describe 'follow' do

View file

@ -262,7 +262,6 @@ describe ProcedurePresentation do
let!(:older_dossier) { create(:dossier, :en_construction, procedure: procedure) }
before do
Flipper.enable_actor(:cached_notifications, instructeur)
notified_dossier.update!(last_champ_updated_at: Time.zone.local(2018, 9, 20))
create(:follow, instructeur: instructeur, dossier: notified_dossier, demande_seen_at: Time.zone.local(2018, 9, 10))
notified_dossier.touch(time: Time.zone.local(2018, 9, 20))