demarches-normaliennes/app/jobs/find_dubious_procedures_job.rb
Pierre de La Morinerie 3c91cfc83c jobs: add health-related keywords to dubious procedures scanner
We are not certified for hosting health-related data yet.
2020-08-25 12:04:10 +00:00

32 lines
1.3 KiB
Ruby

class FindDubiousProceduresJob < 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'
]
def perform(*args)
# \\y is a word boundary
forbidden_regexp = FORBIDDEN_KEYWORDS
.map { |keyword| "\\y#{keyword}\\y" }
.join('|')
# ~* -> 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(?)", 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(&:procedure_id)
.map { |_procedure_id, tdcs| [tdcs[0].procedure, tdcs] }
AdministrationMailer.dubious_procedures(dubious_procedures_and_tdcs).deliver_later
end
end