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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user