Merge pull request #3556 from betagouv/open-publish-draft

Open publish draft 🚀
This commit is contained in:
Mathieu Magnin 2019-03-12 11:31:53 +01:00 committed by GitHub
commit fcddb69dab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 47 additions and 98 deletions

View file

@ -99,7 +99,7 @@ class Admin::ProceduresController < AdminController
@availability = @procedure.path_availability(@path)
end
render 'edit'
elsif Flipflop.publish_draft? && @procedure.brouillon?
elsif @procedure.brouillon?
reset_procedure
flash.notice = 'Démarche modifiée. Tous les dossiers de cette démarche ont été supprimés.'
redirect_to edit_admin_procedure_path(id: @procedure.id)
@ -273,10 +273,7 @@ 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).merge(administrateur_id: current_administrateur.id)
params.require(:procedure).permit(*editable_params, :duree_conservation_dossiers_dans_ds, :duree_conservation_dossiers_hors_ds, :for_individual, :individual_with_siret, :ask_birthday, :path).merge(administrateur_id: current_administrateur.id)
end
end
end

View file

@ -124,7 +124,7 @@ class Procedure < ApplicationRecord
# This method is needed for transition. Eventually this will be the same as brouillon?.
def brouillon_avec_lien?
Flipflop.publish_draft? && brouillon? && path.present?
brouillon? && path.present?
end
def publiee_ou_archivee?
@ -472,10 +472,8 @@ class Procedure < ApplicationRecord
end
def ensure_path_exists
if Flipflop.publish_draft?
if self.path.nil?
self.path = SecureRandom.uuid
end
if self.path.nil?
self.path = SecureRandom.uuid
end
end
end

View file

@ -3,10 +3,7 @@
%li{ class: @draft_class }
%a{ :href => "#{url_for :admin_procedures_draft}" }
%h5.text-primary
- if Flipflop.publish_draft?
En test
- else
Brouillons
En test
%li{ class: @active_class }
%a{ :href => "#{url_for :admin_procedures}" }

View file

@ -6,7 +6,7 @@
= form_for @procedure, url: { controller: 'admin/procedures', action: :create }, multipart: true do |f|
= render partial: 'informations', locals: { f: f }
.text-right
- if !Flipflop.publish_draft? || @availability.in?(Procedure::PATH_CAN_PUBLISH)
- if @availability.in?(Procedure::PATH_CAN_PUBLISH)
= f.button 'Valider', class: 'btn btn-info', id: 'save-procedure'
- else
= f.button 'Valider', class: 'btn btn-info', id: 'save-procedure', disabled: true

View file

@ -11,10 +11,7 @@
#procedure-list
%a#draft-procedures{ :href => "#{url_for :admin_procedures_draft}" }
.procedure-list-element{ class: @draft_class }
- if Flipflop.publish_draft?
En test
- else
Brouillons
En test
.badge.progress-bar-default
= current_administrateur.procedures.brouillons.count

View file

@ -14,7 +14,6 @@ Flipflop.configure do
end
feature :web_hook
feature :publish_draft
feature :enable_email_login_token
feature :new_champs_editor

View file

@ -0,0 +1,17 @@
namespace :after_party do
desc 'Deployment task: create_default_path_for_brouillons'
task create_default_path_for_brouillons: :environment do
puts "Running deploy task 'create_default_path_for_brouillons'"
# Put your task implementation HERE.
Procedure.brouillons.where(path: nil).each do |p|
p.path = SecureRandom.uuid
p.save
end
# Update task as completed. If you remove the line below, the task will
# run with every deploy (or every time you call after_party:run).
AfterParty::TaskRecord.create version: '20190306172842'
end # task :create_default_path_for_brouillons
end # namespace :after_party

View file

@ -136,28 +136,4 @@ namespace :support do
user.update(email: new_email)
end
desc <<~EOD
Activate feature publish draft
EOD
task activate_publish_draft: :environment do
start_with = ENV['START_WITH']
administrateurs = Administrateur.where("email like ?", "#{start_with}%")
rake_puts("Activating publish draft for #{administrateurs.count} administrateurs...")
administrateurs.each do |a|
rake_puts("Activating publish draft for #{a.email}")
a.features["publish_draft"] = true
a.save
a.procedures.brouillon.each do |p|
if p.path.nil?
p.path = SecureRandom.uuid
p.save
end
end
end
end
end

View file

