Fix various edge cases with local moves (#24812)
This commit is contained in:
parent
1e75eb690d
commit
a2a22bad23
4 changed files with 108 additions and 32 deletions
|
@ -18,6 +18,7 @@ class ListAccount < ApplicationRecord
|
|||
belongs_to :follow_request, optional: true
|
||||
|
||||
validates :account_id, uniqueness: { scope: :list_id }
|
||||
validate :validate_relationship
|
||||
|
||||
before_validation :set_follow
|
||||
|
||||
|
@ -30,4 +31,12 @@ class ListAccount < ApplicationRecord
|
|||
rescue ActiveRecord::RecordNotFound
|
||||
self.follow_request = FollowRequest.find_by!(account_id: list.account_id, target_account_id: account.id)
|
||||
end
|
||||
|
||||
def validate_relationship
|
||||
return if list.account_id == account_id
|
||||
|
||||
errors.add(:account_id, 'follow relationship missing') if follow_id.nil? && follow_request_id.nil?
|
||||
errors.add(:follow, 'mismatched accounts') if follow_id.present? && follow.target_account_id != account_id
|
||||
errors.add(:follow_request, 'mismatched accounts') if follow_request_id.present? && follow_request.target_account_id != account_id
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue