Skip to content

Commit

Permalink
add validation to avoid petitions between the same user and organization
Browse files Browse the repository at this point in the history
  • Loading branch information
markets committed Jan 3, 2025
1 parent 0ecec0f commit e9690bc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/controllers/petitions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def create

flash[:notice] = t('petitions.application_status', status: t("petitions.status.sent"))
else
flash[:error] = t('errors.internal_server_error.description')
flash[:error] = petition.errors.full_messages.to_sentence
end

redirect_back fallback_location: organization_path(petition.organization)
Expand All @@ -25,7 +25,7 @@ def update
petition.user.add_to_organization(petition.organization) if status == 'accepted'
flash[:notice] = t('petitions.application_status', status: t("petitions.status.#{status}"))
else
flash[:error] = t('errors.internal_server_error.description')
flash[:error] = petition.errors.full_messages.to_sentence
end

redirect_to manage_petitions_path
Expand Down
2 changes: 2 additions & 0 deletions app/models/petition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ class Petition < ApplicationRecord

belongs_to :user
belongs_to :organization

validates :user_id, uniqueness: { scope: :organization_id }
end

0 comments on commit e9690bc

Please sign in to comment.