Skip to content

Commit

Permalink
Fix affichage onglet Retours
Browse files Browse the repository at this point in the history
  • Loading branch information
clairezed committed Feb 5, 2025
1 parent 85430b3 commit 7d39c40
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/admin/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

scope :admin, group: :role
scope :managers, group: :role
scope :cooperation_managers, group: :role

scope :managers_not_invited, group: :invitations
scope :not_invited, group: :invitations
Expand Down
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class User < ApplicationRecord
#
scope :admin, -> { not_deleted.joins(:user_rights).merge(UserRight.category_admin) }
scope :managers, -> { not_deleted.joins(:user_rights).merge(UserRight.category_manager).distinct }
scope :cooperation_managers, -> { not_deleted.joins(:user_rights).merge(UserRight.category_cooperation_manager).distinct }
scope :national_referent, -> { not_deleted.joins(:user_rights).merge(UserRight.category_national_referent).distinct }

scope :not_invited, -> { not_deleted.where(invitation_sent_at: nil) }
Expand Down
2 changes: 1 addition & 1 deletion app/policies/shared_satisfaction_policy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class SharedSatisfactionPolicy < ApplicationPolicy
def show_navbar?
Institution.expert_provider.include?(@user.institution)
@user.is_manager? || @user.experts.present?
end
end
1 change: 1 addition & 0 deletions config/locales/models.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ fr:
bassins_emploi: Bassins d’emploi
being_taken_care_of: En cours
completed: Analyses terminées
cooperation_managers: Resp. de coopération
deleted: Supprimés
diagnosis_completed: Analyses terminées
done: Clôturé
Expand Down
6 changes: 6 additions & 0 deletions spec/factories/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@
end
end

trait :cooperation_manager do
after(:create) do |user, _|
user.managed_cooperations << create(:cooperation, institution: user.institution)
end
end

trait :national_manager do
antenne factory: [:antenne, :with_experts_subjects, :national], strategy: :create
after(:create) do |user, _|
Expand Down
18 changes: 15 additions & 3 deletions spec/policies/shared_satisfaction_policy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,28 @@
permissions :show_navbar? do
let(:user) { create :user, antenne: create(:antenne, institution: create(:institution)) }

context "grants access if user is from an expert provider institution" do
before { user.institution.categories << create(:category, label: 'expert_provider') }
context "grants access if user is manager" do
before { user.user_rights.create(category: :manager, rightable_element: user.antenne) }

it { is_expected.to permit(user) }
end

context "denies access if user is NOT from an expert provider institution" do
context "grants access if user is simple conseiller" do
before { user.experts << create(:expert, antenne: user.antenne) }

it { is_expected.to permit(user) }
end

context "denies access if user is admin" do
let(:user) { create :user, :admin }

it { is_expected.not_to permit(user) }
end

context "denies access if user only cooperation manager" do
let(:user) { create :user, :cooperation_manager }

it { is_expected.not_to permit(user) }
end
end
end

0 comments on commit 7d39c40

Please sign in to comment.