2022-05-16 12:20:24 +02:00
class DubiousProcedure
extend ActiveModel :: Naming
extend ActiveModel :: Translation
2023-07-21 16:15:25 +02:00
attr_accessor :id , :libelle , :dubious_champs , :aasm_state , :hidden_at_as_template
2022-05-16 12:20:24 +02:00
FORBIDDEN_KEYWORDS = [
2023-06-19 14:30:29 +02:00
'NIR' , 'RNIPP' , 'race' , 'religion' , 'RIB' ,
2022-05-16 12:20:24 +02:00
'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 persisted?
false
end
def self . all
procedures_with_forbidden_tdcs_sql = TypeDeChamp
. joins ( :procedure )
2023-07-21 16:15:25 +02:00
. select ( " string_agg(types_de_champ.libelle, ' - ') as dubious_champs, procedures.id as procedure_id, procedures.libelle as procedure_libelle, procedures.aasm_state as procedure_aasm_state, procedures.hidden_at_as_template as procedure_hidden_at_as_template " )
2022-05-16 12:20:24 +02:00
. 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 } )
. group ( " procedures.id " )
. order ( " procedures.id asc " )
. to_sql
ActiveRecord :: Base . connection . execute ( procedures_with_forbidden_tdcs_sql ) . map do | procedure |
p = DubiousProcedure . new
p . id = procedure [ " procedure_id " ]
p . dubious_champs = procedure [ " dubious_champs " ]
p . libelle = procedure [ " procedure_libelle " ]
p . aasm_state = procedure [ " procedure_aasm_state " ]
2023-07-21 16:15:25 +02:00
p . hidden_at_as_template = procedure [ " procedure_hidden_at_as_template " ]
2022-05-16 12:20:24 +02:00
p
end
end
# \\y is a word boundary
def self . forbidden_regexp
FORBIDDEN_KEYWORDS . map { | keyword | " \\ y #{ keyword } \\ y " }
. join ( '|' )
end
end