0
0
Fork 0

Fix various edge cases with local moves (#24812)

This commit is contained in:
Claire 2023-05-03 19:19:25 +02:00 committed by GitHub
parent 1e75eb690d
commit a2a22bad23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 32 deletions

View file

@ -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