Refactor procedures_controller
This commit is contained in:
parent
b42095363e
commit
f1fd1b38ec
5 changed files with 23 additions and 50 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue