Merge pull request #4952 from betagouv/dev

2020-03-26-01
This commit is contained in:
Paul Chavard 2020-03-26 16:37:25 +01:00 committed by GitHub
commit c8c2633bdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 77 additions and 36 deletions

View file

@ -189,7 +189,7 @@ GEM
activejob (>= 5.0)
devise (>= 4.0)
diff-lcs (1.3)
discard (1.1.0)
discard (1.2.0)
activerecord (>= 4.2, < 7)
domain_name (0.5.20180417)
unf (>= 0.0.5, < 1.0.0)

View file

@ -8,11 +8,11 @@ module Manager
# this will be used to set the records shown on the `index` action.
def scoped_resource
if unfiltered_list?
# Don't display deleted dossiers in the unfiltered list…
Dossier
# Don't display discarded dossiers in the unfiltered list…
Dossier.kept
else
# … but allow them to be searched and displayed.
Dossier.unscope(:where)
Dossier.with_discarded
end
end
@ -20,9 +20,9 @@ module Manager
# Custom actions
#
def hide
def discard
dossier = Dossier.find(params[:id])
dossier.delete_and_keep_track!(current_administration, :manager_request)
dossier.discard_and_keep_track!(current_administration, :manager_request)
logger.info("Le dossier #{dossier.id} est supprimé par #{current_administration.email}")
flash[:notice] = "Le dossier #{dossier.id} a été supprimé."

View file

@ -209,7 +209,7 @@ module Users
dossier = current_user.dossiers.includes(:user, procedure: :administrateurs).find(params[:id])
if dossier.can_be_deleted_by_user?
dossier.delete_and_keep_track!(current_user, :user_request)
dossier.discard_and_keep_track!(current_user, :user_request)
flash.notice = 'Votre dossier a bien été supprimé.'
redirect_to dossiers_path
else

View file

@ -14,7 +14,6 @@ class AdministrateurDashboard < Administrate::BaseDashboard
updated_at: Field::DateTime,
procedures: Field::HasMany.with_options(limit: 20),
registration_state: Field::String.with_options(searchable: false),
current_sign_in_at: Field::DateTime,
features: FeaturesField,
email: Field::Email.with_options(searchable: false)
}.freeze
@ -39,7 +38,6 @@ class AdministrateurDashboard < Administrate::BaseDashboard
:created_at,
:updated_at,
:registration_state,
:current_sign_in_at,
:features,
:procedures
].freeze

View file

@ -12,7 +12,6 @@ class InstructeurDashboard < Administrate::BaseDashboard
user: Field::HasOne.with_options(searchable: true, searchable_field: 'email'),
created_at: Field::DateTime,
updated_at: Field::DateTime,
current_sign_in_at: Field::DateTime,
dossiers: Field::HasMany,
procedures: Field::HasMany,
features: FeaturesField
@ -35,7 +34,6 @@ class InstructeurDashboard < Administrate::BaseDashboard
:dossiers,
:id,
:user,
:current_sign_in_at,
:created_at,
:features
].freeze

View file

@ -92,4 +92,8 @@ class Administrateur < ApplicationRecord
destroy
end
# required to display feature flags field in manager
def features
end
end

View file

@ -340,6 +340,10 @@ class Dossier < ApplicationRecord
brouillon? || en_construction?
end
def can_be_deleted_by_manager?
kept? && can_be_deleted_by_user?
end
def messagerie_available?
!brouillon? && !archived
end
@ -467,7 +471,7 @@ class Dossier < ApplicationRecord
end
end
def delete_and_keep_track!(author, reason)
def discard_and_keep_track!(author, reason)
if keep_track_on_deletion? && en_construction?
deleted_dossier = DeletedDossier.create_from_dossier(self, reason)

View file

@ -191,6 +191,10 @@ class Instructeur < ApplicationRecord
user.administrateur.nil? && procedures.all? { |p| p.defaut_groupe_instructeur.instructeurs.count > 1 }
end
# required to display feature flags field in manager
def features
end
private
def annotations_hash(demande, annotations_privees, avis, messagerie)

View file

@ -120,7 +120,7 @@ class User < ApplicationRecord
end
dossiers.each do |dossier|
dossier.delete_and_keep_track!(administration, :user_removed)
dossier.discard_and_keep_track!(administration, :user_removed)
end
dossiers.with_discarded.destroy_all
destroy!

View file

@ -5,7 +5,8 @@ class FranceConnectService
client.authorization_uri(
scope: [:profile, :email],
state: SecureRandom.hex(16),
nonce: SecureRandom.hex(16)
nonce: SecureRandom.hex(16),
acr_values: 'eidas1'
)
end

View file

@ -22,7 +22,7 @@ as well as a link to its edit page.
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title">
<%= content_for(:title) %>
<% if dossier.hidden_at %>
<% if dossier.discarded? %>
(Supprimé)
<% end %>
</h1>
@ -31,8 +31,8 @@ as well as a link to its edit page.
<% if dossier.accepte? %>
<%= link_to 'Repasser en instruction', repasser_en_instruction_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous le passage en instruction du dossier ?" } %>
<% end %>
<% if dossier.hidden_at.nil? %>
<%= link_to 'Supprimer le dossier', hide_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %>
<% if dossier.can_be_deleted_by_manager? %>
<%= link_to 'Supprimer le dossier', discard_manager_dossier_path(dossier), method: :post, class: 'button', data: { confirm: "Confirmez vous la suppression du dossier ?" } %>
<% end %>
</div>
</header>

