Merge pull request #6185 from betagouv/main

2021-05-07-01
This commit is contained in:
LeSim 2021-05-07 12:10:23 +02:00 committed by GitHub
commit 03acf89fa7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 33 additions and 475 deletions

View file

@ -5,7 +5,8 @@ gem 'active_link_to' # Automatically set a class on active links
gem 'active_model_serializers' gem 'active_model_serializers'
gem 'activestorage-openstack' gem 'activestorage-openstack'
gem 'active_storage_validations' gem 'active_storage_validations'
gem 'administrate', git: 'https://github.com/thoughtbot/administrate.git', ref: 'refs/pull/1972/head' # Provides an administration UI (pull request #1972 has fixes for Rails 6.1.3.2) gem 'administrate'
gem 'administrate-field-enum' # Allow using Field::Enum in administrate
gem 'after_party' gem 'after_party'
gem 'anchored' gem 'anchored'
gem 'bcrypt' gem 'bcrypt'

View file

@ -6,22 +6,6 @@ GIT
open4 (~> 1.3.4) open4 (~> 1.3.4)
rake rake
GIT
remote: https://github.com/thoughtbot/administrate.git
revision: 27404f6bbbfa8ae7227ff205ac8cc4ad194194dd
ref: refs/pull/1972/head
specs:
administrate (0.15.0)
actionpack (>= 5.0)
actionview (>= 5.0)
activerecord (>= 5.0)
datetime_picker_rails (~> 0.0.7)
jquery-rails (>= 4.0)
kaminari (>= 1.0)
momentjs-rails (~> 2.8)
sassc-rails (~> 2.1)
selectize-rails (~> 0.6)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@ -102,6 +86,18 @@ GEM
zeitwerk (~> 2.3) zeitwerk (~> 2.3)
addressable (2.7.0) addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0) public_suffix (>= 2.0.2, < 5.0)
administrate (0.16.0)
actionpack (>= 5.0)
actionview (>= 5.0)
activerecord (>= 5.0)
datetime_picker_rails (~> 0.0.7)
jquery-rails (>= 4.0)
kaminari (>= 1.0)
momentjs-rails (~> 2.8)
sassc-rails (~> 2.1)
selectize-rails (~> 0.6)
administrate-field-enum (0.0.9)
administrate (~> 0.12)
aes_key_wrap (1.1.0) aes_key_wrap (1.1.0)
after_party (1.11.2) after_party (1.11.2)
anchored (1.1.0) anchored (1.1.0)
@ -253,7 +249,7 @@ GEM
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
ruby2_keywords ruby2_keywords
faraday-net_http (1.0.1) faraday-net_http (1.0.1)
ffi (1.14.2) ffi (1.15.0)
flipper (0.20.3) flipper (0.20.3)
flipper-active_record (0.20.3) flipper-active_record (0.20.3)
activerecord (>= 5.0, < 7) activerecord (>= 5.0, < 7)
@ -775,7 +771,8 @@ DEPENDENCIES
active_model_serializers active_model_serializers
active_storage_validations active_storage_validations
activestorage-openstack activestorage-openstack
administrate! administrate
administrate-field-enum
after_party after_party
anchored anchored
annotate annotate

View file

@ -10,7 +10,7 @@ class DossierDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = { ATTRIBUTE_TYPES = {
id: Field::Number.with_options(searchable: true), id: Field::Number.with_options(searchable: true),
procedure: Field::HasOne, procedure: Field::HasOne,
state: Field::String, state: Field::Enum,
user: Field::BelongsTo, user: Field::BelongsTo,
text_summary: Field::String.with_options(searchable: false), text_summary: Field::String.with_options(searchable: false),
created_at: Field::DateTime, created_at: Field::DateTime,

View file

@ -1088,7 +1088,7 @@ enum DossierState {
refuse refuse
""" """
Sans suite Classé sans suite
""" """
sans_suite sans_suite
} }

View file

@ -2,7 +2,7 @@ module Types
class DossierType < Types::BaseObject class DossierType < Types::BaseObject
class DossierState < Types::BaseEnum class DossierState < Types::BaseEnum
Dossier.aasm.states.reject { |state| state.name == :brouillon }.each do |state| Dossier.aasm.states.reject { |state| state.name == :brouillon }.each do |state|
value(state.name.to_s, state.display_name, value: state.name.to_s) value(state.name.to_s, Dossier.human_attribute_name("state.#{state.name}"), value: state.name.to_s)
end end
end end

View file

@ -51,7 +51,7 @@ module DossierHelper
def dossier_display_state(dossier_or_state, lower: false) def dossier_display_state(dossier_or_state, lower: false)
state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state state = dossier_or_state.is_a?(Dossier) ? dossier_or_state.state : dossier_or_state
display_state = I18n.t(state, scope: [:activerecord, :attributes, :dossier, :state]) display_state = Dossier.human_attribute_name("state.#{state}")
lower ? display_state.downcase : display_state lower ? display_state.downcase : display_state
end end

View file

@ -91,7 +91,7 @@ Rails.application.configure do
if ENV['HELO_ENABLED'] == 'enabled' if ENV['HELO_ENABLED'] == 'enabled'
config.action_mailer.delivery_method = :smtp config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { config.action_mailer.smtp_settings = {
user_name: APPLICATION_NAME, user_name: 'demarches-simplifiees',
password: '', password: '',
address: '127.0.0.1', address: '127.0.0.1',
domain: '127.0.0.1', domain: '127.0.0.1',

View file

@ -9,20 +9,16 @@ fr:
montant_projet: 'Le montant du projet' montant_projet: 'Le montant du projet'
montant_aide_demande: "Le montant daide demandée" montant_aide_demande: "Le montant daide demandée"
date_previsionnelle: "La date de début prévisionnelle" date_previsionnelle: "La date de début prévisionnelle"
state: &state state: "État"
autorisation_donnees: Acceptation des CGU
dossier/state: &state
brouillon: "Brouillon" brouillon: "Brouillon"
en_construction: "En construction" en_construction: "En construction"
en_instruction: "En instruction" en_instruction: "En instruction"
accepte: "Accepté" accepte: "Accepté"
refuse: "Refusé" refuse: "Refusé"
sans_suite: "Classé sans suite" sans_suite: "Classé sans suite"
autorisation_donnees: Acceptation des CGU
state/brouillon: Brouillon
state/en_construction: En construction
state/en_instruction: En instruction
state/accepte: Accepté
state/refuse: Refusé
state/sans_suite: Sans suite
traitement: traitement:
state: state: "État"
traitement/state:
<<: *state <<: *state

View file

@ -1,10 +0,0 @@
namespace :after_party do
desc 'Deployment task: cleanup_deleted_dossiers'
task cleanup_deleted_dossiers: :environment do
puts "Running deploy task 'cleanup_deleted_dossiers'"
DeletedDossier.where(state: :brouillon).destroy_all
AfterParty::TaskRecord.create version: '20200326133630'
end
end

View file

@ -1,27 +0,0 @@
namespace :after_party do
desc 'Deployment task: process_expired_dossiers_en_construction'
task process_expired_dossiers_en_construction: :environment do
puts "Running deploy task 'process_expired_dossiers_en_construction'"
if ENV['APP_NAME'] == 'tps'
dossiers_close_to_expiration = Dossier
.en_construction_close_to_expiration
.without_en_construction_expiration_notice_sent
ExpiredDossiersDeletionService.send_expiration_notices(dossiers_close_to_expiration)
BATCH_SIZE = 1000
((dossiers_close_to_expiration.count / BATCH_SIZE).ceil + 1).times do |n|
dossiers_close_to_expiration
.offset(n * BATCH_SIZE)
.limit(BATCH_SIZE)
.update_all(en_construction_close_to_expiration_notice_sent_at: Time.zone.now + n.days)
end
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20200401123317'
end
end

View file

@ -1,35 +0,0 @@
namespace :after_party do
desc 'Deployment task: fix_champ_etablissement'
task fix_champ_etablissement: :environment do
puts "Running deploy task 'fix_champ_etablissement'"
etablissements = Etablissement.joins(:champ).where.not(dossier_id: nil).where('etablissements.created_at > ?', 1.month.ago)
dossiers_modif = []
etablissements.find_each do |e|
if e.dossier
user = e.dossier.user
dossier = e.dossier
if user.dossiers.count == 1 && user.siret == e.champ.value
e.update!(dossier_id: nil)
dossier.reload.etablissement = e.reload.dup
dossier.save!
dossiers_modif << dossier.id
fetch_api_entreprise_infos(dossier.etablissement.id, dossier.procedure.id, user.id)
end
end
end
puts "Nb dossiers modifiés: #{dossiers_modif.size}"
AfterParty::TaskRecord.create version: '20200527124112'
end
def fetch_api_entreprise_infos(etablissement_id, procedure_id, user_id)
[
APIEntreprise::EntrepriseJob, APIEntreprise::AssociationJob, APIEntreprise::ExercicesJob,
APIEntreprise::EffectifsJob, APIEntreprise::EffectifsAnnuelsJob, APIEntreprise::AttestationSocialeJob,
APIEntreprise::BilansBdfJob
].each do |job|
job.perform_later(etablissement_id, procedure_id)
end
APIEntreprise::AttestationFiscaleJob.perform_later(etablissement_id, procedure_id, user_id)
end
end

View file

@ -1,20 +0,0 @@
namespace :after_party do
desc 'Deployment task: fix_dossier_etablissement'
task fix_dossier_etablissement: :environment do
puts "Running deploy task 'fix_dossier_etablissement'"
etablissements = Etablissement.joins(:champ).where.not(dossier_id: nil).where('etablissements.created_at > ?', 1.month.ago)
dossiers_modif = []
etablissements.find_each do |e|
if e.dossier
dossier = e.dossier
e.update!(dossier_id: nil)
dossier.reload.etablissement = e.reload.dup
dossier.save!
dossiers_modif << dossier.id
end
end
puts "Nb dossiers modifiés: #{dossiers_modif.size}"
AfterParty::TaskRecord.create version: '20200528124044'
end
end

View file

@ -1,25 +0,0 @@
namespace :after_party do
desc 'Deployment task: drop_down_list_options_to_json'
task drop_down_list_options_to_json: :environment do
puts "Running deploy task 'drop_down_list_options_to_json'"
types_de_champ = TypeDeChamp.joins(:drop_down_list).where(type_champ: [
TypeDeChamp.type_champs.fetch(:drop_down_list),
TypeDeChamp.type_champs.fetch(:multiple_drop_down_list),
TypeDeChamp.type_champs.fetch(:linked_drop_down_list)
])
progress = ProgressReport.new(types_de_champ.count)
types_de_champ.find_each do |type_de_champ|
type_de_champ.drop_down_list_value = type_de_champ.drop_down_list_value
if type_de_champ.save
type_de_champ.drop_down_list.destroy
end
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20200618121241'
end
end

View file

@ -1,22 +0,0 @@
namespace :after_party do
desc 'Deployment task: migrate_revisions'
task migrate_revisions: :environment do
puts "Running deploy task 'migrate_revisions'"
procedures = Procedure.with_discarded.where(draft_revision_id: nil)
progress = ProgressReport.new(procedures.count)
puts "Processing procedures"
procedures.find_each do |procedure|
RevisionsMigration.add_revisions(procedure)
progress.inc
end
progress.finish
TmpDossiersMigrateRevisionsJob.perform_later([])
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20200625113026'
end
end

View file

@ -1,18 +0,0 @@
namespace :after_party do
desc 'Deployment task: add_traitements_from_dossiers'
task add_traitements_from_dossiers: :environment do
puts "Running deploy task 'add_traitements_from_dossiers'"
dossiers_termines = Dossier.state_termine
progress = ProgressReport.new(dossiers_termines.count)
dossiers_termines.find_each do |dossier|
dossier.traitements.create!(state: dossier.state, motivation: dossier.motivation, processed_at: dossier.processed_at)
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20200630154829'
end
end

View file

@ -1,18 +0,0 @@
namespace :after_party do
desc 'Deployment task: add_default_skip_validation_to_piece_justificative'
task add_default_skip_validation_to_piece_justificative: :environment do
puts "Running deploy task 'add_default_skip_validation_to_piece_justificative'"
tdcs = TypeDeChamp.where(type_champ: TypeDeChamp.type_champs.fetch(:piece_justificative))
progress = ProgressReport.new(tdcs.count)
tdcs.find_each do |tdc|
tdc.update(skip_pj_validation: true)
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20200708101123'
end
end

View file

@ -1,25 +0,0 @@
namespace :after_party do
desc 'Deployment task: fix_cloned_revisions'
task fix_cloned_revisions: :environment do
puts "Running deploy task 'fix_cloned_revisions'"
Procedure.with_discarded.where(aasm_state: :brouillon).where.not(published_revision_id: nil).update_all(published_revision_id: nil)
types_de_champ = TypeDeChamp.joins(:revision).where('types_de_champ.procedure_id != procedure_revisions.procedure_id')
progress = ProgressReport.new(types_de_champ.count)
types_de_champ.find_each do |type_de_champ|
procedure = type_de_champ.procedure ? type_de_champ.procedure : Procedure.with_discarded.find(type_de_champ.procedure_id)
revision_id = procedure.published_revision_id || procedure.draft_revision_id
type_de_champ.update_column(:revision_id, revision_id)
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -1,71 +0,0 @@
namespace :after_party do
desc 'Deployment task: fix_geo_areas_geometry'
task fix_geo_areas_geometry: :environment do
puts "Running deploy task 'fix_geo_areas_geometry'"
geometry_collections = GeoArea.where("geometry -> 'type' = '\"GeometryCollection\"'")
multi_polygons = GeoArea.where("geometry -> 'type' = '\"MultiPolygon\"'")
multi_line_strings = GeoArea.where("geometry -> 'type' = '\"MultiLineString\"'")
def valid_geometry?(geometry)
RGeo::GeoJSON.decode(geometry.to_json, geo_factory: RGeo::Geographic.simple_mercator_factory)
true
rescue
false
end
progress = ProgressReport.new(geometry_collections.count)
geometry_collections.find_each do |geometry_collection|
geometry_collection.geometry['geometries'].each do |geometry|
if valid_geometry?(geometry)
geometry_collection.champ.geo_areas.create!(geometry: geometry, source: 'selection_utilisateur')
end
end
geometry_collection.destroy
progress.inc
end
progress.finish
progress = ProgressReport.new(multi_line_strings.count)
multi_line_strings.find_each do |multi_line_string|
multi_line_string.geometry['coordinates'].each do |coordinates|
geometry = {
type: 'LineString',
coordinates: coordinates
}
if valid_geometry?(geometry)
multi_line_string.champ.geo_areas.create!(geometry: geometry, source: 'selection_utilisateur')
end
end
multi_line_string.destroy
progress.inc
end
progress.finish
progress = ProgressReport.new(multi_polygons.count)
multi_polygons.find_each do |multi_polygon|
multi_polygon.geometry['coordinates'].each do |coordinates|
geometry = {
type: 'Polygon',
coordinates: coordinates
}
if valid_geometry?(geometry)
multi_polygon.champ.geo_areas.create!(geometry: geometry, source: 'selection_utilisateur')
end
end
multi_polygon.destroy
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -1,50 +0,0 @@
namespace :after_party do
desc 'Deployment task: migrate_filters_to_use_stable_id'
task migrate_filters_to_use_stable_id: :environment do
puts "Running deploy task 'migrate_filters_to_use_stable_id'"
procedure_presentations = ProcedurePresentation.where("filters -> 'migrated' IS NULL")
progress = ProgressReport.new(procedure_presentations.count)
procedure_presentations.find_each do |procedure_presentation|
filters = procedure_presentation.filters
sort = procedure_presentation.sort
displayed_fields = procedure_presentation.displayed_fields
['tous', 'suivis', 'traites', 'a-suivre', 'archives'].each do |statut|
filters[statut] = filters[statut].map do |filter|
table, column = filter.values_at('table', 'column')
if table && (table == 'type_de_champ' || table == 'type_de_champ_private')
type_de_champ = TypeDeChamp.find_by(id: column)
filter['column'] = type_de_champ&.stable_id&.to_s
end
filter
end
end
table, column = sort.values_at('table', 'column')
if table && (table == 'type_de_champ' || table == 'type_de_champ_private')
type_de_champ = TypeDeChamp.find_by(id: column)
sort['column'] = type_de_champ&.stable_id&.to_s
end
displayed_fields = displayed_fields.map do |displayed_field|
table, column = displayed_field.values_at('table', 'column')
if table && (table == 'type_de_champ' || table == 'type_de_champ_private')
type_de_champ = TypeDeChamp.find_by(id: column)
displayed_field['column'] = type_de_champ&.stable_id&.to_s
end
displayed_field
end
filters['migrated'] = true
procedure_presentation.update_columns(filters: filters, sort: sort, displayed_fields: displayed_fields)
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -1,11 +0,0 @@
namespace :after_party do
desc 'Deployment task: setup_first_stats'
task setup_first_stats: :environment do
Stat.update_stats
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -1,19 +0,0 @@
namespace :after_party do
desc 'Deployment task: fix_types_de_champ_revisions'
task fix_types_de_champ_revisions: :environment do
puts "Running deploy task 'fix_types_de_champ_revisions'"
types_de_champ = TypeDeChamp.joins(:parent).where('types_de_champ.revision_id != parents_types_de_champ.revision_id')
progress = ProgressReport.new(types_de_champ.count)
types_de_champ.find_each do |type_de_champ|
type_de_champ.update_column(:revision_id, type_de_champ.parent.revision_id)
progress.inc
end
progress.finish
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord
.create version: AfterParty::TaskRecorder.new(__FILE__).timestamp
end
end

View file

@ -1,25 +0,0 @@
describe '20200708101123_add_default_skip_validation_to_piece_justificative.rake' do
let(:rake_task) { Rake::Task['after_party:add_default_skip_validation_to_piece_justificative'] }
let!(:pj_type_de_champ) { create(:type_de_champ_piece_justificative) }
let!(:text_type_de_champ) { create(:type_de_champ_text) }
before do
rake_task.invoke
text_type_de_champ.reload
pj_type_de_champ.reload
end
after { rake_task.reenable }
context 'on a piece_justificative type de champ' do
it 'sets the skip_pj_validation option' do
expect(pj_type_de_champ.skip_pj_validation).to be_truthy
end
end
context 'on a non piece_justificative type de champ' do
it 'does not set the skip_pj_validation option' do
expect(text_type_de_champ.skip_pj_validation).to be_blank
end
end
end

View file

@ -1,60 +0,0 @@
describe '20201001161931_migrate_filters_to_use_stable_id' do
let(:rake_task) { Rake::Task['after_party:migrate_filters_to_use_stable_id'] }
let(:procedure) { create(:procedure, :with_instructeur, :with_type_de_champ) }
let(:type_de_champ) { procedure.types_de_champ.first }
let(:sort) do
{
"table" => "type_de_champ",
"column" => type_de_champ.id.to_s,
"order" => "asc"
}
end
let(:filters) do
{
'tous' => [
{
"label" => "test",
"table" => "type_de_champ",
"column" => type_de_champ.id.to_s,
"value" => "test"
}
],
'suivis' => [],
'traites' => [],
'a-suivre' => [],
'archives' => []
}
end
let(:displayed_fields) do
[
{
"label" => "test",
"table" => "type_de_champ",
"column" => type_de_champ.id.to_s
}
]
end
let!(:procedure_presentation) do
type_de_champ.update_column(:stable_id, 13)
procedure_presentation = create(:procedure_presentation, procedure: procedure, assign_to: procedure.groupe_instructeurs.first.assign_tos.first)
procedure_presentation.update_columns(sort: sort, filters: filters, displayed_fields: displayed_fields)
procedure_presentation
end
before do
rake_task.invoke
procedure_presentation.reload
end
after { rake_task.reenable }
context "should migrate procedure_presentation" do
it "columns are updated" do
expect(procedure_presentation.sort['column']).to eq(type_de_champ.stable_id.to_s)
expect(procedure_presentation.filters['tous'][0]['column']).to eq(type_de_champ.stable_id.to_s)
expect(procedure_presentation.displayed_fields[0]['column']).to eq(type_de_champ.stable_id.to_s)
expect(procedure_presentation.filters['migrated']).to eq(true)
end
end
end