Merge pull request #514 from sgmap/430_admin_can_delete_procedure
#430 admin can delete procedure
This commit is contained in:
commit
6357a112c6
12 changed files with 124 additions and 5 deletions
|
@ -42,6 +42,14 @@ class Admin::ProceduresController < AdminController
|
|||
def edit
|
||||
end
|
||||
|
||||
def hide
|
||||
procedure = Procedure.find(params[:id])
|
||||
procedure.hide!
|
||||
|
||||
flash.notice = "Procédure supprimée, en cas d'erreur contactez nous : contact@tps.apientreprise.fr"
|
||||
redirect_to admin_procedures_draft_path
|
||||
end
|
||||
|
||||
def destroy
|
||||
procedure = Procedure.find(params[:id])
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class Dossier < ActiveRecord::Base
|
|||
belongs_to :procedure
|
||||
belongs_to :user
|
||||
|
||||
default_scope { where(hidden_at: nil) }
|
||||
scope :state_brouillon, -> { where(state: BROUILLON) }
|
||||
scope :state_not_brouillon, -> { where.not(state: BROUILLON) }
|
||||
scope :state_nouveaux, -> { where(state: NOUVEAUX) }
|
||||
|
|
|
@ -20,9 +20,13 @@ class Gestionnaire < ActiveRecord::Base
|
|||
include CredentialsSyncableConcern
|
||||
|
||||
def procedure_filter
|
||||
return nil unless assign_to.pluck(:procedure_id).include?(self[:procedure_filter])
|
||||
|
||||
self[:procedure_filter]
|
||||
procedure_id = self[:procedure_filter]
|
||||
if procedures.find_by(id: procedure_id).present?
|
||||
procedure_id
|
||||
else
|
||||
self.update_column(:procedure_filter, nil)
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def can_view_dossier?(dossier_id)
|
||||
|
|
|
@ -31,12 +31,19 @@ class Procedure < ActiveRecord::Base
|
|||
|
||||
mount_uploader :logo, ProcedureLogoUploader
|
||||
|
||||
default_scope { where(hidden_at: nil) }
|
||||
scope :not_archived, -> { where(archived: false) }
|
||||
scope :by_libelle, -> { order(libelle: :asc) }
|
||||
|
||||
validates :libelle, presence: true, allow_blank: false, allow_nil: false
|
||||
validates :description, presence: true, allow_blank: false, allow_nil: false
|
||||
|
||||
def hide!
|
||||
now = DateTime.now
|
||||
self.update_attributes(hidden_at: now)
|
||||
self.dossiers.update_all(hidden_at: now)
|
||||
end
|
||||
|
||||
def path
|
||||
procedure_path.path unless procedure_path.nil?
|
||||
end
|
||||
|
|
|
@ -129,3 +129,20 @@
|
|||
Aucune statistique pour le moment
|
||||
- else
|
||||
= pie_chart @facade.dossiers_for_pie_highchart
|
||||
|
||||
- if @facade.procedure.published? || @facade.procedure.archived?
|
||||
%h3 Supprimer la procédure
|
||||
.alert.alert-danger
|
||||
%p
|
||||
Attention : la suppression d'une procédure est définitive.
|
||||
- dossiers_count = @facade.procedure.dossiers.count
|
||||
- if dossiers_count > 0
|
||||
%p
|
||||
= pluralize(dossiers_count, "dossier est rattaché", "dossiers sont rattachés")
|
||||
à cette procédure, la suppression de cette procédure entrainera également leur suppression.
|
||||
%p.text-right
|
||||
= link_to "J'ai compris, je supprime la procédure",
|
||||
hide_admin_procedure_path(@facade.procedure),
|
||||
method: :post,
|
||||
class: "btn btn-danger",
|
||||
data: { confirm: "Voulez-vous supprimer la procédure ?", disable_with: "Suppression..." }
|
||||
|
|
|
@ -114,6 +114,10 @@ Rails.application.routes.draw do
|
|||
patch 'change_dossier_state' => 'change_dossier_state#change'
|
||||
|
||||
resources :procedures do
|
||||
member do
|
||||
post :hide
|
||||
end
|
||||
|
||||
resources :types_de_champ, only: [:destroy]
|
||||
resource :types_de_champ, only: [:show, :update] do
|
||||
post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up
|
||||
|
|
6
db/migrate/20170627120928_add_hidden_at_to_procedures.rb
Normal file
6
db/migrate/20170627120928_add_hidden_at_to_procedures.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
class AddHiddenAtToProcedures < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :procedures, :hidden_at, :datetime
|
||||
add_index :procedures, :hidden_at
|
||||
end
|
||||
end
|
6
db/migrate/20170627144046_add_hidden_at_to_dossiers.rb
Normal file
6
db/migrate/20170627144046_add_hidden_at_to_dossiers.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
class AddHiddenAtToDossiers < ActiveRecord::Migration[5.0]
|
||||
def change
|
||||
add_column :dossiers, :hidden_at, :datetime
|
||||
add_index :dossiers, :hidden_at
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20170627143701) do
|
||||
ActiveRecord::Schema.define(version: 20170627144046) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -175,6 +175,8 @@ ActiveRecord::Schema.define(version: 20170627143701) do
|
|||
t.datetime "received_at"
|
||||
t.datetime "processed_at"
|
||||
t.text "motivation"
|
||||
t.datetime "hidden_at"
|
||||
t.index ["hidden_at"], name: "index_dossiers_on_hidden_at", using: :btree
|
||||
t.index ["procedure_id"], name: "index_dossiers_on_procedure_id", using: :btree
|
||||
t.index ["user_id"], name: "index_dossiers_on_user_id", using: :btree
|
||||
end
|
||||
|
@ -381,7 +383,9 @@ ActiveRecord::Schema.define(version: 20170627143701) do
|
|||
t.string "lien_notice"
|
||||
t.boolean "for_individual", default: false
|
||||
t.boolean "individual_with_siret", default: false
|
||||
t.datetime "auto_archive_on"
|
||||
t.date "auto_archive_on"
|
||||
t.datetime "hidden_at"
|
||||
t.index ["hidden_at"], name: "index_procedures_on_hidden_at", using: :btree
|
||||
t.datetime "published_at"
|
||||
t.datetime "archived_at"
|
||||
end
|
||||
|
|
|
@ -928,4 +928,21 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe ".default_scope" do
|
||||
let!(:dossier) { create(:dossier, hidden_at: hidden_at) }
|
||||
|
||||
context "when dossier is not hidden" do
|
||||
let(:hidden_at) { nil }
|
||||
|
||||
it { expect(Dossier.count).to eq(1) }
|
||||
it { expect(Dossier.all).to include(dossier) }
|
||||
end
|
||||
|
||||
context "when dossier is hidden" do
|
||||
let(:hidden_at) { 1.day.ago }
|
||||
|
||||
it { expect(Dossier.count).to eq(0) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -260,6 +260,15 @@ describe Gestionnaire, type: :model do
|
|||
it { expect(AssignTo.where(gestionnaire: gestionnaire, procedure: procedure_3).count).to eq 0 }
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
|
||||
context "when procedure is hidden clear procedure_filter" do
|
||||
before do
|
||||
gestionnaire.update_column :procedure_filter, procedure_3.id
|
||||
procedure_3.hide!
|
||||
end
|
||||
|
||||
it { is_expected.to be_nil }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -302,4 +302,40 @@ describe Procedure do
|
|||
|
||||
it { is_expected.to eq('a-long-libelle-with-accents-blabla-coucou-hello-un') }
|
||||
end
|
||||
|
||||
describe ".default_scope" do
|
||||
let!(:procedure) { create(:procedure, hidden_at: hidden_at) }
|
||||
|
||||
context "when hidden_at is nil" do
|
||||
let(:hidden_at) { nil }
|
||||
|
||||
it { expect(Procedure.count).to eq(1) }
|
||||
it { expect(Procedure.all).to include(procedure) }
|
||||
end
|
||||
|
||||
context "when hidden_at is not nil" do
|
||||
let(:hidden_at) { 2.days.ago }
|
||||
|
||||
it { expect(Procedure.count).to eq(0) }
|
||||
it { expect { Procedure.find(procedure.id) }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#hide!" do
|
||||
let(:procedure) { create(:procedure) }
|
||||
let!(:dossier) { create(:dossier, procedure: procedure) }
|
||||
let!(:dossier2) { create(:dossier, procedure: procedure) }
|
||||
|
||||
it { expect(Dossier.count).to eq(2) }
|
||||
it { expect(Dossier.all).to include(dossier, dossier2) }
|
||||
|
||||
context "when hidding procedure" do
|
||||
before do
|
||||
procedure.hide!
|
||||
end
|
||||
|
||||
it { expect(procedure.dossiers.count).to eq(0) }
|
||||
it { expect(Dossier.count).to eq(0) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue