From b4e5037469ecc24b1ea664a4a07531e06b06df3e Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 9 Jun 2022 19:44:58 +0200 Subject: [PATCH] Disallow commenting when blocked by the answer's author --- app/models/user.rb | 3 +++ lib/errors.rb | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/app/models/user.rb b/app/models/user.rb index de4f37c2..6ae0b3cc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -150,6 +150,9 @@ class User < ApplicationRecord end def comment(answer, content) + raise Errors::CommentingSelfBlockedOther if self.blocking?(answer.user) + raise Errors::CommentingOtherBlockedSelf if answer.user.blocking?(self) + Comment.create!(user: self, answer: answer, content: content) end diff --git a/lib/errors.rb b/lib/errors.rb index ab7a8b7a..a56cb778 100644 --- a/lib/errors.rb +++ b/lib/errors.rb @@ -73,5 +73,11 @@ module Errors class AnsweringSelfBlockedOther < SelfBlockedOther end + + class CommentingSelfBlockedOther < SelfBlockedOther + end + + class CommentingOtherBlockedSelf < OtherBlockedSelf + end # endregion end