Administrateur : le lien vers la page sur laquelle sera publiée la démarche est maintenant demandé à la publication (plutôt qu'à la création de la démarche)
This commit is contained in:
commit
a20e658cdb
10 changed files with 70 additions and 34 deletions
|
@ -107,17 +107,20 @@ class Admin::ProceduresController < AdminController
|
|||
|
||||
def publish
|
||||
path = params[:path]
|
||||
lien_site_web = params[:lien_site_web]
|
||||
procedure = current_administrateur.procedures.find(params[:procedure_id])
|
||||
|
||||
procedure.path = path
|
||||
procedure.lien_site_web = lien_site_web
|
||||
|
||||
if !procedure.validate
|
||||
flash.alert = 'Lien de la démarche invalide'
|
||||
flash.alert = 'Lien de la démarche invalide ou lien vers la démarche manquant'
|
||||
return redirect_to admin_procedures_path
|
||||
else
|
||||
procedure.path = nil
|
||||
end
|
||||
|
||||
if procedure.publish_or_reopen!(current_administrateur, path)
|
||||
if procedure.publish_or_reopen!(current_administrateur, path, lien_site_web)
|
||||
flash.notice = "Démarche publiée"
|
||||
redirect_to admin_procedures_path
|
||||
else
|
||||
|
|
|
@ -107,12 +107,12 @@ class Procedure < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def publish_or_reopen!(administrateur, path)
|
||||
if archivee? && may_reopen?(administrateur, path)
|
||||
reopen!(administrateur, path)
|
||||
elsif may_publish?(administrateur, path)
|
||||
def publish_or_reopen!(administrateur, path, lien_site_web)
|
||||
if archivee? && may_reopen?(administrateur, path, lien_site_web)
|
||||
reopen!(administrateur, path, lien_site_web)
|
||||
elsif may_publish?(administrateur, path, lien_site_web)
|
||||
reset!
|
||||
publish!(administrateur, path)
|
||||
publish!(administrateur, path, lien_site_web)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -488,21 +488,17 @@ class Procedure < ApplicationRecord
|
|||
update!(path: path)
|
||||
end
|
||||
|
||||
def can_publish?(administrateur, path)
|
||||
path_availability(administrateur, path).in?(PATH_CAN_PUBLISH)
|
||||
def can_publish?(administrateur, path, lien_site_web)
|
||||
path_availability(administrateur, path).in?(PATH_CAN_PUBLISH) && lien_site_web.present?
|
||||
end
|
||||
|
||||
def can_reopen?(administrateur, path)
|
||||
path_availability(administrateur, path).in?(PATH_CAN_PUBLISH)
|
||||
end
|
||||
|
||||
def after_publish(administrateur, path)
|
||||
def after_publish(administrateur, path, lien_site_web)
|
||||
update!(published_at: Time.zone.now)
|
||||
|
||||
claim_path_ownership!(path)
|
||||
end
|
||||
|
||||
def after_reopen(administrateur, path)
|
||||
def after_reopen(administrateur, path, lien_site_web)
|
||||
update!(published_at: Time.zone.now, archived_at: nil)
|
||||
|
||||
claim_path_ownership!(path)
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
= f.label :duree_conservation_dossiers_hors_ds, "Hors demarches-simplifiees.fr* (durée en mois après la fin de l'instruction)"
|
||||
= f.number_field :duree_conservation_dossiers_hors_ds, class: 'form-control', placeholder: '6', required: true
|
||||
|
||||
.form-group
|
||||
%h4 Où les usagers trouveront-ils le lien vers la démarche ?
|
||||
= f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche'
|
||||
- if @procedure.created_at.present?
|
||||
.form-group
|
||||
%h4 Où les usagers trouveront-ils le lien vers la démarche ?
|
||||
= f.text_field :lien_site_web, class: 'form-control', placeholder: 'https://exemple.gouv.fr/ma_demarche'
|
||||
|
||||
.form-group
|
||||
%h4 Cadre juridique *
|
||||
|
|
|
@ -38,6 +38,14 @@
|
|||
"https://vimeo.com/334463514",
|
||||
target: "_blank"
|
||||
|
||||
.form-group
|
||||
%h4 Où les usagers trouveront-ils le lien vers cette démarche ? *
|
||||
%p.center
|
||||
= text_field_tag(:lien_site_web, @procedure.lien_site_web,
|
||||
required: true,
|
||||
class: 'form-control',
|
||||
placeholder: 'https://exemple.gouv.fr/ma_demarche')
|
||||
|
||||
#path-messages
|
||||
#path_is_mine.text-warning.center.message
|
||||
Ce lien est déjà utilisé par une de vos démarche.
|
||||
|
|
|
@ -15,6 +15,7 @@ describe Admin::ProceduresController, type: :controller do
|
|||
let(:duree_conservation_dossiers_dans_ds) { 3 }
|
||||
let(:duree_conservation_dossiers_hors_ds) { 6 }
|
||||
let(:monavis_embed) { nil }
|
||||
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
||||
|
||||
let(:procedure_params) {
|
||||
{
|
||||
|
@ -26,7 +27,8 @@ describe Admin::ProceduresController, type: :controller do
|
|||
cadre_juridique: cadre_juridique,
|
||||
duree_conservation_dossiers_dans_ds: duree_conservation_dossiers_dans_ds,
|
||||
duree_conservation_dossiers_hors_ds: duree_conservation_dossiers_hors_ds,
|
||||
monavis_embed: monavis_embed
|
||||
monavis_embed: monavis_embed,
|
||||
lien_site_web: lien_site_web
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,23 +333,26 @@ describe Admin::ProceduresController, type: :controller do
|
|||
end
|
||||
|
||||
describe 'PUT #publish' do
|
||||
let(:procedure) { create(:procedure, administrateur: admin) }
|
||||
let(:procedure2) { create(:procedure, :published, administrateur: admin) }
|
||||
let(:procedure3) { create(:procedure, :published) }
|
||||
let(:procedure) { create(:procedure, administrateur: admin, lien_site_web: lien_site_web) }
|
||||
let(:procedure2) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
|
||||
let(:procedure3) { create(:procedure, :published, lien_site_web: lien_site_web) }
|
||||
let(:lien_site_web) { 'http://some.administration/' }
|
||||
|
||||
context 'when admin is the owner of the procedure' do
|
||||
before do
|
||||
put :publish, params: { procedure_id: procedure.id, path: path }
|
||||
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }
|
||||
procedure.reload
|
||||
procedure2.reload
|
||||
end
|
||||
|
||||
context 'procedure path does not exist' do
|
||||
let(:path) { 'new_path' }
|
||||
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
||||
|
||||
it 'publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_truthy
|
||||
expect(procedure.path).to eq(path)
|
||||
expect(procedure.lien_site_web).to eq(lien_site_web)
|
||||
expect(response.status).to eq 302
|
||||
expect(flash[:notice]).to have_content 'Démarche publiée'
|
||||
end
|
||||
|
@ -355,10 +360,12 @@ describe Admin::ProceduresController, type: :controller do
|
|||
|
||||
context 'procedure path exists and is owned by current administrator' do
|
||||
let(:path) { procedure2.path }
|
||||
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
||||
|
||||
it 'publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_truthy
|
||||
expect(procedure.path).to eq(path)
|
||||
expect(procedure.lien_site_web).to eq(lien_site_web)
|
||||
expect(response.status).to eq 302
|
||||
expect(flash[:notice]).to have_content 'Démarche publiée'
|
||||
end
|
||||
|
@ -371,10 +378,12 @@ describe Admin::ProceduresController, type: :controller do
|
|||
|
||||
context 'procedure path exists and is not owned by current administrator' do
|
||||
let(:path) { procedure3.path }
|
||||
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
||||
|
||||
it 'does not publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_falsey
|
||||
expect(procedure.path).not_to match(path)
|
||||
expect(procedure.lien_site_web).to match(lien_site_web)
|
||||
expect(response.status).to eq 200
|
||||
end
|
||||
|
||||
|
@ -387,10 +396,12 @@ describe Admin::ProceduresController, type: :controller do
|
|||
|
||||
context 'procedure path is invalid' do
|
||||
let(:path) { 'Invalid Procedure Path' }
|
||||
let(:lien_site_web) { 'http://mon-site.gouv.fr' }
|
||||
|
||||
it 'does not publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_falsey
|
||||
expect(procedure.path).not_to match(path)
|
||||
expect(procedure.lien_site_web).to match(lien_site_web)
|
||||
expect(response).to redirect_to :admin_procedures
|
||||
expect(flash[:alert]).to have_content 'Lien de la démarche invalide'
|
||||
end
|
||||
|
@ -413,10 +424,25 @@ describe Admin::ProceduresController, type: :controller do
|
|||
expect(flash[:alert]).to have_content 'Démarche inexistante'
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the admin does not provide a lien_site_web' do
|
||||
before do
|
||||
put :publish, params: { procedure_id: procedure.id, path: path, lien_site_web: lien_site_web }
|
||||
procedure.reload
|
||||
end
|
||||
context 'procedure path is valid but lien_site_web is missing' do
|
||||
let(:path) { 'new_path2' }
|
||||
let(:lien_site_web) { nil }
|
||||
|
||||
it 'does not publish the given procedure' do
|
||||
expect(procedure.publiee?).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'PUT #archive' do
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin) }
|
||||
let(:procedure) { create(:procedure, :published, administrateur: admin, lien_site_web: lien_site_web) }
|
||||
|
||||
context 'when admin is the owner of the procedure' do
|
||||
before do
|
||||
|
@ -432,7 +458,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, path: 'fake_path' }
|
||||
put :publish, params: { procedure_id: procedure.id, path: 'fake_path', lien_site_web: lien_site_web }
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ FactoryBot.define do
|
|||
duree_conservation_dossiers_dans_ds { 3 }
|
||||
duree_conservation_dossiers_hors_ds { 6 }
|
||||
ask_birthday { false }
|
||||
lien_site_web { "https://mon-site.gouv" }
|
||||
|
||||
transient do
|
||||
administrateur {}
|
||||
|
@ -37,7 +38,7 @@ FactoryBot.define do
|
|||
after(:build) do |procedure, _evaluator|
|
||||
procedure.for_individual = true
|
||||
procedure.types_de_champ << create(:type_de_champ, libelle: 'Texte obligatoire', mandatory: true)
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -147,13 +148,13 @@ FactoryBot.define do
|
|||
|
||||
trait :published do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
|
||||
end
|
||||
end
|
||||
|
||||
trait :archived do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
|
||||
procedure.archive!
|
||||
end
|
||||
end
|
||||
|
@ -162,14 +163,14 @@ FactoryBot.define do
|
|||
# For now the behavior is the same than :archived
|
||||
# (it may be different in the future though)
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
|
||||
procedure.archive!
|
||||
end
|
||||
end
|
||||
|
||||
trait :hidden do
|
||||
after(:build) do |procedure, _evaluator|
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path))
|
||||
procedure.publish!(procedure.administrateurs.first, generate(:published_path), procedure.lien_site_web)
|
||||
procedure.hide!
|
||||
end
|
||||
end
|
||||
|
|
|
@ -123,6 +123,7 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
|
|||
|
||||
within '#publish-modal' do
|
||||
expect(page).to have_field('procedure_path')
|
||||
fill_in 'lien_site_web', with: 'http://some.website'
|
||||
click_on 'publish'
|
||||
end
|
||||
|
||||
|
|
|
@ -554,7 +554,7 @@ describe Procedure do
|
|||
|
||||
before do
|
||||
Timecop.freeze(now)
|
||||
procedure.publish!(procedure.administrateurs.first, "example-path")
|
||||
procedure.publish!(procedure.administrateurs.first, "example-path", procedure.lien_site_web)
|
||||
end
|
||||
after { Timecop.return }
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe 'admin/procedures/edit.html.haml', type: :view, vcr: { cassette_name: 'admin_procedure_edit' } do
|
||||
let(:logo) { Rack::Test::UploadedFile.new("./spec/fixtures/files/logo_test_procedure.png", 'image/png') }
|
||||
let(:procedure) { create(:procedure, logo: logo) }
|
||||
let(:procedure) { create(:procedure, logo: logo, lien_site_web: 'http://some.website') }
|
||||
|
||||
before do
|
||||
assign(:procedure, procedure)
|
||||
|
|
|
@ -41,7 +41,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
|
|||
|
||||
describe 'procedure is published' do
|
||||
before do
|
||||
procedure.publish!(procedure.administrateurs.first, 'fake_path')
|
||||
procedure.publish!(procedure.administrateurs.first, 'fake_path', procedure.lien_site_web)
|
||||
procedure.reload
|
||||
render
|
||||
end
|
||||
|
@ -59,7 +59,7 @@ describe 'admin/procedures/show.html.haml', type: :view do
|
|||
|
||||
describe 'procedure is archived' do
|
||||
before do
|
||||
procedure.publish!(procedure.administrateurs.first, 'fake_path')
|
||||
procedure.publish!(procedure.administrateurs.first, 'fake_path', procedure.lien_site_web)
|
||||
procedure.archive!
|
||||
procedure.reload
|
||||
render
|
||||
|
|
Loading…
Reference in a new issue