Add feature delete for draft procedure
This commit is contained in:
parent
86e26e520c
commit
1dcb29ec65
9 changed files with 77 additions and 34 deletions
|
@ -7,7 +7,7 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@procedures = smart_listing_create :procedures,
|
@procedures = smart_listing_create :procedures,
|
||||||
current_administrateur.procedures.where(published: true, archived: false),
|
current_administrateur.procedures.where(published: true, archived: false).order(created_at: :desc),
|
||||||
partial: "admin/procedures/list",
|
partial: "admin/procedures/list",
|
||||||
array: true
|
array: true
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
def archived
|
def archived
|
||||||
@procedures = smart_listing_create :procedures,
|
@procedures = smart_listing_create :procedures,
|
||||||
current_administrateur.procedures.where(archived: true),
|
current_administrateur.procedures.where(archived: true).order(created_at: :desc),
|
||||||
partial: "admin/procedures/list",
|
partial: "admin/procedures/list",
|
||||||
array: true
|
array: true
|
||||||
|
|
||||||
|
@ -27,8 +27,8 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
def draft
|
def draft
|
||||||
@procedures = smart_listing_create :procedures,
|
@procedures = smart_listing_create :procedures,
|
||||||
current_administrateur.procedures.where(published: false, archived: false),
|
current_administrateur.procedures.where(published: false, archived: false).order(created_at: :desc),
|
||||||
partial: "admin/procedures/draft_list",
|
partial: "admin/procedures/list",
|
||||||
array: true
|
array: true
|
||||||
|
|
||||||
draft_class
|
draft_class
|
||||||
|
@ -45,6 +45,17 @@ class Admin::ProceduresController < AdminController
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
procedure = Procedure.find(params[:id])
|
||||||
|
|
||||||
|
return render json: {}, status: 401 if procedure.published? || procedure.archived?
|
||||||
|
|
||||||
|
procedure.destroy
|
||||||
|
|
||||||
|
flash.notice = 'Procédure supprimée'
|
||||||
|
redirect_to admin_procedures_draft_path
|
||||||
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@procedure ||= Procedure.new
|
@procedure ||= Procedure.new
|
||||||
@procedure.module_api_carto ||= ModuleAPICarto.new
|
@procedure.module_api_carto ||= ModuleAPICarto.new
|
||||||
|
|
|
@ -2,7 +2,7 @@ class CommentaireDecorator < Draper::Decorator
|
||||||
delegate_all
|
delegate_all
|
||||||
|
|
||||||
def created_at_fr
|
def created_at_fr
|
||||||
created_at.to_datetime.strftime('%d/%m/%Y - %H:%M')
|
created_at.localtime.strftime('%d/%m/%Y - %H:%M')
|
||||||
rescue
|
rescue
|
||||||
'dd/mm/YYYY - HH:MM'
|
'dd/mm/YYYY - HH:MM'
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,7 +3,7 @@ class DossierDecorator < Draper::Decorator
|
||||||
delegate_all
|
delegate_all
|
||||||
|
|
||||||
def display_date
|
def display_date
|
||||||
date_previsionnelle.to_date.strftime('%d/%m/%Y')
|
date_previsionnelle.localtime.strftime('%d/%m/%Y')
|
||||||
rescue
|
rescue
|
||||||
'dd/mm/YYYY'
|
'dd/mm/YYYY'
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,10 @@ class ProcedureDecorator < Draper::Decorator
|
||||||
h.new_users_dossiers_url(procedure_id: id)
|
h.new_users_dossiers_url(procedure_id: id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def created_at_fr
|
||||||
|
created_at.localtime.strftime('%d/%m/%Y %H:%M')
|
||||||
|
end
|
||||||
|
|
||||||
def logo_img
|
def logo_img
|
||||||
return 'logo-tps.png' if logo.blank?
|
return 'logo-tps.png' if logo.blank?
|
||||||
logo
|
logo
|
||||||
|
|
|
@ -4,7 +4,7 @@ class Gestionnaire < ActiveRecord::Base
|
||||||
|
|
||||||
has_and_belongs_to_many :administrateurs
|
has_and_belongs_to_many :administrateurs
|
||||||
|
|
||||||
has_many :assign_to
|
has_many :assign_to, dependent: :destroy
|
||||||
has_many :procedures, through: :assign_to
|
has_many :procedures, through: :assign_to
|
||||||
has_many :dossiers, through: :procedures
|
has_many :dossiers, through: :procedures
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
class Procedure < ActiveRecord::Base
|
class Procedure < ActiveRecord::Base
|
||||||
has_many :types_de_piece_justificative, dependent: :destroy
|
has_many :types_de_piece_justificative, dependent: :destroy
|
||||||
has_many :types_de_champ, dependent: :destroy
|
has_many :types_de_champ, dependent: :destroy
|
||||||
has_many :dossiers, dependent: :destroy
|
has_many :dossiers
|
||||||
|
|
||||||
has_one :module_api_carto, dependent: :destroy
|
has_one :module_api_carto, dependent: :destroy
|
||||||
|
|
||||||
belongs_to :administrateur
|
belongs_to :administrateur
|
||||||
|
|
||||||
has_many :assign_to
|
has_many :assign_to, dependent: :destroy
|
||||||
has_many :gestionnaires, through: :assign_to
|
has_many :gestionnaires, through: :assign_to
|
||||||
|
|
||||||
delegate :use_api_carto, to: :module_api_carto
|
delegate :use_api_carto, to: :module_api_carto
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
- unless smart_listing.empty?
|
|
||||||
%table.table
|
|
||||||
%thead
|
|
||||||
%th#ID= smart_listing.sortable 'ID', 'id'
|
|
||||||
%th#libelle= smart_listing.sortable 'Libellé', 'libelle'
|
|
||||||
%th#lien Actions
|
|
||||||
|
|
||||||
- @procedures.each do |procedure|
|
|
||||||
- procedure = procedure.decorate
|
|
||||||
%tr
|
|
||||||
%td.col-md-1.col-lg-1= procedure.id
|
|
||||||
%td.col-md-6.col-lg-6
|
|
||||||
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
|
|
||||||
%td= link_to('cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-xs btn-primary')
|
|
||||||
|
|
||||||
= smart_listing.paginate
|
|
||||||
= smart_listing.pagination_per_page_links
|
|
||||||
|
|
||||||
- else
|
|
||||||
%h4.center
|
|
||||||
Aucune procédure
|
|
|
@ -3,7 +3,9 @@
|
||||||
%thead
|
%thead
|
||||||
%th#ID= smart_listing.sortable 'ID', 'id'
|
%th#ID= smart_listing.sortable 'ID', 'id'
|
||||||
%th#libelle= smart_listing.sortable 'Libellé', 'libelle'
|
%th#libelle= smart_listing.sortable 'Libellé', 'libelle'
|
||||||
%th#lien Lien
|
- unless @draft_class
|
||||||
|
%th#lien Lien
|
||||||
|
%th#created_at= smart_listing.sortable 'Date création', 'created_at'
|
||||||
%th#lien Actions
|
%th#lien Actions
|
||||||
|
|
||||||
- @procedures.each do |procedure|
|
- @procedures.each do |procedure|
|
||||||
|
@ -12,8 +14,14 @@
|
||||||
%td.col-md-1.col-lg-1= procedure.id
|
%td.col-md-1.col-lg-1= procedure.id
|
||||||
%td.col-md-6.col-lg-6
|
%td.col-md-6.col-lg-6
|
||||||
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
|
= link_to(procedure.libelle, "/admin/procedures/#{procedure.id}")
|
||||||
%td= link_to procedure.lien, procedure.lien
|
- unless @draft_class
|
||||||
%td= link_to('cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-xs btn-primary')
|
%td= link_to procedure.lien, procedure.lien
|
||||||
|
%td
|
||||||
|
= procedure.created_at_fr
|
||||||
|
%td
|
||||||
|
= link_to('Cloner', admin_procedure_clone_path(procedure.id), 'data-method' => :put, class: 'btn-sm btn-primary')
|
||||||
|
- unless procedure.published? || procedure.archived?
|
||||||
|
= link_to('X', url_for(controller: 'admin/procedures', action: :destroy, id: procedure.id), 'data-method' => :delete, class: 'btn-sm btn-danger')
|
||||||
|
|
||||||
= smart_listing.paginate
|
= smart_listing.paginate
|
||||||
= smart_listing.pagination_per_page_links
|
= smart_listing.pagination_per_page_links
|
||||||
|
|
|
@ -52,6 +52,47 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
it { expect(response.status).to eq(200) }
|
it { expect(response.status).to eq(200) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'DELETE #destroy' do
|
||||||
|
|
||||||
|
let(:procedure_draft) { create :procedure, published: false, archived: false }
|
||||||
|
let(:procedure_published) { create :procedure, published: true, archived: false }
|
||||||
|
let(:procedure_archived) { create :procedure, published: false, archived: true }
|
||||||
|
|
||||||
|
subject { delete :destroy, id: procedure.id }
|
||||||
|
|
||||||
|
context 'when procedure is draft' do
|
||||||
|
let!(:procedure) { procedure_draft }
|
||||||
|
|
||||||
|
describe 'tech params' do
|
||||||
|
before do
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 302 }
|
||||||
|
it { expect(flash[:notice]).to be_present }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'destroy procedure is call' do
|
||||||
|
expect_any_instance_of(Procedure).to receive(:destroy)
|
||||||
|
subject
|
||||||
|
end
|
||||||
|
|
||||||
|
it { expect { subject }.to change{Procedure.count}.by(-1) }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure is published' do
|
||||||
|
let(:procedure) { procedure_published }
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 401 }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when procedure is archived' do
|
||||||
|
let(:procedure) { procedure_published }
|
||||||
|
|
||||||
|
it { expect(subject.status).to eq 401 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe 'GET #edit' do
|
describe 'GET #edit' do
|
||||||
let(:published) { false }
|
let(:published) { false }
|
||||||
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
|
let(:procedure) { create(:procedure, administrateur: admin, published: published) }
|
||||||
|
@ -270,7 +311,7 @@ describe Admin::ProceduresController, type: :controller do
|
||||||
let!(:procedure) { create(:procedure, administrateur: admin) }
|
let!(:procedure) { create(:procedure, administrateur: admin) }
|
||||||
subject { put :clone, procedure_id: procedure.id }
|
subject { put :clone, procedure_id: procedure.id }
|
||||||
|
|
||||||
it { expect{ subject }.to change(Procedure, :count).by(1) }
|
it { expect { subject }.to change(Procedure, :count).by(1) }
|
||||||
|
|
||||||
context 'when admin is the owner of the procedure' do
|
context 'when admin is the owner of the procedure' do
|
||||||
before do
|
before do
|
||||||
|
|
Loading…
Reference in a new issue