From 92e60321157283b2da293c847505b967776f6843 Mon Sep 17 00:00:00 2001 From: Nicolas Bouilleaud Date: Fri, 5 Jul 2019 10:37:29 +0200 Subject: [PATCH] Remove path availability dead code when creating/editing a procedure MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There’s no “path” field anymore in the Procedure form, it can only be set when publishing. --- .../admin/procedures_controller.rb | 21 ------- .../admin/procedures/_unavailable.html.haml | 11 ---- .../procedures/check_availability.js.erb | 11 ---- config/routes.rb | 1 - .../admin/procedures_controller_spec.rb | 57 ------------------- 5 files changed, 101 deletions(-) delete mode 100644 app/views/admin/procedures/_unavailable.html.haml delete mode 100644 app/views/admin/procedures/check_availability.js.erb diff --git a/app/controllers/admin/procedures_controller.rb b/app/controllers/admin/procedures_controller.rb index c2c061e75..1fc919b07 100644 --- a/app/controllers/admin/procedures_controller.rb +++ b/app/controllers/admin/procedures_controller.rb @@ -43,8 +43,6 @@ class Admin::ProceduresController < AdminController end def edit - @path = @procedure.path || @procedure.default_path - @availability = @procedure.path_availability(current_administrateur, @path) end def destroy @@ -63,13 +61,10 @@ class Admin::ProceduresController < AdminController def new @procedure ||= Procedure.new(for_individual: true) - @availability = Procedure::PATH_AVAILABLE end def create @procedure = Procedure.new(procedure_params.merge(administrateurs: [current_administrateur])) - @path = @procedure.path - @availability = Procedure.path_availability(current_administrateur, @procedure.path) if !@procedure.save flash.now.alert = @procedure.errors.full_messages @@ -87,10 +82,6 @@ class Admin::ProceduresController < AdminController if !@procedure.update(procedure_params) flash.now.alert = @procedure.errors.full_messages - @path = procedure_params[:path] - if @path.present? - @availability = @procedure.path_availability(current_administrateur, @path) - end render 'edit' elsif @procedure.brouillon? reset_procedure @@ -234,18 +225,6 @@ class Admin::ProceduresController < AdminController render json: json_path_list end - def check_availability - path = params[:procedure][:path] - procedure_id = params[:procedure][:id] - - if procedure_id.present? - procedure = current_administrateur.procedures.find(procedure_id) - @availability = procedure.path_availability(current_administrateur, path) - else - @availability = Procedure.path_availability(current_administrateur, path) - end - end - def delete_logo @procedure.logo.purge_later @procedure.logo_active_storage.purge_later diff --git a/app/views/admin/procedures/_unavailable.html.haml b/app/views/admin/procedures/_unavailable.html.haml deleted file mode 100644 index d3c2ce71d..000000000 --- a/app/views/admin/procedures/_unavailable.html.haml +++ /dev/null @@ -1,11 +0,0 @@ -- case availability -- when Procedure::PATH_AVAILABLE_PUBLIEE - 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 lors de la publication de la démarche (plus accessible du public). -- when Procedure::PATH_NOT_AVAILABLE_BROUILLON - Une démarche en test existe déjà avec ce lien. -- when Procedure::PATH_NOT_AVAILABLE - Ce lien est déjà utilisé par une démarche. - %br - Vous ne pouvez pas l’utiliser car il appartient à un autre administrateur. diff --git a/app/views/admin/procedures/check_availability.js.erb b/app/views/admin/procedures/check_availability.js.erb deleted file mode 100644 index f5eed5960..000000000 --- a/app/views/admin/procedures/check_availability.js.erb +++ /dev/null @@ -1,11 +0,0 @@ -<% if @availability == Procedure::PATH_AVAILABLE %> - <%= remove_element('.unavailable-path-message', inner: true) %> -<% else %> - <%= render_to_element('.unavailable-path-message', partial: 'unavailable', locals: { availability: @availability }) %> -<% end %> - -<% if @availability.in?(Procedure::PATH_CAN_PUBLISH) %> - <%= enable_element('button[type=submit]') %> -<% else %> - <%= disable_element('button[type=submit]') %> -<% end %> diff --git a/config/routes.rb b/config/routes.rb index 0bb11a794..9214c6d5d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -160,7 +160,6 @@ Rails.application.routes.draw do get 'procedures/archived' => 'procedures#archived' get 'procedures/draft' => 'procedures#draft' get 'procedures/path_list' => 'procedures#path_list' - get 'procedures/available' => 'procedures#check_availability' resources :procedures do collection do diff --git a/spec/controllers/admin/procedures_controller_spec.rb b/spec/controllers/admin/procedures_controller_spec.rb index 7df3010d7..ede09f394 100644 --- a/spec/controllers/admin/procedures_controller_spec.rb +++ b/spec/controllers/admin/procedures_controller_spec.rb @@ -716,63 +716,6 @@ describe Admin::ProceduresController, type: :controller do end end - describe "GET #check_availability" do - render_views - let(:procedure) { create(:procedure, :with_path, administrateur: admin) } - let(:params) { - { - procedure: { - path: path, - id: procedure.id - } - } - } - let(:path) { generate(:published_path) } - - before do - get :check_availability, params: params, format: 'js' - end - - context 'self path' do - let(:path) { procedure.path } - - it { expect(response.body).to include("innerHTML = ''") } - end - - context 'available path' do - it { expect(response.body).to include("innerHTML = ''") } - end - - context 'my path (brouillon)' do - let(:procedure_owned) { create(:procedure, :with_path, administrateur: admin) } - let(:path) { procedure_owned.path } - - it { - expect(response.body).to include('Une démarche en test existe déjà avec ce lien.') - } - end - - context 'my path' do - let(:procedure_owned) { create(:procedure, :published, administrateur: admin) } - let(:path) { procedure_owned.path } - - it { - expect(response.body).to include('Ce lien est déjà utilisé par une de vos démarche.') - expect(response.body).to include('Si vous voulez l’utiliser, l’ancienne démarche sera archivée') - } - end - - context 'unavailable path' do - let(:procedure_not_owned) { create(:procedure, :with_path, administrateur: create(:administrateur)) } - let(:path) { procedure_not_owned.path } - - it { - expect(response.body).to include('Ce lien est déjà utilisé par une démarche.') - expect(response.body).to include('Vous ne pouvez pas l’utiliser car il appartient à un autre administrateur.') - } - end - end - describe 'PATCH #monavis' do let!(:procedure) { create(:procedure, administrateur: admin) } let(:procedure_params) {