handle ignored author on receive
This commit is contained in:
parent
53e14dd2d6
commit
97f4b0c2e4
4 changed files with 31 additions and 22 deletions
|
|
@ -19,6 +19,7 @@ module Workers
|
|||
DiasporaFederation::Salmon::InvalidSignature,
|
||||
DiasporaFederation::Salmon::InvalidAlgorithm,
|
||||
DiasporaFederation::Salmon::InvalidEncoding,
|
||||
Diaspora::Federation::AuthorIgnored,
|
||||
# TODO: deprecated
|
||||
DiasporaFederation::Salmon::MissingMagicEnvelope,
|
||||
DiasporaFederation::Salmon::MissingAuthor,
|
||||
|
|
@ -27,10 +28,7 @@ module Workers
|
|||
logger.warn "don't retry for error: #{e.class}"
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
logger.warn "failed to save received object: #{e.record.errors.full_messages}"
|
||||
raise e unless [
|
||||
"already been taken",
|
||||
"is ignored by the post author"
|
||||
].any? {|reason| e.message.include? reason }
|
||||
raise e unless e.message.include? "already been taken"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,6 +4,10 @@ module Diaspora
|
|||
def self.xml(entity)
|
||||
DiasporaFederation::Salmon::XmlPayload.pack(entity)
|
||||
end
|
||||
|
||||
# Raised, if author is ignored by the relayable parent author
|
||||
class AuthorIgnored < RuntimeError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,7 @@ module Diaspora
|
|||
created_at: entity.created_at,
|
||||
text: entity.text,
|
||||
commentable: Post.find_by(guid: entity.parent_guid)
|
||||
).tap do |comment|
|
||||
comment.author_signature = entity.author_signature if comment.parent.author.local?
|
||||
comment.save!
|
||||
end
|
||||
).tap {|comment| save_relayable(comment, entity) }
|
||||
end
|
||||
|
||||
def self.contact(entity)
|
||||
|
|
@ -52,10 +49,7 @@ module Diaspora
|
|||
guid: entity.guid,
|
||||
positive: entity.positive,
|
||||
target: entity.parent_type.constantize.find_by(guid: entity.parent_guid)
|
||||
).tap do |like|
|
||||
like.author_signature = entity.author_signature if like.parent.author.local?
|
||||
like.save!
|
||||
end
|
||||
).tap {|like| save_relayable(like, entity) }
|
||||
end
|
||||
|
||||
def self.message(entity)
|
||||
|
|
@ -85,8 +79,8 @@ module Diaspora
|
|||
poll: Poll.find_by(guid: entity.parent_guid)
|
||||
).tap do |poll_participation|
|
||||
poll_participation.poll_answer_guid = entity.poll_answer_guid
|
||||
poll_participation.author_signature = entity.author_signature if poll_participation.parent.author.local?
|
||||
poll_participation.save!
|
||||
|
||||
save_relayable(poll_participation, entity)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -170,6 +164,22 @@ module Diaspora
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.save_relayable(relayable, entity)
|
||||
retract_if_author_ignored(relayable)
|
||||
|
||||
relayable.author_signature = entity.author_signature if relayable.parent.author.local?
|
||||
relayable.save!
|
||||
end
|
||||
|
||||
def self.retract_if_author_ignored(relayable)
|
||||
parent_author = relayable.parent.author
|
||||
return unless parent_author.local? && parent_author.owner.ignored_people.include?(relayable.author)
|
||||
|
||||
# TODO: send retraction
|
||||
|
||||
raise Diaspora::Federation::AuthorIgnored
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -30,15 +30,12 @@ module Diaspora
|
|||
end
|
||||
|
||||
def author_is_not_ignored
|
||||
if self.new_record? && self.parent.present?
|
||||
post_author = self.parent.author
|
||||
relayable_author = self.author
|
||||
unless new_record? && parent.present? && parent.author.local? &&
|
||||
parent.author.owner.ignored_people.include?(author)
|
||||
return
|
||||
end
|
||||
|
||||
if post_author.local? && post_author.owner.ignored_people.include?(relayable_author)
|
||||
self.errors.add(:author_id, 'This person is ignored by the post author')
|
||||
#post_author.owner.retract(self)
|
||||
end
|
||||
end
|
||||
errors.add(:author_id, "This relayable author is ignored by the post author")
|
||||
end
|
||||
|
||||
# @return [Boolean] true
|
||||
|
|
|
|||
Loading…
Reference in a new issue