2018-01-05 11:16:50 +01:00
|
|
|
class FindDubiousProceduresJob < ApplicationJob
|
|
|
|
queue_as :cron
|
|
|
|
|
2018-01-15 14:42:48 +01:00
|
|
|
FORBIDDEN_KEYWORDS = [
|
2018-05-23 13:34:13 +02:00
|
|
|
'NIR', 'NIRPP', 'race', 'religion',
|
2018-05-31 11:28:31 +02:00
|
|
|
'carte bancaire', 'carte bleue', 'sécurité sociale',
|
|
|
|
'agdref', 'handicap', 'syndicat', 'syndical',
|
|
|
|
'parti politique', 'opinion politique', 'bord politique', 'courant politique'
|
2018-01-15 14:42:48 +01:00
|
|
|
]
|
2018-01-05 11:16:50 +01:00
|
|
|
|
|
|
|
def perform(*args)
|
|
|
|
# \\y is a word boundary
|
|
|
|
forbidden_regexp = FORBIDDEN_KEYWORDS
|
2018-01-15 21:41:16 +01:00
|
|
|
.map { |keyword| "\\y#{keyword}\\y" }
|
2018-01-05 11:16:50 +01:00
|
|
|
.join('|')
|
|
|
|
|
|
|
|
# ~* -> case insensitive regexp match
|
|
|
|
# https://www.postgresql.org/docs/current/static/functions-matching.html#FUNCTIONS-POSIX-REGEXP
|
|
|
|
forbidden_tdcs = TypeDeChamp
|
|
|
|
.joins(:procedure)
|
2018-04-11 09:38:58 +02:00
|
|
|
.where("unaccent(types_de_champ.libelle) ~* unaccent(?)", forbidden_regexp)
|
2018-01-05 11:16:50 +01:00
|
|
|
.where(type_champ: %w(text textarea))
|
2018-01-05 17:08:43 +01:00
|
|
|
.where(procedures: { archived_at: nil, whitelisted_at: nil })
|
2018-01-05 11:16:50 +01:00
|
|
|
|
|
|
|
dubious_procedures_and_tdcs = forbidden_tdcs
|
|
|
|
.group_by(&:procedure_id)
|
|
|
|
.map { |_procedure_id, tdcs| [tdcs[0].procedure, tdcs] }
|
|
|
|
|
2018-05-25 18:05:28 +02:00
|
|
|
AdministrationMailer.dubious_procedures(dubious_procedures_and_tdcs).deliver_later
|
2018-01-05 11:16:50 +01:00
|
|
|
end
|
|
|
|
end
|