@ -303,10 +303,6 @@ describe Admin::ProceduresController, type: :controller do
let!(:dossiers_count) { procedure.dossiers.count }
describe 'dossiers are dropped' do
before do
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
end
subject { update_procedure }
it {
@ -378,7 +374,7 @@ describe Admin::ProceduresController, type: :controller do
it 'does not publish the given procedure' do
expect(procedure.publiee?).to be_falsey
expect(procedure.path).to be_nil
expect(procedure.path).not_to match(path)
expect(response.status).to eq 200
end
@ -394,7 +390,7 @@ describe Admin::ProceduresController, type: :controller do
it 'does not publish the given procedure' do
expect(procedure.publiee?).to be_falsey
expect(procedure.path).to be_nil
expect(procedure.path).not_to match(path)
expect(response).to redirect_to :admin_procedures
expect(flash[:alert]).to have_content 'Lien de la démarche invalide'
end

View file

@ -7,7 +7,6 @@ feature 'As an administrateur I wanna clone a procedure', js: true do
let(:administrateur) { create(:administrateur) }
before do
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
login_as administrateur, scope: :administrateur
visit new_from_existing_admin_procedures_path
end

View file

@ -8,7 +8,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
let(:test_strategy) { Flipflop::FeatureSet.current.test! }
before do
test_strategy.switch!(:publish_draft, true)
test_strategy.switch!(:new_champs_editor, true)
login_as administrateur, scope: :administrateur
visit root_path
@ -50,29 +49,6 @@ feature 'As an administrateur I wanna create a new procedure', js: true do
expect(page).to have_current_path(champs_procedure_path(Procedure.last))
end
end
context "when publish_draft disabled" do
before do
test_strategy.switch!(:publish_draft, false)
end
scenario 'Finding save button for new procedure, libelle, description and cadre_juridique required' do
expect(page).to have_selector('#new-procedure')
find('#new-procedure').click
click_on 'from-scratch'
expect(page).to have_current_path(new_admin_procedure_path)
fill_in 'procedure_duree_conservation_dossiers_dans_ds', with: '3'
fill_in 'procedure_duree_conservation_dossiers_hors_ds', with: '6'
click_on 'save-procedure'
expect(page).to have_text('Libelle doit être rempli')
fill_in_dummy_procedure_details(fill_path: false)
click_on 'save-procedure'
expect(page).to have_current_path(champs_procedure_path(Procedure.last))
end
end
end
context 'Editing a new procedure' do

View file

@ -14,7 +14,6 @@ feature 'Administrateurs can edit procedures', js: true do
end
before do
Flipflop::FeatureSet.current.test!.switch!(:publish_draft, true)
login_as administrateur, scope: :administrateur
end

View file

@ -1,24 +1,17 @@
require 'spec_helper'
describe 'activate_publish_draft#clean' do
let(:rake_task) { Rake::Task['support:activate_publish_draft'] }
describe '20190306172842_create_default_path_for_brouillons.rake' do
let(:rake_task) { Rake::Task['after_party:create_default_path_for_brouillons'] }
let(:administrateur) { create(:administrateur) }
let!(:procedure) { create(:procedure, administrateur: administrateur) }
let!(:procedure2) { create(:simple_procedure, administrateur: administrateur) }
before do
ENV['START_WITH'] = administrateur.email
rake_task.invoke
administrateur.reload
end
after { rake_task.reenable }
it 'activate feature for administrateur' do
expect(administrateur.features["publish_draft"]).to eq(true)
end
it 'create a path for his brouillon procedure' do
expect(administrateur.procedures.brouillon.count).to eq(1)
expect(administrateur.procedures.brouillon.first.path).not_to eq(nil)

View file

@ -14,14 +14,14 @@ describe Gestionnaire, type: :model do
describe '#visible_procedures' do
let(:procedure_not_assigned) { create :procedure, administrateur: admin }
let(:procedure_without_link) { create :procedure, administrateur: admin }
let(:procedure_with_link) { create :procedure, :with_path, administrateur: admin }
let(:procedure_with_default_path) { create :procedure, administrateur: admin }
let(:procedure_with_custom_path) { create :procedure, :with_path, administrateur: admin }
let(:procedure_archived_manually) { create :procedure, :archived, administrateur: admin }
let(:procedure_archived_automatically) { create :procedure, :archived_automatically, administrateur: admin }
before do
assign(procedure_without_link)
assign(procedure_with_link)
assign(procedure_with_default_path)
assign(procedure_with_custom_path)
assign(procedure_archived_manually)
assign(procedure_archived_automatically)
end
@ -30,8 +30,8 @@ describe Gestionnaire, type: :model do
it do
expect(subject).not_to include(procedure_not_assigned)
expect(subject).not_to include(procedure_without_link)
expect(subject).to include(procedure_with_link)
expect(subject).to include(procedure_with_default_path)
expect(subject).to include(procedure_with_custom_path)
expect(subject).to include(procedure_archived_manually)
expect(subject).to include(procedure_archived_automatically)
end

View file

@ -386,7 +386,7 @@ describe Procedure do
cloned_procedure = subject
cloned_procedure.parent_procedure_id = nil
expect(cloned_procedure).to have_same_attributes_as(procedure)
expect(cloned_procedure).to have_same_attributes_as(procedure, except: ["path"])
end
it 'should not clone piece justificatives but create corresponding champs' do
@ -479,7 +479,7 @@ describe Procedure do
expect(subject.published_at).to be_nil
expect(subject.test_started_at).to be_nil
expect(subject.aasm_state).to eq "brouillon"
expect(subject.path).to be_nil
expect(subject.path).not_to be_nil
end
end
@ -638,9 +638,11 @@ describe Procedure do
end
context "without a path" do
let(:procedure) { create(:procedure) }
let(:procedure) { create(:procedure, :archived) }
it { is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11.csv") }
it do
is_expected.to eq("dossiers_procedure-#{procedure.id}_2018-01-02_23-11.csv")
end
end
end

View file

@ -158,9 +158,12 @@ RSpec.configure do |config|
end
}
RSpec::Matchers.define :have_same_attributes_as do |expected|
RSpec::Matchers.define :have_same_attributes_as do |expected, options|
match do |actual|
ignored = [:id, :procedure_id, :updated_at, :created_at]
if options.present? && options[:except]
ignored = ignored + options[:except]
end
actual.attributes.with_indifferent_access.except(*ignored) == expected.attributes.with_indifferent_access.except(*ignored)
end
end

View file

@ -33,8 +33,8 @@ describe 'admin/procedures/show.html.haml', type: :view do
it { expect(rendered).not_to have_css('a#reopen-procedure') }
end
describe 'procedure link is not present' do
it { expect(rendered).to have_content('Cette démarche na pas encore de lien, et nest pas accessible par le public.') }
describe 'procedure path is not customized' do
it { expect(rendered).to have_content('Cette démarche est actuellement en test') }
end
end
end