Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create new policy for palace invite updates #2509

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/controllers/concerns/palace_attendees_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ def new
invite = PalaceInvite.find(params[:palace_invite_id])
@enable_edition = true
@form_answer = invite.form_answer
authorize @form_answer, :update?
authorize invite, :update?
palace_attendee = invite.palace_attendees.build
render_attendee_form(palace_attendee, invite)
end

def create
authorize form_answer, :update?
authorize palace_invite, :update?
limit = palace_invite.attendees_limit
if palace_invite.palace_attendees.count < limit
palace_attendee = palace_invite.palace_attendees.create(create_params)
Expand All @@ -21,15 +21,15 @@ def create
end

def update
authorize form_answer, :update?
authorize palace_invite, :update?

palace_attendee = palace_invite.palace_attendees.find(params[:id])
log_event if palace_attendee.update(create_params)
render_attendee_form(palace_attendee, palace_invite)
end

def destroy
authorize form_answer, :update?
authorize palace_invite, :update?
palace_attendee = palace_invite.palace_attendees.find(params[:id])
log_event if palace_attendee.destroy
respond_to do |format|
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/concerns/palace_invites_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module PalaceInvitesMixin
def submit
@invite = PalaceInvite.find(params[:id])
authorize @invite.form_answer, :update?
authorize @invite, :update?

@invite.submit!

Expand Down
6 changes: 6 additions & 0 deletions app/policies/palace_invite_policy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class PalaceInvitePolicy < ApplicationPolicy
def update?
admin? ||
subject.lead_or_assigned?(record.form_answer)
end
end