remove warning mail for dubious procedures

This commit is contained in:
Christophe Robillard 2022-05-16 15:02:19 +02:00
parent fd98247b48
commit f14cd7b022
5 changed files with 0 additions and 131 deletions

View file

@ -1,33 +0,0 @@
class Cron::FindDubiousProceduresJob < Cron::CronJob
self.schedule_expression = "every day at midnight"
FORBIDDEN_KEYWORDS = [
'NIR', 'NIRPP', 'race', 'religion',
'carte bancaire', 'carte bleue', 'sécurité sociale',
'agdref', 'syndicat', 'syndical',
'parti politique', 'opinion politique', 'bord politique', 'courant politique',
'médical', 'handicap', 'maladie', 'allergie', 'hospitalisé', 'RQTH', 'vaccin'
]
# \\y is a word boundary
def self.forbidden_regexp
FORBIDDEN_KEYWORDS.map { |keyword| "\\y#{keyword}\\y" }
.join('|')
end
def perform(*args)
# ~* -> case insensitive regexp match
# https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
forbidden_tdcs = TypeDeChamp
.joins(:procedure)
.where("unaccent(types_de_champ.libelle) ~* unaccent(?)", Cron::FindDubiousProceduresJob.forbidden_regexp)
.where(type_champ: [TypeDeChamp.type_champs.fetch(:text), TypeDeChamp.type_champs.fetch(:textarea)])
.where(procedures: { closed_at: nil, whitelisted_at: nil })
dubious_procedures_and_tdcs = forbidden_tdcs
.group_by { |type_de_champ| type_de_champ.procedure.id }
.map { |_procedure_id, tdcs| [tdcs[0].procedure, tdcs] }
AdministrationMailer.dubious_procedures(dubious_procedures_and_tdcs).deliver_later
end
end

View file

@ -20,12 +20,4 @@ class AdministrationMailer < ApplicationMailer
subject: subject,
reply_to: CONTACT_EMAIL)
end
def dubious_procedures(procedures_and_type_de_champs)
@procedures_and_type_de_champs = procedures_and_type_de_champs
subject = "[RGS] De nouvelles démarches comportent des champs interdits"
mail(to: EQUIPE_EMAIL,
subject: subject)
end
end

View file

@ -1,21 +0,0 @@
- content_for(:title, 'Liste de démarches douteuses')
- if @procedures_and_type_de_champs.any?
%ul
- @procedures_and_type_de_champs.each do |procedure, type_de_champs|
%li{ style: 'margin-bottom: 8px;' }
= link_to "Nº #{procedure.id},", manager_procedure_url(procedure)
 #{procedure.libelle} :
%b= type_de_champs.map(&:libelle).join(', ')
%br
État : #{procedure.aasm_state}
%br
Nombre de dossier : #{procedure.dossiers.count}
%br
Admin :
%ul
- procedure.administrateurs.each do |administrateur|
%li
= link_to "#{administrateur.email}", "mailto:#{administrateur.email}"
- else
Il ny a aucune démarche douteuse aujourd'hui

View file

@ -1,61 +0,0 @@
RSpec.describe Cron::FindDubiousProceduresJob, type: :job do
describe 'perform' do
let(:mailer_double) { double('mailer', deliver_later: true) }
let(:procedure) { create(:procedure, types_de_champ: tdcs) }
let(:allowed_tdc) { build(:type_de_champ, libelle: 'fournir') }
before do
procedure
allow(AdministrationMailer).to receive(:dubious_procedures) do |arg|
@dubious_procedures_args = arg
end.and_return(mailer_double)
Cron::FindDubiousProceduresJob.new.perform
end
context 'with suspicious champs' do
let(:forbidden_tdcs) do
[
build(:type_de_champ, libelle: 'num de securite sociale, stp'),
build(:type_de_champ, libelle: "t'aurais une carte bancaire ?")
]
end
let(:tdcs) { forbidden_tdcs + [allowed_tdc] }
it 'mails tech about the dubious procedure' do
receive_procedure, receive_forbidden_tdcs = @dubious_procedures_args[0]
expect(receive_procedure).to eq(procedure)
expect(receive_forbidden_tdcs).to match_array(forbidden_tdcs)
expect(AdministrationMailer).to have_received(:dubious_procedures).with(@dubious_procedures_args)
end
context 'and a whitelisted procedure' do
let(:procedure) { create(:procedure, :whitelisted) }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
context 'and a closed procedure' do
let(:procedure) { create(:procedure, :closed) }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
context 'and a discarded procedure' do
let(:procedure) { create(:procedure, :discarded) }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
end
context 'with no suspicious champs' do
let(:tdcs) { [allowed_tdc] }
it { expect(AdministrationMailer).to have_received(:dubious_procedures).with([]) }
end
end
end

View file

@ -28,12 +28,4 @@ RSpec.describe AdministrationMailer, type: :mailer do
it { expect(subject.subject).not_to be_empty }
end
describe '#dubious_procedures' do
let(:procedures_and_type_de_champs) { [] }
subject { described_class.dubious_procedures(procedures_and_type_de_champs) }
it { expect(subject.subject).not_to be_empty }
end
end