From b38ae50ba776c9782234a80ae36c57d8125ce82e Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Thu, 9 Jun 2022 19:49:24 +0200 Subject: [PATCH] Disallow reacting to an answer when blocked by its 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 6ae0b3cc..eac5f9f1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -120,6 +120,9 @@ class User < ApplicationRecord # smiles an answer # @param answer [Answer] the answer to smile def smile(answer) + raise Errors::ReactingSelfBlockedOther if self.blocking?(answer.user) + raise Errors::ReactingOtherBlockedSelf if answer.user.blocking?(self) + Smile.create!(user: self, answer: answer) end diff --git a/lib/errors.rb b/lib/errors.rb index a56cb778..b577491e 100644 --- a/lib/errors.rb +++ b/lib/errors.rb @@ -79,5 +79,11 @@ module Errors class CommentingOtherBlockedSelf < OtherBlockedSelf end + + class ReactingSelfBlockedOther < SelfBlockedOther + end + + class ReactingOtherBlockedSelf < OtherBlockedSelf + end # endregion end