Merge pull request #10119 from demarches-simplifiees/add-explanation-when-publish-with-same-url-ldu
ETQ admin j'ai un message d'explication si j'utilise une URL déja utilisée lors de la publication d'une démarche
This commit is contained in:
commit
6c5c744411
12 changed files with 69 additions and 15 deletions
|
@ -3,7 +3,7 @@ module Administrateurs
|
||||||
layout 'all', only: [:all, :administrateurs]
|
layout 'all', only: [:all, :administrateurs]
|
||||||
respond_to :html, :xlsx
|
respond_to :html, :xlsx
|
||||||
|
|
||||||
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :confirmation, :allow_expert_review, :allow_expert_messaging, :experts_require_administrateur_invitation, :reset_draft, :publish_revision]
|
before_action :retrieve_procedure, only: [:champs, :annotations, :modifications, :edit, :zones, :monavis, :update_monavis, :jeton, :update_jeton, :publication, :publish, :transfert, :close, :confirmation, :allow_expert_review, :allow_expert_messaging, :experts_require_administrateur_invitation, :reset_draft, :publish_revision, :check_path]
|
||||||
before_action :draft_valid?, only: [:apercu]
|
before_action :draft_valid?, only: [:apercu]
|
||||||
after_action :reset_procedure, only: [:update]
|
after_action :reset_procedure, only: [:update]
|
||||||
|
|
||||||
|
@ -318,6 +318,16 @@ module Administrateurs
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_path
|
||||||
|
@path_available = @procedure.path_available?(params[:path])
|
||||||
|
@other_procedure = @procedure.other_procedure_with_path(params[:path])
|
||||||
|
respond_to do |format|
|
||||||
|
format.turbo_stream do
|
||||||
|
render :check_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def publish
|
def publish
|
||||||
@procedure.assign_attributes(publish_params)
|
@procedure.assign_attributes(publish_params)
|
||||||
|
|
||||||
|
|
|
@ -395,7 +395,7 @@ class Procedure < ApplicationRecord
|
||||||
slug = libelle&.parameterize&.first(50)
|
slug = libelle&.parameterize&.first(50)
|
||||||
suggestion = slug
|
suggestion = slug
|
||||||
counter = 1
|
counter = 1
|
||||||
while !path_available?(administrateur, suggestion)
|
while !path_available?(suggestion)
|
||||||
counter = counter + 1
|
counter = counter + 1
|
||||||
suggestion = "#{slug}-#{counter}"
|
suggestion = "#{slug}-#{counter}"
|
||||||
end
|
end
|
||||||
|
@ -408,10 +408,8 @@ class Procedure < ApplicationRecord
|
||||||
.find_by(path: path)
|
.find_by(path: path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def path_available?(administrateur, path)
|
def path_available?(path)
|
||||||
procedure = other_procedure_with_path(path)
|
other_procedure_with_path(path).blank?
|
||||||
|
|
||||||
procedure.blank? || (administrateur.owns?(procedure) && canonical_procedure_child?(procedure))
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def canonical_procedure_child?(procedure)
|
def canonical_procedure_child?(procedure)
|
||||||
|
|
|
@ -14,8 +14,11 @@
|
||||||
placeholder: t('activerecord.attributes.procedure.procedure_path_placeholder'),
|
placeholder: t('activerecord.attributes.procedure.procedure_path_placeholder'),
|
||||||
required: true,
|
required: true,
|
||||||
class: 'unstyled flex-1',
|
class: 'unstyled flex-1',
|
||||||
pattern: '^[a-z0-9_-]{3,200}$',
|
pattern: '[a-z0-9.\-_]{3,200}',
|
||||||
autocomplete: 'off')
|
autocomplete: 'off',
|
||||||
|
data: { controller: 'turbo-input', turbo_input_url_value: admin_procedure_check_path_path })
|
||||||
|
|
||||||
|
#check_path
|
||||||
|
|
||||||
.fr-input-group
|
.fr-input-group
|
||||||
= label_tag :lien_site_web, class: 'fr-label' do
|
= label_tag :lien_site_web, class: 'fr-label' do
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
= turbo_stream.update 'check_path' do
|
||||||
|
- if @path_available == false && current_administrateur.owns?(@other_procedure)
|
||||||
|
%p.fr-error-text= t('.path_not_available.owner')
|
||||||
|
- elsif @path_available == false
|
||||||
|
%p.fr-error-text= t('.path_not_available.not_owner')
|
||||||
|
- else
|
|
@ -657,8 +657,7 @@ en:
|
||||||
attributes:
|
attributes:
|
||||||
path:
|
path:
|
||||||
taken: is already used for procedure. You cannot use it because it belongs to another administrator.
|
taken: is already used for procedure. You cannot use it because it belongs to another administrator.
|
||||||
taken_can_be_claimed: Is the same as another of your procedure. If you publish this procedure, the other one will be unpublished
|
invalid: is not valid. It must countain between 3 and 200 characters among a-z, 0-9, '_' and '-'.
|
||||||
invalid: is not valid. It must countain between 3 and 50 characters among a-z, 0-9, '_' and '-'.
|
|
||||||
"dossier/champs":
|
"dossier/champs":
|
||||||
format: "%{message}"
|
format: "%{message}"
|
||||||
attributes:
|
attributes:
|
||||||
|
|
|
@ -658,8 +658,7 @@ fr:
|
||||||
attributes:
|
attributes:
|
||||||
path:
|
path:
|
||||||
taken: est déjà utilisé par une démarche. Vous ne pouvez pas l’utiliser car il appartient à un autre administrateur.
|
taken: est déjà utilisé par une démarche. Vous ne pouvez pas l’utiliser car il appartient à un autre administrateur.
|
||||||
taken_can_be_claimed: est identique à celui d’une autre de vos démarches publiées. Si vous publiez cette démarche, l’ancienne sera dépubliée et ne sera plus accessible au public. Les utilisateurs qui ont commencé un brouillon vont pouvoir le déposer.
|
invalid: n’est pas valide. Il doit comporter au moins 3 caractères, au plus 200 caractères et seuls les caractères a-z, 0-9, '_' et '-' sont autorisés.
|
||||||
invalid: 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.
|
|
||||||
"dossier/champs":
|
"dossier/champs":
|
||||||
format: "%{message}"
|
format: "%{message}"
|
||||||
attributes:
|
attributes:
|
||||||
|
|
|
@ -67,6 +67,10 @@ en:
|
||||||
dpd_part_4: How to do ? You can either send him the link to the procedure on test stage by email, or name him "administrator". In any case, publish your approach only after having had his opinion.
|
dpd_part_4: How to do ? You can either send him the link to the procedure on test stage by email, or name him "administrator". In any case, publish your approach only after having had his opinion.
|
||||||
back_to_procedure: 'Cancel and return to the procedure page'
|
back_to_procedure: 'Cancel and return to the procedure page'
|
||||||
submit: Publish
|
submit: Publish
|
||||||
|
check_path:
|
||||||
|
path_not_available:
|
||||||
|
owner: This URL is identical to another of your published procedures. If you publish this procedure, the old one will be unpublished and will no longer be accessible to the public.
|
||||||
|
not_owner: This URL is identical to another procedure, you must modify it.
|
||||||
autosave_notice:
|
autosave_notice:
|
||||||
form_saved: "Form saved"
|
form_saved: "Form saved"
|
||||||
form_error: "Form in error"
|
form_error: "Form in error"
|
||||||
|
|
|
@ -67,6 +67,10 @@ fr:
|
||||||
dpd_part_4: Comment faire ? Vous pouvez soit lui communiquer par email le lien vers la démarche en test, ou bien le nommer « administrateur ». Dans tous les cas, ne publiez votre démarche qu’après avoir eu son avis.
|
dpd_part_4: Comment faire ? Vous pouvez soit lui communiquer par email le lien vers la démarche en test, ou bien le nommer « administrateur ». Dans tous les cas, ne publiez votre démarche qu’après avoir eu son avis.
|
||||||
back_to_procedure: 'Annuler et revenir à la page de la démarche'
|
back_to_procedure: 'Annuler et revenir à la page de la démarche'
|
||||||
submit: Publier
|
submit: Publier
|
||||||
|
check_path:
|
||||||
|
path_not_available:
|
||||||
|
owner: Cette url est identique à celle d’une autre de vos démarches publiées. Si vous publiez cette démarche, l’ancienne sera dépubliée et ne sera plus accessible au public.
|
||||||
|
not_owner: Cette url est identique à celle d’une autre démarche, vous devez la modifier afin de pouvoir publier votre démarche.
|
||||||
autosave_notice:
|
autosave_notice:
|
||||||
form_saved: "Formulaire enregistré"
|
form_saved: "Formulaire enregistré"
|
||||||
form_error: "Formulaire en erreur"
|
form_error: "Formulaire en erreur"
|
||||||
|
|
|
@ -603,6 +603,7 @@ Rails.application.routes.draw do
|
||||||
put 'clone'
|
put 'clone'
|
||||||
put 'archive'
|
put 'archive'
|
||||||
get 'publication' => 'procedures#publication', as: :publication
|
get 'publication' => 'procedures#publication', as: :publication
|
||||||
|
get 'check_path' => 'procedures#check_path', as: :check_path
|
||||||
put 'publish' => 'procedures#publish', as: :publish
|
put 'publish' => 'procedures#publish', as: :publish
|
||||||
put 'reset_draft' => 'procedures#reset_draft', as: :reset_draft
|
put 'reset_draft' => 'procedures#reset_draft', as: :reset_draft
|
||||||
put 'publish_revision' => 'procedures#publish_revision', as: :publish_revision
|
put 'publish_revision' => 'procedures#publish_revision', as: :publish_revision
|
||||||
|
|
|
@ -1331,7 +1331,7 @@ describe Procedure do
|
||||||
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', administrateurs: procedure.administrateurs, zones: [create(:zone)])
|
create(:procedure, aasm_state: :publiee, path: 'inscription-au-college', administrateurs: procedure.administrateurs, zones: [create(:zone)])
|
||||||
end
|
end
|
||||||
|
|
||||||
it { is_expected.to eq 'inscription-au-college' }
|
it { is_expected.to eq 'inscription-au-college-2' }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,10 @@ describe 'As an administrateur I wanna clone a procedure', js: true do
|
||||||
|
|
||||||
# then publish
|
# then publish
|
||||||
find('#publish-procedure-link').click
|
find('#publish-procedure-link').click
|
||||||
expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure'
|
expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure-2'
|
||||||
|
fill_in 'procedure_path', with: 'libelle-de-la-procedure'
|
||||||
|
expect(page).to have_content 'Si vous publiez cette démarche, l’ancienne sera dépubliée et ne sera plus accessible au public.'
|
||||||
|
|
||||||
fill_in 'lien_site_web', with: 'http://some.website'
|
fill_in 'lien_site_web', with: 'http://some.website'
|
||||||
click_on 'publish'
|
click_on 'publish'
|
||||||
|
|
||||||
|
@ -87,7 +90,9 @@ describe 'As an administrateur I wanna clone a procedure', js: true do
|
||||||
|
|
||||||
# then publish
|
# then publish
|
||||||
find('#publish-procedure-link').click
|
find('#publish-procedure-link').click
|
||||||
expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure'
|
expect(find_field('procedure_path').value).to eq 'libelle-de-la-procedure-2'
|
||||||
|
fill_in 'procedure_path', with: 'libelle-de-la-procedure'
|
||||||
|
expect(page).to have_content 'Si vous publiez cette démarche, l’ancienne sera dépubliée et ne sera plus accessible au public.'
|
||||||
fill_in 'lien_site_web', with: 'http://some.website'
|
fill_in 'lien_site_web', with: 'http://some.website'
|
||||||
click_on 'publish'
|
click_on 'publish'
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ describe 'Publishing a procedure', js: true do
|
||||||
include ProcedureSpecHelper
|
include ProcedureSpecHelper
|
||||||
|
|
||||||
let(:administrateur) { create(:administrateur) }
|
let(:administrateur) { create(:administrateur) }
|
||||||
|
let(:other_administrateur) { create(:administrateur) }
|
||||||
|
|
||||||
let(:instructeurs) { [administrateur.user.instructeur] }
|
let(:instructeurs) { [administrateur.user.instructeur] }
|
||||||
let!(:procedure) do
|
let!(:procedure) do
|
||||||
create(:procedure_with_dossiers,
|
create(:procedure_with_dossiers,
|
||||||
|
@ -14,6 +16,16 @@ describe 'Publishing a procedure', js: true do
|
||||||
instructeurs: instructeurs,
|
instructeurs: instructeurs,
|
||||||
administrateur: administrateur)
|
administrateur: administrateur)
|
||||||
end
|
end
|
||||||
|
let!(:other_procedure) do
|
||||||
|
create(:procedure_with_dossiers,
|
||||||
|
:published,
|
||||||
|
:with_path,
|
||||||
|
:with_type_de_champ,
|
||||||
|
:with_service,
|
||||||
|
:with_zone,
|
||||||
|
instructeurs: instructeurs,
|
||||||
|
administrateur: other_administrateur)
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
login_as administrateur.user, scope: :user
|
login_as administrateur.user, scope: :user
|
||||||
|
@ -70,6 +82,19 @@ describe 'Publishing a procedure', js: true do
|
||||||
expect(page).to have_button('Publier', disabled: true)
|
expect(page).to have_button('Publier', disabled: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context 'when the procedure has the same path as another procedure from another admin ' do
|
||||||
|
scenario 'an error message prevents the publication' do
|
||||||
|
expect(find_field('procedure_path').value).to eq procedure.path
|
||||||
|
fill_in 'procedure_path', with: other_procedure.path
|
||||||
|
expect(page).to have_content 'vous devez la modifier afin de pouvoir publier votre démarche'
|
||||||
|
|
||||||
|
fill_in 'lien_site_web', with: 'http://some.website'
|
||||||
|
within('form') { click_on 'Publier' }
|
||||||
|
|
||||||
|
expect(page).to have_text('Le champ « Lien public » est déjà utilisé par une démarche.')
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when a procedure is closed' do
|
context 'when a procedure is closed' do
|
||||||
|
|
Loading…
Reference in a new issue