Merge pull request #9088 from colinux/fix-fork-invalid

ETQ usager invité sur un dossier, je peux ajouter une PJ d'un dossier en construction
This commit is contained in:
Colin Darie 2023-05-25 07:40:39 +00:00 committed by GitHub
commit c62893d7c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -15,7 +15,7 @@ class ChampPolicy < ApplicationPolicy
# but for some reasons ActiveRecord <= 5.2 generates bogus SQL. Hence the manual version of it below.
joined_scope = scope
.joins('LEFT OUTER JOIN dossiers ON dossiers.id = champs.dossier_id')
.joins('LEFT OUTER JOIN invites ON invites.dossier_id = dossiers.id')
.joins('LEFT OUTER JOIN invites ON invites.dossier_id = dossiers.id OR invites.dossier_id = dossiers.editing_fork_origin_id')
.joins('LEFT OUTER JOIN groupe_instructeurs ON groupe_instructeurs.id = dossiers.groupe_instructeur_id')
.joins('LEFT OUTER JOIN assign_tos ON assign_tos.groupe_instructeur_id = groupe_instructeurs.id')
.joins('LEFT OUTER JOIN instructeurs ON instructeurs.id = assign_tos.instructeur_id')

View file

@ -78,4 +78,21 @@ describe ChampPolicy do
it_behaves_like 'they cant access a private champ'
end
end
context 'when the champ is on a forked dossier' do
let(:signed_in_user) { dossier_owner }
let(:origin) { create(:dossier, procedure: procedure, user: dossier_owner) }
let(:dossier) { origin.find_or_create_editing_fork(dossier_owner) }
it_behaves_like 'they can access a public champ'
it_behaves_like 'they cant access a private champ'
context 'when the user is invited on the origin dossier' do
let(:invite) { create(:invite, :with_user, dossier: origin) }
let(:signed_in_user) { invite.user }
it_behaves_like 'they can access a public champ'
it_behaves_like 'they cant access a private champ'
end
end
end