From 78dc582588e4a6b0873a43c01dd2d116d14921b1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 25 Oct 2018 17:40:23 +0200 Subject: [PATCH 1/5] Remove ProcedurePath --- app/models/procedure.rb | 1 - app/models/procedure_path.rb | 36 -------------- .../procedure_path_format_validator.rb | 15 ------ config/locales/models/procedure/fr.yml | 7 +++ config/locales/models/procedure_path/fr.yml | 12 ----- lib/tasks/support.rake | 12 ----- spec/decorators/procedure_decorator_spec.rb | 1 - spec/factories/procedure.rb | 7 +-- spec/factories/procedure_path.rb | 5 -- spec/features/new_user/brouillon_spec.rb | 2 +- .../features/new_user/linked_dropdown_spec.rb | 2 +- spec/models/procedure_path_spec.rb | 49 ------------------- spec/models/procedure_spec.rb | 8 ++- 13 files changed, 13 insertions(+), 144 deletions(-) delete mode 100644 app/models/procedure_path.rb delete mode 100644 app/validators/procedure_path_format_validator.rb delete mode 100644 config/locales/models/procedure_path/fr.yml delete mode 100644 spec/factories/procedure_path.rb delete mode 100644 spec/models/procedure_path_spec.rb diff --git a/app/models/procedure.rb b/app/models/procedure.rb index c65f49366..2dc769bc7 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -9,7 +9,6 @@ class Procedure < ApplicationRecord has_one :module_api_carto, dependent: :destroy has_one :attestation_template, dependent: :destroy - has_one :procedure_path, dependent: :destroy belongs_to :administrateur belongs_to :parent_procedure, class_name: 'Procedure' diff --git a/app/models/procedure_path.rb b/app/models/procedure_path.rb deleted file mode 100644 index 8606a9ff4..000000000 --- a/app/models/procedure_path.rb +++ /dev/null @@ -1,36 +0,0 @@ -class ProcedurePath < ApplicationRecord - validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: true, presence: true, allow_blank: false, allow_nil: false - validates :administrateur_id, presence: true, allow_blank: false, allow_nil: false - validates :procedure_id, presence: true, allow_blank: false, allow_nil: false - - belongs_to :procedure - belongs_to :administrateur - - def self.valid?(procedure, path) - create_with(procedure: procedure, administrateur: procedure.administrateur) - .find_or_initialize_by(path: path).validate - end - - def self.mine?(administrateur, path) - procedure_path = find_by(path: path) - procedure_path && administrateur.owns?(procedure_path) - end - - def self.find_with_path(path) - joins(:procedure) - .where.not(procedures: { aasm_state: :archivee }) - .where("procedure_paths.path LIKE ?", "%#{path}%") - .order(:id) - end - - def hide! - destroy! - end - - def publish!(new_procedure) - if procedure&.publiee? && procedure != new_procedure - procedure.archive! - end - update!(procedure: new_procedure) - end -end diff --git a/app/validators/procedure_path_format_validator.rb b/app/validators/procedure_path_format_validator.rb deleted file mode 100644 index 7c5e1f5b9..000000000 --- a/app/validators/procedure_path_format_validator.rb +++ /dev/null @@ -1,15 +0,0 @@ -class ProcedurePathFormatValidator < ActiveModel::Validator - def path_regex - /^[a-z0-9_]{3,30}$/ - end - - def validate(record) - if record.path.blank? - return false - end - - if !path_regex.match(record.path) - record.errors[:path] << "Path invalide" - end - end -end diff --git a/config/locales/models/procedure/fr.yml b/config/locales/models/procedure/fr.yml index 9f6898e1d..662acf604 100644 --- a/config/locales/models/procedure/fr.yml +++ b/config/locales/models/procedure/fr.yml @@ -2,6 +2,13 @@ fr: activerecord: attributes: procedure: + path: Lien organisation: Organisme duree_conservation_dossiers_dans_ds: Durée de conservation des dossiers sur demarches-simplifiees.fr duree_conservation_dossiers_hors_ds: Durée de conservation des dossiers hors demarches-simplifiees.fr + errors: + models: + procedure: + attributes: + path: + format: Ce lien n'est pas valide. Il doit comporter au moins 3 caractères, au plus 50 caractères et seuls les caractères a-z, 0-9, '_' et '-' sont autorisés. diff --git a/config/locales/models/procedure_path/fr.yml b/config/locales/models/procedure_path/fr.yml deleted file mode 100644 index bd1e29b41..000000000 --- a/config/locales/models/procedure_path/fr.yml +++ /dev/null @@ -1,12 +0,0 @@ -fr: - activerecord: - attributes: - procedure_path: - path: Lien - errors: - models: - procedure_path: - attributes: - path: - format: Ce lien n'est pas valide. Il doit comporter au moins 3 caractères, au plus 50 caractères et seuls les caractères a-z, 0-9, '_' et '-' sont autorisés. - taken: est déjà utilisé par une procédure. diff --git a/lib/tasks/support.rake b/lib/tasks/support.rake index bbb166bfa..3c00b017d 100644 --- a/lib/tasks/support.rake +++ b/lib/tasks/support.rake @@ -27,11 +27,6 @@ namespace :support do rake_puts("Changing owner of procedure ##{procedure_id} from ##{procedure.administrateur_id} to ##{new_owner.id}") procedure.update(administrateur: new_owner) - - ProcedurePath.where(procedure_id: procedure_id).each do |pp| - rake_puts("Changing owner of procedure_path #{pp.path} from ##{pp.administrateur_id} to ##{new_owner.id}") - pp.update(administrateur: new_owner) - end end desc <<~EOD @@ -74,13 +69,6 @@ namespace :support do end procedures.update_all(administrateur_id: new_owner.id) - - procedures.pluck(:id).each do |procedure_id| - ProcedurePath.where(procedure_id: procedure_id).each do |pp| - rake_puts("Changing owner of procedure_path #{pp.path} from ##{pp.administrateur_id} to ##{new_owner.id}") - pp.update(administrateur: new_owner) - end - end end desc <<~EOD diff --git a/spec/decorators/procedure_decorator_spec.rb b/spec/decorators/procedure_decorator_spec.rb index 742db1047..2c7972076 100644 --- a/spec/decorators/procedure_decorator_spec.rb +++ b/spec/decorators/procedure_decorator_spec.rb @@ -3,7 +3,6 @@ require 'spec_helper' describe ProcedureDecorator do let(:published_at) { Time.zone.local(2017, 12, 24, 14, 12) } let(:procedure) { create(:procedure, published_at: published_at, created_at: Time.zone.local(2015, 12, 24, 14, 10)) } - let!(:procedure_path) { create(:procedure_path, administrateur: create(:administrateur), procedure: procedure) } subject { procedure.decorate } diff --git a/spec/factories/procedure.rb b/spec/factories/procedure.rb index 74a83cf26..c22488dcc 100644 --- a/spec/factories/procedure.rb +++ b/spec/factories/procedure.rb @@ -37,12 +37,7 @@ FactoryBot.define do end trait :with_path do - after(:create) do |procedure| - create(:procedure_path, - procedure: procedure, - administrateur: procedure.administrateur, - path: generate(:published_path)) - end + path { generate(:published_path) } end trait :with_service do diff --git a/spec/factories/procedure_path.rb b/spec/factories/procedure_path.rb deleted file mode 100644 index bd05581d1..000000000 --- a/spec/factories/procedure_path.rb +++ /dev/null @@ -1,5 +0,0 @@ -FactoryBot.define do - factory :procedure_path do - path { 'fake_path' } - end -end diff --git a/spec/features/new_user/brouillon_spec.rb b/spec/features/new_user/brouillon_spec.rb index 51c7bedbb..244cf9b8d 100644 --- a/spec/features/new_user/brouillon_spec.rb +++ b/spec/features/new_user/brouillon_spec.rb @@ -129,7 +129,7 @@ feature 'The user' do private def log_in(email, password, procedure) - visit "/commencer/#{procedure.procedure_path.path}" + visit "/commencer/#{procedure.path}" expect(page).to have_current_path(new_user_session_path) fill_in 'user_email', with: email diff --git a/spec/features/new_user/linked_dropdown_spec.rb b/spec/features/new_user/linked_dropdown_spec.rb index 70b9870e1..a175f407a 100644 --- a/spec/features/new_user/linked_dropdown_spec.rb +++ b/spec/features/new_user/linked_dropdown_spec.rb @@ -47,7 +47,7 @@ feature 'linked dropdown lists' do private def log_in(email, password, procedure) - visit "/commencer/#{procedure.procedure_path.path}" + visit "/commencer/#{procedure.path}" expect(page).to have_current_path(new_user_session_path) fill_in 'user_email', with: email diff --git a/spec/models/procedure_path_spec.rb b/spec/models/procedure_path_spec.rb deleted file mode 100644 index 29d349f31..000000000 --- a/spec/models/procedure_path_spec.rb +++ /dev/null @@ -1,49 +0,0 @@ -require 'spec_helper' - -describe ProcedurePath do - describe 'assocations' do - it { is_expected.to belong_to(:administrateur) } - it { is_expected.to belong_to(:procedure) } - end - - describe 'attributes' do - it { is_expected.to have_db_column(:path) } - end - - describe 'validation' do - describe 'path' do - let(:admin) { create(:administrateur) } - let(:procedure) { create(:procedure) } - let(:procedure_path) { create(:procedure_path, administrateur: admin, procedure: procedure, path: path) } - - context 'when path is nil' do - let(:path) { nil } - it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid } - end - context 'when path is empty' do - let(:path) { '' } - it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid } - end - context 'when path contains spaces' do - let(:path) { 'Demande de subvention' } - it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid } - end - context 'when path contains alphanumerics and underscores' do - let(:path) { 'ma_super_procedure_1' } - it { expect{ procedure_path }.not_to raise_error } - end - context 'when path contains dashes' do - let(:path) { 'ma-super-procedure' } - it { expect{ procedure_path }.not_to raise_error } - end - context 'when path is too long' do - let(:path) { 'ma-super-procedure-12345678901234567890123456789012345678901234567890' } - it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid } - end - context 'when path is too short' do - let(:path) { 'pr' } - it { expect{ procedure_path }.to raise_error ActiveRecord::RecordInvalid } - end - end - end -end diff --git a/spec/models/procedure_spec.rb b/spec/models/procedure_spec.rb index bdd0f5f45..1f039cea0 100644 --- a/spec/models/procedure_spec.rb +++ b/spec/models/procedure_spec.rb @@ -439,9 +439,8 @@ describe Procedure do it { expect(procedure.archived_at).to eq(nil) } it { expect(procedure.published_at).to eq(now) } - it { expect(ProcedurePath.find_by(path: "example-path")).to be } - it { expect(ProcedurePath.find_by(path: "example-path").procedure).to eq(procedure) } - it { expect(ProcedurePath.find_by(path: "example-path").administrateur).to eq(procedure.administrateur) } + it { expect(Procedure.find_by(path: "example-path")).to eq(procedure) } + it { expect(Procedure.find_by(path: "example-path").administrateur).to eq(procedure.administrateur) } end describe "#brouillon?" do @@ -486,7 +485,6 @@ describe Procedure do describe 'archive' do let(:procedure) { create(:procedure, :published) } - let(:procedure_path) { ProcedurePath.find(procedure.procedure_path.id) } let(:now) { Time.zone.now.beginning_of_minute } before do Timecop.freeze(now) @@ -634,7 +632,7 @@ describe Procedure do context "with a path" do let(:procedure) { create(:procedure, :published) } - it { is_expected.to eq("dossiers_#{procedure.procedure_path.path}_2018-01-02_23-11") } + it { is_expected.to eq("dossiers_#{procedure.path}_2018-01-02_23-11") } end context "without a path" do From 641831864ba1087887b017a533d81fa80a7e0091 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 25 Oct 2018 17:40:58 +0200 Subject: [PATCH 2/5] Refactor commencer actions --- app/controllers/users/dossiers_controller.rb | 16 ++++------------ app/views/commencer/archived.html.haml | 15 --------------- 2 files changed, 4 insertions(+), 27 deletions(-) delete mode 100644 app/views/commencer/archived.html.haml diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 0a292509b..9bf7ff033 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -12,10 +12,9 @@ class Users::DossiersController < UsersController end def commencer_test - procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) - procedure = procedure_path&.procedure + procedure = Procedure.brouillons.find_by(path: params[:procedure_path]) - if procedure&.brouillon? && procedure&.path.present? + if procedure.present? redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true) else flash.alert = "La démarche est inconnue." @@ -24,17 +23,10 @@ class Users::DossiersController < UsersController end def commencer - procedure_path = ProcedurePath.find_by(path: params[:procedure_path]) - procedure = procedure_path&.procedure + procedure = Procedure.publiees.find_by(path: params[:procedure_path]) if procedure.present? - if procedure.archivee? - @dossier = Dossier.new(procedure: procedure) - - render 'commencer/archived' - else - redirect_to new_users_dossier_path(procedure_id: procedure.id) - end + redirect_to new_users_dossier_path(procedure_id: procedure.id) else flash.alert = "La démarche est inconnue, ou la création de nouveaux dossiers pour cette démarche est terminée." redirect_to root_path diff --git a/app/views/commencer/archived.html.haml b/app/views/commencer/archived.html.haml deleted file mode 100644 index 84c72ab34..000000000 --- a/app/views/commencer/archived.html.haml +++ /dev/null @@ -1,15 +0,0 @@ -%br -%div{ style: 'text-align: center; max-width: 500px; margin-left: auto; margin-right: auto; padding: 20px;' } - = render partial: 'users/sessions/resume_procedure' - -.center{ style: 'margin-top: -20px;' } - %h3 - La campagne de création de nouveau dossier - %br - pour cette démarche en ligne est maintenant terminée. - - %br - %p - Si vous avez déjà déposé un ou plusieurs dossiers : - %a.btn.btn-lg.btn-info{ href: new_user_session_path } - Accéder à mon espace en ligne. From b42095363eeac9ace0f054707b8b3e93f4430dcc Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 25 Oct 2018 17:41:48 +0200 Subject: [PATCH 3/5] Refactor procedure model --- app/models/procedure.rb | 77 +++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 41 deletions(-) diff --git a/app/models/procedure.rb b/app/models/procedure.rb index 2dc769bc7..545947c46 100644 --- a/app/models/procedure.rb +++ b/app/models/procedure.rb @@ -45,12 +45,12 @@ class Procedure < ApplicationRecord scope :by_libelle, -> { order(libelle: :asc) } scope :created_during, -> (range) { where(created_at: range) } scope :cloned_from_library, -> { where(cloned_from_library: true) } - scope :avec_lien, -> { joins(:procedure_path) } + scope :avec_lien, -> { where.not(path: nil) } validates :libelle, presence: true, allow_blank: false, allow_nil: false validates :description, presence: true, allow_blank: false, allow_nil: false validate :check_juridique - validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: true, presence: true, allow_blank: false, allow_nil: true + validates :path, format: { with: /\A[a-z0-9_\-]{3,50}\z/ }, uniqueness: { scope: :aasm_state, case_sensitive: false }, presence: true, allow_blank: false, allow_nil: true # FIXME: remove duree_conservation_required flag once all procedures are converted to the new style validates :duree_conservation_dossiers_dans_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 1, less_than_or_equal_to: MAX_DUREE_CONSERVATION }, if: :durees_conservation_required validates :duree_conservation_dossiers_hors_ds, allow_nil: false, numericality: { only_integer: true, greater_than_or_equal_to: 0 }, if: :durees_conservation_required @@ -100,19 +100,6 @@ class Procedure < ApplicationRecord end end - def publish_with_path!(path) - procedure_path = ProcedurePath - .where(administrateur: administrateur) - .find_by(path: path) - - if procedure_path.present? - procedure_path.publish!(self) - else - create_procedure_path!(administrateur: administrateur, path: path) - end - update!(path: path) - end - def reset! if locked? raise "Can not reset a locked procedure." @@ -125,14 +112,6 @@ class Procedure < ApplicationRecord publiee_ou_archivee? end - def path_available?(path) - !ProcedurePath.where.not(procedure: self).exists?(path: path) - end - - def path_is_mine?(path) - ProcedurePath.where.not(procedure: self).mine?(administrateur, path) - end - # This method is needed for transition. Eventually this will be the same as brouillon?. def brouillon_avec_lien? Flipflop.publish_draft? && brouillon? && path.present? @@ -156,10 +135,6 @@ class Procedure < ApplicationRecord Dossier.new(procedure: self, champs: champs, champs_private: champs_private) end - def path - read_attribute(:path) || procedure_path&.path - end - def default_path libelle&.parameterize&.first(50) end @@ -331,21 +306,48 @@ class Procedure < ApplicationRecord mean_time(:en_instruction_at, :processed_at) end + def path_available?(path) + !Procedure.where.not(id: id).exists?(path: path) + end + + def path_mine?(path) + Procedure.path_mine?(administrateur, path) + end + + def self.path_mine?(administrateur, path) + where(administrateur: administrateur).exists?(path: path) + end + + def self.find_with_path(path) + where.not(aasm_state: :archivee).where("path LIKE ?", "%#{path}%") + end + private - def can_publish?(path) - procedure_path = ProcedurePath.find_by(path: path) - if procedure_path.present? - administrateur.owns?(procedure_path) - else - true + def claim_path_ownership!(path) + procedure = Procedure.where(administrateur: administrateur).find_by(path: path) + + if procedure&.publiee? && procedure != self + procedure.archive! end + + update!(path: path) + end + + def can_publish?(path) + path_available?(path) || path_mine?(path) end def after_publish(path) update!(published_at: Time.zone.now) - publish_with_path!(path) + claim_path_ownership!(path) + end + + def after_reopen(path) + update!(published_at: Time.zone.now, archived_at: nil) + + claim_path_ownership!(path) end def after_archive @@ -355,16 +357,9 @@ class Procedure < ApplicationRecord def after_hide now = Time.zone.now update!(hidden_at: now, path: nil) - procedure_path&.hide! dossiers.update_all(hidden_at: now) end - def after_reopen(path) - update!(published_at: Time.zone.now, archived_at: nil) - - publish_with_path!(path) - end - def after_draft update!(published_at: nil) end From f1fd1b38ec687564d206ae7fcb76bc47c21a885c Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 25 Oct 2018 17:42:09 +0200 Subject: [PATCH 4/5] Refactor procedures_controller --- .../admin/procedures_controller.rb | 51 ++++++++----------- .../admin/procedures/_unavailable.html.haml | 2 +- .../admin/procedures_controller_spec.rb | 16 ------ spec/features/admin/procedure_cloning_spec.rb | 2 - .../features/admin/procedure_creation_spec.rb | 2 - 5 files changed, 23 insertions(+), 50 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 6a37e24f4..94b120fff 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -41,7 +41,7 @@ class Admin::ProceduresController < AdminController def edit @path = @procedure.path || @procedure.default_path @available = @procedure.path_available?(@path) - @mine = @procedure.path_is_mine?(@path) + @mine = @procedure.path_mine?(@path) end def destroy @@ -71,22 +71,14 @@ class Admin::ProceduresController < AdminController @procedure.module_api_carto = ModuleAPICarto.new(create_module_api_carto_params) end - @path = params.require(:procedure).permit(:path)[:path] - @available = !ProcedurePath.exists?(path: @path) - @mine = ProcedurePath.mine?(current_administrateur, @path) + @path = @procedure.path + @available = !Procedure.exists?(path: @path) + @mine = Procedure.path_mine?(current_administrateur, @path) - if !@procedure.validate + if !@procedure.save flash.now.alert = @procedure.errors.full_messages return render 'new' - elsif Flipflop.publish_draft? && !ProcedurePath.valid?(Procedure.last, @path) - # FIXME: The code abow is a horrible hack that we need until we migrated path directly on procedure model - flash.now.alert = 'Lien de la démarche invalide.' - return render 'new' else - @procedure.save! - if Flipflop.publish_draft? - @procedure.publish_with_path!(@path) - end flash.notice = 'Démarche enregistrée.' end @@ -95,20 +87,13 @@ class Admin::ProceduresController < AdminController def update @procedure = current_administrateur.procedures.find(params[:id]) - path = params.require(:procedure).permit(:path)[:path] if !@procedure.update(procedure_params) flash.alert = @procedure.errors.full_messages elsif Flipflop.publish_draft? && @procedure.brouillon? - if ProcedurePath.valid?(@procedure, path) - @procedure.publish_with_path!(path) - reset_procedure - flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.' - else - flash.alert = 'Lien de la démarche invalide.' - end - else reset_procedure + flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.' + else flash.notice = 'Démarche modifiée.' end @@ -116,14 +101,18 @@ class Admin::ProceduresController < AdminController end def publish + path = params[:procedure_path] procedure = current_administrateur.procedures.find(params[:procedure_id]) - if !ProcedurePath.valid?(procedure, params[:procedure_path]) + procedure.path = path + if !procedure.validate flash.alert = 'Lien de la démarche invalide' return redirect_to admin_procedures_path + else + procedure.path = nil end - if procedure.publish_or_reopen!(params[:procedure_path]) + if procedure.publish_or_reopen!(path) flash.notice = "Démarche publiée" redirect_to admin_procedures_path else @@ -216,9 +205,10 @@ class Admin::ProceduresController < AdminController end def path_list - json_path_list = ProcedurePath + json_path_list = Procedure .find_with_path(params[:request]) - .pluck('procedure_paths.path', :administrateur_id) + .order(:id) + .pluck(:path, :administrateur_id) .map do |path, administrateur_id| { label: path, @@ -236,10 +226,10 @@ class Admin::ProceduresController < AdminController if procedure_id.present? procedure = current_administrateur.procedures.find(procedure_id) @available = procedure.path_available?(path) - @mine = procedure.path_is_mine?(path) + @mine = procedure.path_mine?(path) else - @available = !ProcedurePath.exists?(path: path) - @mine = ProcedurePath.mine?(current_administrateur, path) + @available = !Procedure.exists?(path: path) + @mine = Procedure.path_mine?(current_administrateur, path) end end @@ -276,6 +266,9 @@ class Admin::ProceduresController < AdminController if @procedure&.locked? params.require(:procedure).permit(*editable_params) else + if Flipflop.publish_draft? + editable_params << :path + end params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :individual_with_siret, :ask_birthday, module_api_carto_attributes: [:id, :use_api_carto, :quartiers_prioritaires, :cadastre]).merge(administrateur_id: current_administrateur.id) end end diff --git a/app/views/admin/procedures/_unavailable.html.haml b/app/views/admin/procedures/_unavailable.html.haml index a47dfee6d..bb11886f2 100644 --- a/app/views/admin/procedures/_unavailable.html.haml +++ b/app/views/admin/procedures/_unavailable.html.haml @@ -1,7 +1,7 @@ - if mine Ce lien est déjà utilisé par une de vos démarche. %br - Si vous voulez l’utiliser, l’ancienne démarche sera archivée (plus accessible du public). + Si vous voulez l’utiliser, l’ancienne démarche sera archivée lors de la publication de la démarche (plus accessible du public). - else Ce lien est déjà utilisé par une démarche. %br diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index a5c8cdbfe..bf4cfcb1d 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -391,22 +391,6 @@ describe Admin::ProceduresController, type: :controller do end end - context 'procedure path exists and has archived procedure' do - let(:procedure_path) { procedure2.path } - let(:procedure2) { create(:procedure, :archived, administrateur: admin) } - - it 'publish the given procedure' do - expect(procedure.publiee?).to be_truthy - expect(procedure.path).to eq(procedure_path) - expect(response.status).to eq 302 - expect(flash[:notice]).to have_content 'Démarche publiée' - end - - it 'archive previous procedure' do - expect(procedure2.archivee?).to be_truthy - end - end - context 'procedure path exists and is not owned by current administrator' do let(:procedure_path) { procedure3.path } diff --git a/spec/features/admin/procedure_cloning_spec.rb b/spec/features/admin/procedure_cloning_spec.rb index 1315a0b35..5f1528d43 100644 --- a/spec/features/admin/procedure_cloning_spec.rb +++ b/spec/features/admin/procedure_cloning_spec.rb @@ -7,8 +7,6 @@ feature 'As an administrateur I wanna clone a procedure', js: true do let(:administrateur) { create(:administrateur) } before do - # FIXME: needed to make procedure_path validation work - create(:procedure) Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true) login_as administrateur, scope: :administrateur visit root_path diff --git a/spec/features/admin/procedure_creation_spec.rb b/spec/features/admin/procedure_creation_spec.rb index 9bc37d4fc..9bf6fa01a 100644 --- a/spec/features/admin/procedure_creation_spec.rb +++ b/spec/features/admin/procedure_creation_spec.rb @@ -7,8 +7,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do let(:administrateur) { create(:administrateur) } before do - # FIXME: needed to make procedure_path validation work - create(:procedure) Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true) login_as administrateur, scope: :administrateur visit root_path From 725e88a89acc7e3da86aae8eb2e40910c864628a Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 30 Oct 2018 12:00:58 +0100 Subject: [PATCH 5/5] Rename :procedure_path -> :path --- app/controllers/admin/procedures_controller.rb | 2 +- app/controllers/users/dossiers_controller.rb | 4 ++-- app/helpers/procedure_helper.rb | 4 ++-- app/serializers/procedure_serializer.rb | 4 ++-- .../admin/procedures/_informations.html.haml | 2 +- .../admin/procedures/_modal_publish.html.haml | 6 +++--- .../procedure_link_field/_show.html.haml | 2 +- app/views/new_user/demarches/index.html.haml | 4 ++-- config/routes.rb | 4 ++-- .../admin/procedures_controller_spec.rb | 18 +++++++++--------- .../users/dossiers_controller_spec.rb | 4 ++-- .../features/new_user/dossier_creation_spec.rb | 6 +++--- .../admin/procedures/show.html.haml_spec.rb | 2 +- 13 files changed, 31 insertions(+), 31 deletions(-) diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index 94b120fff..5bcc245da 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -101,7 +101,7 @@ class Admin::ProceduresController < AdminController end def publish - path = params[:procedure_path] + path = params[:path] procedure = current_administrateur.procedures.find(params[:procedure_id]) procedure.path = path diff --git a/app/controllers/users/dossiers_controller.rb b/app/controllers/users/dossiers_controller.rb index 9bf7ff033..914c41146 100644 --- a/app/controllers/users/dossiers_controller.rb +++ b/app/controllers/users/dossiers_controller.rb @@ -12,7 +12,7 @@ class Users::DossiersController < UsersController end def commencer_test - procedure = Procedure.brouillons.find_by(path: params[:procedure_path]) + procedure = Procedure.brouillons.find_by(path: params[:path]) if procedure.present? redirect_to new_users_dossier_path(procedure_id: procedure.id, brouillon: true) @@ -23,7 +23,7 @@ class Users::DossiersController < UsersController end def commencer - procedure = Procedure.publiees.find_by(path: params[:procedure_path]) + procedure = Procedure.publiees.find_by(path: params[:path]) if procedure.present? redirect_to new_users_dossier_path(procedure_id: procedure.id) diff --git a/app/helpers/procedure_helper.rb b/app/helpers/procedure_helper.rb index 2f28feed9..4305b05e5 100644 --- a/app/helpers/procedure_helper.rb +++ b/app/helpers/procedure_helper.rb @@ -2,9 +2,9 @@ module ProcedureHelper def procedure_lien(procedure) if procedure.path.present? if procedure.brouillon_avec_lien? - commencer_test_url(procedure_path: procedure.path) + commencer_test_url(path: procedure.path) else - commencer_url(procedure_path: procedure.path) + commencer_url(path: procedure.path) end end end diff --git a/app/serializers/procedure_serializer.rb b/app/serializers/procedure_serializer.rb index 6982cfd84..bd5605a6c 100644 --- a/app/serializers/procedure_serializer.rb +++ b/app/serializers/procedure_serializer.rb @@ -21,9 +21,9 @@ class ProcedureSerializer < ActiveModel::Serializer def link if object.path.present? if object.brouillon_avec_lien? - commencer_test_url(procedure_path: object.path) + commencer_test_url(path: object.path) else - commencer_url(procedure_path: object.path) + commencer_url(path: object.path) end end end diff --git a/app/views/admin/procedures/_informations.html.haml b/app/views/admin/procedures/_informations.html.haml index 6650fa034..77b53632d 100644 --- a/app/views/admin/procedures/_informations.html.haml +++ b/app/views/admin/procedures/_informations.html.haml @@ -16,7 +16,7 @@ %h4 Lien public* .procedure-lien %span.prefix - = commencer_test_url(procedure_path: '') + = commencer_test_url(path: '') = f.text_field :path, value: @path, class: 'form-control', data: { remote: true, debounce: true, url: admin_procedures_available_path, params: { id: @procedure.id }.to_query(:procedure) } %p.unavailable-path-message.text-warning - if !@available diff --git a/app/views/admin/procedures/_modal_publish.html.haml b/app/views/admin/procedures/_modal_publish.html.haml index 2109792ae..0508ff880 100644 --- a/app/views/admin/procedures/_modal_publish.html.haml +++ b/app/views/admin/procedures/_modal_publish.html.haml @@ -20,8 +20,8 @@ %br %h4 Lien de la démarche %p.center - = commencer_url(procedure_path: '') - = text_field_tag('procedure_path', @procedure.path || @procedure.default_path, + = commencer_url(path: '') + = text_field_tag(:path, @procedure.path || @procedure.default_path, id: 'procedure_path', placeholder: 'Chemin vers la démarche', data: { autocomplete: 'path' }, @@ -41,7 +41,7 @@ %br Vous ne pouvez pas l’utiliser car il appartient à un autre administrateur. #path_is_invalid.text-danger.center.message - = t('activerecord.errors.models.procedure_path.attributes.path.format') + = t('activerecord.errors.models.procedure.attributes.path.format') .modal-footer = submit_tag procedure_modal_text(@procedure, :submit), class: %w(btn btn btn-success), disabled: :disabled, id: 'publish' = button_tag "Annuler", class: %w(btn btn btn-default), data: { dismiss: :modal }, id: 'cancel' diff --git a/app/views/fields/procedure_link_field/_show.html.haml b/app/views/fields/procedure_link_field/_show.html.haml index 250a02c4f..7d0ee3413 100644 --- a/app/views/fields/procedure_link_field/_show.html.haml +++ b/app/views/fields/procedure_link_field/_show.html.haml @@ -1,4 +1,4 @@ - if field.data.present? - = link_to "/commencer/#{field.data}", commencer_url(procedure_path: field.data), target: '_blank' + = link_to "/commencer/#{field.data}", commencer_url(path: field.data), target: '_blank' - else Plus en ligne diff --git a/app/views/new_user/demarches/index.html.haml b/app/views/new_user/demarches/index.html.haml index 334471b7b..0767a4b04 100644 --- a/app/views/new_user/demarches/index.html.haml +++ b/app/views/new_user/demarches/index.html.haml @@ -12,7 +12,7 @@ %ul.demarche-links - @previous_demarches_still_active.each do |demarche| %li - = link_to(commencer_url(procedure_path: demarche.path), class: "demarche-link") do + = link_to(commencer_url(path: demarche.path), class: "demarche-link") do = demarche.libelle %br .service-name @@ -23,7 +23,7 @@ %ul.demarche-links - @popular_demarches.each do |demarche| %li - = link_to(commencer_url(procedure_path: demarche.path), class: "demarche-link") do + = link_to(commencer_url(path: demarche.path), class: "demarche-link") do = demarche.libelle %br .service-name diff --git a/config/routes.rb b/config/routes.rb index 8479addd8..0b520e22f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -129,8 +129,8 @@ Rails.application.routes.draw do end namespace :commencer do - get '/test/:procedure_path' => '/users/dossiers#commencer_test', as: :test - get '/:procedure_path' => '/users/dossiers#commencer' + get '/test/:path' => '/users/dossiers#commencer_test', as: :test + get '/:path' => '/users/dossiers#commencer' end get "patron" => "root#patron" diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index bf4cfcb1d..1f01f11b4 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -359,28 +359,28 @@ describe Admin::ProceduresController, type: :controller do context 'when admin is the owner of the procedure' do before do - put :publish, params: { procedure_id: procedure.id, procedure_path: procedure_path } + put :publish, params: { procedure_id: procedure.id, path: path } procedure.reload procedure2.reload end context 'procedure path does not exist' do - let(:procedure_path) { 'new_path' } + let(:path) { 'new_path' } it 'publish the given procedure' do expect(procedure.publiee?).to be_truthy - expect(procedure.path).to eq(procedure_path) + expect(procedure.path).to eq(path) expect(response.status).to eq 302 expect(flash[:notice]).to have_content 'Démarche publiée' end end context 'procedure path exists and is owned by current administrator' do - let(:procedure_path) { procedure2.path } + let(:path) { procedure2.path } it 'publish the given procedure' do expect(procedure.publiee?).to be_truthy - expect(procedure.path).to eq(procedure_path) + expect(procedure.path).to eq(path) expect(response.status).to eq 302 expect(flash[:notice]).to have_content 'Démarche publiée' end @@ -392,7 +392,7 @@ describe Admin::ProceduresController, type: :controller do end context 'procedure path exists and is not owned by current administrator' do - let(:procedure_path) { procedure3.path } + let(:path) { procedure3.path } it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey @@ -408,7 +408,7 @@ describe Admin::ProceduresController, type: :controller do end context 'procedure path is invalid' do - let(:procedure_path) { 'Invalid Procedure Path' } + let(:path) { 'Invalid Procedure Path' } it 'does not publish the given procedure' do expect(procedure.publiee?).to be_falsey @@ -426,7 +426,7 @@ describe Admin::ProceduresController, type: :controller do sign_out admin sign_in admin_2 - put :publish, params: { procedure_id: procedure.id, procedure_path: 'fake_path' } + put :publish, params: { procedure_id: procedure.id, path: 'fake_path' } procedure.reload end @@ -454,7 +454,7 @@ describe Admin::ProceduresController, type: :controller do context 'when owner want to re-enable procedure' do before do - put :publish, params: { procedure_id: procedure.id, procedure_path: 'fake_path' } + put :publish, params: { procedure_id: procedure.id, path: 'fake_path' } procedure.reload end diff --git a/spec/controllers/users/dossiers_controller_spec.rb b/spec/controllers/users/dossiers_controller_spec.rb index 5bfa1dd45..f323d0f3f 100644 --- a/spec/controllers/users/dossiers_controller_spec.rb +++ b/spec/controllers/users/dossiers_controller_spec.rb @@ -65,7 +65,7 @@ describe Users::DossiersController, type: :controller do end describe 'GET #commencer' do - subject { get :commencer, params: { procedure_path: path } } + subject { get :commencer, params: { path: path } } let(:path) { procedure.path } it { expect(subject.status).to eq 302 } @@ -83,7 +83,7 @@ describe Users::DossiersController, type: :controller do Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true) end - subject { get :commencer_test, params: { procedure_path: path } } + subject { get :commencer_test, params: { path: path } } let(:procedure) { create(:procedure, :with_path) } let(:path) { procedure.path } diff --git a/spec/features/new_user/dossier_creation_spec.rb b/spec/features/new_user/dossier_creation_spec.rb index 6c468745a..84fc98621 100644 --- a/spec/features/new_user/dossier_creation_spec.rb +++ b/spec/features/new_user/dossier_creation_spec.rb @@ -16,7 +16,7 @@ feature 'Creating a new dossier:' do let(:expected_birthday) { nil } before do - visit commencer_path(procedure_path: procedure.path) + visit commencer_path(path: procedure.path) fill_in 'individual_nom', with: 'Nom' fill_in 'individual_prenom', with: 'Prenom' end @@ -76,7 +76,7 @@ feature 'Creating a new dossier:' do end scenario 'the user can enter the SIRET of its etablissement and create a new draft', vcr: { cassette_name: 'api_adresse_search_paris_3' }, js: true do - visit commencer_path(procedure_path: procedure.path) + visit commencer_path(path: procedure.path) expect(page).to have_current_path(siret_dossier_path(dossier)) fill_in 'Numéro SIRET', with: siret @@ -93,7 +93,7 @@ feature 'Creating a new dossier:' do end scenario 'the user is notified when its SIRET is invalid' do - visit commencer_path(procedure_path: procedure.path) + visit commencer_path(path: procedure.path) expect(page).to have_current_path(siret_dossier_path(dossier)) fill_in 'Numéro SIRET', with: '0000' diff --git a/spec/views/admin/procedures/show.html.haml_spec.rb b/spec/views/admin/procedures/show.html.haml_spec.rb index c44f748cb..1418c389b 100644 --- a/spec/views/admin/procedures/show.html.haml_spec.rb +++ b/spec/views/admin/procedures/show.html.haml_spec.rb @@ -53,7 +53,7 @@ describe 'admin/procedures/show.html.haml', type: :view do end describe 'procedure link is present' do - it { expect(rendered).to have_content(commencer_url(procedure_path: procedure.path)) } + it { expect(rendered).to have_content(commencer_url(path: procedure.path)) } end end