Enable republish on démarches dépubliée

This commit is contained in:
Paul Chavard 2020-03-13 15:32:30 +01:00
parent 60998f410d
commit b516cbc179
4 changed files with 118 additions and 17 deletions

View file

@ -195,7 +195,11 @@ class Procedure < ApplicationRecord
def path_available?(administrateur, path)
procedure = other_procedure_with_path(path)
procedure.blank? || administrateur.owns?(procedure)
procedure.blank? || (administrateur.owns?(procedure) && canonical_procedure_child?(procedure))
end
def canonical_procedure_child?(procedure)
!canonical_procedure || canonical_procedure == procedure || canonical_procedure == procedure.canonical_procedure
end
def locked?

View file

@ -1,9 +1,9 @@
= render partial: 'admin/closed_mail_template_attestation_inconsistency_alert'
.row.white-back
#procedure_show
= render 'modal_publish', procedure: @procedure, administrateur: @current_administrateur
= render partial: '/admin/procedures/modal_transfer'
= render 'modal_transfer'
#procedure_show
- if @procedure.brouillon?
- if @procedure.missing_steps.present?
- missing_elements = []
@ -12,20 +12,20 @@
- if @procedure.service.nil?
- missing_elements << 'un service'
- message = "Affectez #{missing_elements.join(' et ')} à votre démarche."
%a.action_button.btn.btn-success#disabled-publish-procedure{ data: { toggle: :tooltip, placement: :bottom }, style: 'float: right; margin-top: 10px;', disabled: true, title: message }
%button.action_button.btn.btn-success#disabled-publish-procedure{ data: { toggle: :tooltip, placement: :bottom }, style: 'float: right; margin-top: 10px;', disabled: true, title: message }
%i.fa.fa-eraser
Publier
- else
%a.btn.btn-success#publish-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px;' }
%button.btn.btn-success#publish-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px;' }
%i.fa.fa-eraser
Publier
%a.btn.btn-default#transfer-procedure{ data: { target: '#transfer-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' }
%button.btn.btn-default#transfer-procedure{ data: { target: '#transfer-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' }
%i.fa.fa-exchange
Envoyer une copie
- if @procedure.close?
%a.btn.btn-default#reopen-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' }
- if @procedure.close? || @procedure.depubliee?
%button.btn.btn-default#reopen-procedure{ data: { target: '#publish-modal', toggle: :modal }, type: 'button', style: 'float: right; margin-top: 10px; margin-right: 10px;' }
%i.fa.fa-rocket
Réactiver

View file

@ -0,0 +1,97 @@
require 'features/admin/procedure_spec_helper'
feature 'Publication de démarches', js: true do
include ProcedureSpecHelper
let(:administrateur) { create(:administrateur) }
let(:instructeurs) { [administrateur.user.instructeur] }
let!(:procedure) do
create(:procedure_with_dossiers,
:with_path,
:with_type_de_champ,
:with_service,
instructeurs: instructeurs,
administrateur: administrateur)
end
before do
login_as administrateur.user, scope: :user
end
context 'lorsquune démarche est en test' do
scenario 'un administrateur peut la publier' do
visit admin_procedures_draft_path
click_on procedure.libelle
within "#procedure_show" do
click_on "Publier"
end
within '#publish-modal' do
expect(find_field('procedure_path').value).to eq procedure.path
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish'
end
expect(page).to have_text('Démarche publiée')
expect(page).to have_selector('.procedure-lien')
end
end
context 'lorsquune démarche est close' do
let!(:procedure) do
create(:procedure_with_dossiers,
:closed,
:with_path,
:with_type_de_champ,
:with_service,
instructeurs: instructeurs,
administrateur: administrateur)
end
scenario 'un administrateur peut la publier' do
visit admin_procedures_archived_path
click_on procedure.libelle
within "#procedure_show" do
click_on "Réactiver"
end
within '#publish-modal' do
expect(find_field('procedure_path').value).to eq procedure.path
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish'
end
expect(page).to have_text('Démarche publiée')
expect(page).to have_selector('.procedure-lien')
end
end
context 'lorsquune démarche est dépublié' do
let!(:procedure) do
create(:procedure_with_dossiers,
:unpublished,
:with_path,
:with_type_de_champ,
:with_service,
instructeurs: instructeurs,
administrateur: administrateur)
end
scenario 'un administrateur peut la publier' do
visit admin_procedures_archived_path
click_on procedure.libelle
within "#procedure_show" do
click_on "Réactiver"
end
within '#publish-modal' do
expect(find_field('procedure_path').value).to eq procedure.path
fill_in 'lien_site_web', with: 'http://some.website'
click_on 'publish'
end
expect(page).to have_text('Démarche publiée')
expect(page).to have_selector('.procedure-lien')
end
end
end

View file

@ -14,9 +14,9 @@ describe 'admin/procedures/show.html.haml', type: :view do
end
describe 'publish button is not visible' do
it { expect(rendered).not_to have_css('a#publish-procedure') }
it { expect(rendered).not_to have_css('button#publish-procedure') }
it { expect(rendered).not_to have_css('button#archive-procedure') }
it { expect(rendered).not_to have_css('a#reopen-procedure') }
it { expect(rendered).not_to have_css('button#reopen-procedure') }
end
end
@ -27,9 +27,9 @@ describe 'admin/procedures/show.html.haml', type: :view do
end
describe 'publish button is visible' do
it { expect(rendered).to have_css('a#publish-procedure') }
it { expect(rendered).to have_css('button#publish-procedure') }
it { expect(rendered).not_to have_css('button#archive-procedure') }
it { expect(rendered).not_to have_css('a#reopen-procedure') }
it { expect(rendered).not_to have_css('button#reopen-procedure') }
end
describe 'procedure path is not customized' do
@ -46,9 +46,9 @@ describe 'admin/procedures/show.html.haml', type: :view do
end
describe 'archive button is visible', js: true do
it { expect(rendered).not_to have_css('a#publish-procedure') }
it { expect(rendered).not_to have_css('button#publish-procedure') }
it { expect(rendered).to have_css('button#archive-procedure') }
it { expect(rendered).not_to have_css('a#reopen-procedure') }
it { expect(rendered).not_to have_css('button#reopen-procedure') }
end
describe 'procedure link is present' do
@ -65,9 +65,9 @@ describe 'admin/procedures/show.html.haml', type: :view do
end
describe 'Re-enable button is visible' do
it { expect(rendered).not_to have_css('a#publish-procedure') }
it { expect(rendered).not_to have_css('button#publish-procedure') }
it { expect(rendered).not_to have_css('button#archive-procedure') }
it { expect(rendered).to have_css('a#reopen-procedure') }
it { expect(rendered).to have_css('button#reopen-procedure') }
end
describe 'procedure link is present' do