View file

@ -15,7 +15,7 @@ Rails.application.routes.draw do
end
resources :dossiers, only: [:index, :show] do
post 'hide', on: :member
post 'discard', on: :member
post 'repasser_en_instruction', on: :member
end

View file

@ -1,10 +1,21 @@
describe Manager::AdministrateursController, type: :controller do
let(:administration) { create(:administration) }
let(:administrateur) { create(:administrateur) }
before do
sign_in administration
end
describe '#show' do
render_views
before do
get :show, params: { id: administrateur.id }
end
it { expect(response.body).to include(administrateur.email) }
end
describe 'GET #new' do
render_views
it 'displays form to create a new admin' do
@ -41,23 +52,20 @@ describe Manager::AdministrateursController, type: :controller do
end
describe '#delete' do
let!(:admin) { create(:administrateur) }
subject { delete :delete, params: { id: admin.id } }
subject { delete :delete, params: { id: administrateur.id } }
it 'deletes the admin' do
subject
expect(Administrateur.find_by(id: admin.id)).to be_nil
expect(Administrateur.find_by(id: administrateur.id)).to be_nil
end
end
describe '#index' do
render_views
let(:admin) { create(:administrateur) }
it 'searches admin by email' do
get :index, params: { search: admin.email }
get :index, params: { search: administrateur.email }
expect(response).to be_success
end
end

View file

@ -1,20 +1,20 @@
describe Manager::DossiersController, type: :controller do
describe '#hide' do
describe '#discard' do
let(:administration) { create :administration }
let!(:dossier) { create(:dossier) }
let(:dossier) { create(:dossier) }
before do
sign_in administration
post :hide, params: { id: dossier.id }
post :discard, params: { id: dossier.id }
dossier.reload
end
it { expect(dossier.hidden_at).not_to be_nil }
it { expect(dossier.discarded?).to be_truthy }
end
describe '#repasser_en_instruction' do
let(:administration) { create :administration }
let!(:dossier) { create(:dossier, :accepte) }
let(:dossier) { create(:dossier, :accepte) }
before do
sign_in administration
@ -22,6 +22,6 @@ describe Manager::DossiersController, type: :controller do
dossier.reload
end
it { expect(dossier.en_instruction?).to be true }
it { expect(dossier.en_instruction?).to be_truthy }
end
end

View file

@ -1,9 +1,19 @@
describe Manager::InstructeursController, type: :controller do
let(:administration) { create(:administration) }
let(:instructeur) { create(:instructeur) }
describe '#show' do
render_views
before do
sign_in(administration)
get :show, params: { id: instructeur.id }
end
it { expect(response.body).to include(instructeur.email) }
end
describe '#delete' do
let!(:instructeur) { create(:instructeur) }
before { sign_in administration }
subject { delete :delete, params: { id: instructeur.id } }

View file

@ -1,6 +1,20 @@
describe Manager::UsersController, type: :controller do
let(:administration) { create(:administration) }
describe '#show' do
render_views
let(:administration) { create(:administration) }
let(:user) { create(:user) }
before do
sign_in(administration)
get :show, params: { id: user.id }
end
it { expect(response.body).to include(user.email) }
end
describe '#update' do
let!(:user) { create(:user, email: 'ancien.email@domaine.fr') }

View file

@ -670,7 +670,7 @@ describe Dossier do
end
end
describe "#delete_and_keep_track!" do
describe "#discard_and_keep_track!" do
let(:dossier) { create(:dossier, :en_construction) }
let(:deleted_dossier) { DeletedDossier.find_by(dossier_id: dossier.id) }
let(:last_operation) { dossier.dossier_operation_logs.last }
@ -681,7 +681,7 @@ describe Dossier do
allow(DossierMailer).to receive(:notify_deletion_to_administration).and_return(double(deliver_later: nil))
end
subject! { dossier.delete_and_keep_track!(dossier.user, reason) }
subject! { dossier.discard_and_keep_track!(dossier.user, reason) }
context 'brouillon' do
let(:dossier) { create(:dossier) }

View file

@ -278,7 +278,7 @@ describe User, type: :model do
end
it "keep track of dossiers and delete user" do
dossier_cache.delete_and_keep_track!(administration, :user_request)
dossier_cache.discard_and_keep_track!(administration, :user_request)
user.delete_and_keep_track_dossiers(administration)
expect(DeletedDossier.find_by(dossier_id: dossier_en_construction)).to be_present
@ -287,7 +287,7 @@ describe User, type: :model do
end
it "doesn't destroy dossiers of another user" do
dossier_cache.delete_and_keep_track!(administration, :user_request)
dossier_cache.discard_and_keep_track!(administration, :user_request)
user.delete_and_keep_track_dossiers(administration)
expect(Dossier.find_by(id: dossier_from_another_user.id)).to be_present