chore: Add validations to campaign model

- Add validations to campaign model ensuring that the associated inbox belongs to one with in the campaign account.
This commit is contained in:
Shivam Mishra
2025-03-20 05:59:08 +05:30
committed by GitHub
parent cc8c05834a
commit 51ad80a61e
7 changed files with 60 additions and 24 deletions

View File

@@ -38,6 +38,7 @@ class Campaign < ApplicationRecord
validate :validate_url
validate :prevent_completed_campaign_from_update, on: :update
validate :sender_must_belong_to_account
validate :inbox_must_belong_to_account
belongs_to :account
belongs_to :inbox
@@ -92,6 +93,14 @@ class Campaign < ApplicationRecord
errors.add(:url, 'invalid') if inbox.inbox_type == 'Website' && !use_http_protocol
end
def inbox_must_belong_to_account
return unless inbox
return if inbox.account_id == account_id
errors.add(:inbox_id, 'must belong to the same account as the campaign')
end
def sender_must_belong_to_account
return unless sender