Skip to content

Commit

Permalink
Add policy call for lieux
Browse files Browse the repository at this point in the history
  • Loading branch information
victormours committed Jan 24, 2025
1 parent 9371f3b commit 50a161d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion app/policies/agent/rdv_plan_policy.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Agent::RdvPlanPolicy < ApplicationPolicy
# TODO: ajouter des contraintes sur le lieu et le rdv_agent
def create?
pundit_user == record.planning_agent
authorized_lieu && pundit_user == record.planning_agent
end
alias edit? create?

Expand All @@ -10,4 +10,12 @@ def resolve
scope.where(planning_agent: pundit_user)
end
end

private

def authorized_lieu
return true unless record.lieu_id

Agent::LieuPolicy::Scope.new(pundit_user, Lieu.enabled).resolve.find_by(id: record.lieu_id).present?
end
end
2 changes: 1 addition & 1 deletion app/views/agents/rdv_plans/_modalites_field.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fieldset[class="fr-fieldset" id="rdv_plan[modalite]" aria-labelledby="radio-rich
| Comment souhaitez-vous faire le rendez-vous ?

- if available_location_types.include?("public_office")
- lieux = Lieu.enabled.where(organisation_id: current_agent.organisations.select(:id))
- lieux = policy_scope(Lieu.enabled, policy_scope_class: Agent::LieuPolicy::Scope)
- lieux.each do |lieu|
.fr-fieldset__element
.fr-radio-group.fr-radio-rich
Expand Down

0 comments on commit 50a161d

Please sign in to comment.