commit
3f99f41372
14 changed files with 103 additions and 108 deletions
|
@ -73,7 +73,7 @@ module NewUser
|
|||
@dossier.en_construction!
|
||||
NotificationMailer.send_initiated_notification(@dossier).deliver_later
|
||||
redirect_to merci_dossier_path(@dossier)
|
||||
elsif owns_dossier?
|
||||
elsif current_user.owns?(dossier)
|
||||
redirect_to users_dossier_recapitulatif_path(@dossier)
|
||||
else
|
||||
redirect_to users_dossiers_invite_path(@dossier.invite_for_user(current_user))
|
||||
|
@ -142,19 +142,19 @@ module NewUser
|
|||
end
|
||||
|
||||
def ensure_ownership!
|
||||
if !owns_dossier?
|
||||
if !current_user.owns?(dossier)
|
||||
forbidden!
|
||||
end
|
||||
end
|
||||
|
||||
def ensure_ownership_or_invitation!
|
||||
if !dossier.owner_or_invite?(current_user)
|
||||
if !current_user.owns_or_invite?(dossier)
|
||||
forbidden!
|
||||
end
|
||||
end
|
||||
|
||||
def forbid_invite_submission!
|
||||
if passage_en_construction? && !owns_dossier?
|
||||
if passage_en_construction? && !current_user.owns?(dossier)
|
||||
forbidden!
|
||||
end
|
||||
end
|
||||
|
@ -172,10 +172,6 @@ module NewUser
|
|||
params.require(:dossier).permit(:autorisation_donnees)
|
||||
end
|
||||
|
||||
def owns_dossier?
|
||||
dossier.user_id == current_user.id
|
||||
end
|
||||
|
||||
def passage_en_construction?
|
||||
dossier.brouillon? && !draft?
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ class UsersController < ApplicationController
|
|||
|
||||
dossier = Dossier.find(dossier_id)
|
||||
|
||||
if !dossier.owner_or_invite?(current_user)
|
||||
if !current_user.owns_or_invite?(dossier)
|
||||
raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
||||
|
|
|
@ -16,10 +16,12 @@ module DossierHelper
|
|||
end
|
||||
|
||||
def delete_dossier_confirm(dossier)
|
||||
message = "Vous vous apprêtez à supprimer votre dossier ainsi que les informations qu’il contient. "
|
||||
message = ["Vous vous apprêtez à supprimer votre dossier ainsi que les informations qu’il contient."]
|
||||
if dossier.en_construction_ou_instruction?
|
||||
message += "Nous vous rappelons que toute suppression entraine l’annulation de la démarche en cours. "
|
||||
message << "Nous vous rappelons que toute suppression entraine l’annulation de la démarche en cours."
|
||||
end
|
||||
message += "Confirmer la suppression ?"
|
||||
message << "Confirmer la suppression ?"
|
||||
|
||||
message.join(" ")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -163,10 +163,6 @@ class Dossier < ApplicationRecord
|
|||
en_instruction? || accepte? || refuse? || sans_suite?
|
||||
end
|
||||
|
||||
def owner_or_invite?(user)
|
||||
self.user == user || invite_for_user(user).present?
|
||||
end
|
||||
|
||||
def invite_for_user(user)
|
||||
invites_user.find_by(user_id: user.id)
|
||||
end
|
||||
|
|
|
@ -38,7 +38,15 @@ class User < ApplicationRecord
|
|||
loged_in_with_france_connect.present?
|
||||
end
|
||||
|
||||
def owns?(dossier)
|
||||
dossier.user_id == id
|
||||
end
|
||||
|
||||
def invite?(dossier_id)
|
||||
invites.pluck(:dossier_id).include?(dossier_id.to_i)
|
||||
end
|
||||
|
||||
def owns_or_invite?(dossier)
|
||||
owns?(dossier) || invite?(dossier.id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- if !@facade.dossier.read_only?
|
||||
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||
- if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier))
|
||||
%a#maj_carte.action{ href: "/users/dossiers/#{@facade.dossier.id}/carte" }
|
||||
.col-lg-2.col-md-2.col-sm-2.col-xs-2.action
|
||||
= 'ÉDITER'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- if !@facade.dossier.read_only?
|
||||
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||
- if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier))
|
||||
= link_to modifier_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do
|
||||
#edit-dossier.col-lg-2.col-md-2.col-sm-2.col-xs-2.action
|
||||
= "ÉDITER"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- if !@facade.dossier.read_only?
|
||||
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||
- if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier))
|
||||
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
|
||||
.col-lg-4.col-md-4.col-sm-4.col-xs-4.action
|
||||
%a#maj_pj.action{ "data-target" => "#upload-pj-modal",
|
||||
|
|
|
@ -101,7 +101,7 @@
|
|||
Pièce non fournie
|
||||
|
||||
- if !@facade.dossier.read_only?
|
||||
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||
- if user_signed_in? && (current_user.owns_or_invite?(@facade.dossier))
|
||||
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
|
||||
.row
|
||||
.col-xs-4
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
.dossier-state= @facade.dossier.display_state
|
||||
.split-hr-left
|
||||
|
||||
- if @facade.dossier.user == current_user
|
||||
- if current_user.owns?(@facade.dossier)
|
||||
.text-center.mt-1
|
||||
= link_to ask_deletion_dossier_path(@facade.dossier), method: :post, class: "btn btn-danger", data: { confirm: delete_dossier_confirm(@facade.dossier) } do
|
||||
Supprimer définitivement
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
class: 'button send',
|
||||
data: { action: 'draft', disable_with: 'Envoi...' }
|
||||
|
||||
- if dossier.user == current_user
|
||||
- if current_user.owns?(dossier)
|
||||
= f.button 'Soumettre le dossier',
|
||||
class: 'button send primary',
|
||||
data: { action: 'submit', disable_with: 'Envoi...' }
|
||||
|
|
|
@ -397,44 +397,6 @@ describe Dossier do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#owner_or_invite?' do
|
||||
let(:owner) { create(:user) }
|
||||
let(:dossier) { create(:dossier, user: owner) }
|
||||
let(:invite_user) { create(:user) }
|
||||
let(:invite_gestionnaire) { create(:user) }
|
||||
|
||||
before do
|
||||
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
|
||||
create(:invite, dossier: dossier, user: invite_gestionnaire, type: 'InviteGestionnaire')
|
||||
end
|
||||
|
||||
subject { dossier.owner_or_invite?(user) }
|
||||
|
||||
context 'when user is owner' do
|
||||
let(:user) { owner }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when user was invited by user' do
|
||||
let(:user) { invite_user }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when user was invited by gestionnaire (legacy, no new invitations happen)' do
|
||||
let(:user) { invite_gestionnaire }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
|
||||
context 'when user is quidam' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#text_summary" do
|
||||
let(:procedure) { create(:procedure, libelle: "Procédure", organisation: "Organisme") }
|
||||
|
||||
|
|
|
@ -31,6 +31,37 @@ describe User, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#owns?' do
|
||||
let(:owner) { create(:user) }
|
||||
let(:dossier) { create(:dossier, user: owner) }
|
||||
let(:invite_user) { create(:user) }
|
||||
let(:invite_gestionnaire) { create(:user) }
|
||||
|
||||
subject { user.owns?(dossier) }
|
||||
|
||||
context 'when user is owner' do
|
||||
let(:user) { owner }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when user was invited by user' do
|
||||
before do
|
||||
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
|
||||
end
|
||||
|
||||
let(:user) { invite_user }
|
||||
|
||||
it { is_expected.to be_falsy }
|
||||
end
|
||||
|
||||
context 'when user is quidam' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
describe '#invite?' do
|
||||
let(:dossier) { create :dossier }
|
||||
let(:user) { dossier.user }
|
||||
|
@ -50,6 +81,37 @@ describe User, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#owns_or_invite?' do
|
||||
let(:owner) { create(:user) }
|
||||
let(:dossier) { create(:dossier, user: owner) }
|
||||
let(:invite_user) { create(:user) }
|
||||
let(:invite_gestionnaire) { create(:user) }
|
||||
|
||||
subject { user.owns_or_invite?(dossier) }
|
||||
|
||||
context 'when user is owner' do
|
||||
let(:user) { owner }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when user was invited by user' do
|
||||
before do
|
||||
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
|
||||
end
|
||||
|
||||
let(:user) { invite_user }
|
||||
|
||||
it { is_expected.to be_truthy }
|
||||
end
|
||||
|
||||
context 'when user is quidam' do
|
||||
let(:user) { create(:user) }
|
||||
|
||||
it { is_expected.to be_falsey }
|
||||
end
|
||||
end
|
||||
|
||||
context 'unified login' do
|
||||
it 'syncs credentials to associated gestionnaire' do
|
||||
user = create(:user)
|
||||
|
|
|
@ -72,61 +72,30 @@ describe 'users/recapitulatif/show.html.haml', type: :view do
|
|||
end
|
||||
|
||||
context 'when invite is logged' do
|
||||
context 'when invite is by Gestionnaire' do
|
||||
let!(:invite_user) { create(:user, email: 'invite@octo.com') }
|
||||
let!(:invite_user) { create(:user, email: 'invite@octo.com') }
|
||||
|
||||
before do
|
||||
create(:invite) { create(:invite, email: invite_user.email, user: invite_user, dossier: dossier) }
|
||||
sign_out dossier.user
|
||||
sign_in invite_user
|
||||
render
|
||||
end
|
||||
|
||||
describe 'les liens de modifications' do
|
||||
it 'describe link is not present' do
|
||||
expect(rendered).not_to have_css('#maj_infos')
|
||||
end
|
||||
|
||||
it 'map link is not present' do
|
||||
expect(rendered).not_to have_css('#maj_carte')
|
||||
end
|
||||
|
||||
it 'PJ link is not present' do
|
||||
expect(rendered).not_to have_css('#maj_pj')
|
||||
end
|
||||
|
||||
it 'archive link is not present' do
|
||||
expect(rendered).not_to have_content('Archiver')
|
||||
end
|
||||
end
|
||||
before do
|
||||
create(:invite) { create(:invite, email: invite_user.email, user: invite_user, dossier: dossier, type: 'InviteUser') }
|
||||
sign_out dossier.user
|
||||
sign_in invite_user
|
||||
render
|
||||
end
|
||||
|
||||
context 'invite is by User' do
|
||||
let!(:invite_user) { create(:user, email: 'invite@octo.com') }
|
||||
|
||||
before do
|
||||
create(:invite) { create(:invite, email: invite_user.email, user: invite_user, dossier: dossier, type: 'InviteUser') }
|
||||
sign_out dossier.user
|
||||
sign_in invite_user
|
||||
render
|
||||
describe 'les liens de modifications' do
|
||||
it 'describe link is not present' do
|
||||
expect(rendered).to have_css('#maj_infos')
|
||||
end
|
||||
|
||||
describe 'les liens de modifications' do
|
||||
it 'describe link is not present' do
|
||||
expect(rendered).to have_css('#maj_infos')
|
||||
end
|
||||
it 'map link is present' do
|
||||
expect(rendered).to have_css('#maj_carte')
|
||||
end
|
||||
|
||||
it 'map link is present' do
|
||||
expect(rendered).to have_css('#maj_carte')
|
||||
end
|
||||
it 'PJ link is present' do
|
||||
expect(rendered).to have_css('#maj_pj')
|
||||
end
|
||||
|
||||
it 'PJ link is present' do
|
||||
expect(rendered).to have_css('#maj_pj')
|
||||
end
|
||||
|
||||
it 'archive link is present' do
|
||||
expect(rendered).not_to have_content('Archiver')
|
||||
end
|
||||
it 'archive link is present' do
|
||||
expect(rendered).not_to have_content('Archiver')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue