Appease the dog overlords

This commit is contained in:
Karina Kwiatek 2022-06-12 13:46:48 +02:00 committed by Karina Kwiatek
parent 9b5fefc661
commit 04243c2ec8
5 changed files with 27 additions and 9 deletions

View File

@ -1,4 +1,6 @@
require 'errors' # frozen_string_literal: true
require "errors"
class Ajax::QuestionController < AjaxController class Ajax::QuestionController < AjaxController
def destroy def destroy
@ -72,9 +74,11 @@ class Ajax::QuestionController < AjaxController
return return
end end
# rubocop:disable Style/IfUnlessModifier
unless MuteRule.where(user: target_user).any? { |rule| rule.applies_to? question } unless MuteRule.where(user: target_user).any? { |rule| rule.applies_to? question }
Inbox.create!(user_id: target_user.id, question_id: question.id, new: true) Inbox.create!(user_id: target_user.id, question_id: question.id, new: true)
end end
# rubocop:enable Style/IfUnlessModifier
end end
@response[:status] = :okay @response[:status] = :okay

View File

@ -106,8 +106,10 @@ class User < ApplicationRecord
# @param question [Question] the question to answer # @param question [Question] the question to answer
# @param content [String] the answer content # @param content [String] the answer content
def answer(question, content) def answer(question, content)
# rubocop:disable Style/RedundantSelf
raise Errors::AnsweringOtherBlockedSelf if question.user.blocking?(self) raise Errors::AnsweringOtherBlockedSelf if question.user.blocking?(self)
raise Errors::AnsweringSelfBlockedOther if self.blocking?(question.user) raise Errors::AnsweringSelfBlockedOther if self.blocking?(question.user)
# rubocop:enable Style/RedundantSelf
Answer.create!(content: content, Answer.create!(content: content,
user: self, user: self,
@ -123,8 +125,10 @@ class User < ApplicationRecord
# smiles an answer # smiles an answer
# @param answer [Answer] the answer to smile # @param answer [Answer] the answer to smile
def smile(answer) def smile(answer)
# rubocop:disable Style/RedundantSelf
raise Errors::ReactingSelfBlockedOther if self.blocking?(answer.user) raise Errors::ReactingSelfBlockedOther if self.blocking?(answer.user)
raise Errors::ReactingOtherBlockedSelf if answer.user.blocking?(self) raise Errors::ReactingOtherBlockedSelf if answer.user.blocking?(self)
# rubocop:enable Style/RedundantSelf
Smile.create!(user: self, answer: answer) Smile.create!(user: self, answer: answer)
end end
@ -156,8 +160,10 @@ class User < ApplicationRecord
end end
def comment(answer, content) def comment(answer, content)
# rubocop:disable Style/RedundantSelf
raise Errors::CommentingSelfBlockedOther if self.blocking?(answer.user) raise Errors::CommentingSelfBlockedOther if self.blocking?(answer.user)
raise Errors::CommentingOtherBlockedSelf if answer.user.blocking?(self) raise Errors::CommentingOtherBlockedSelf if answer.user.blocking?(self)
# rubocop:enable Style/RedundantSelf
Comment.create!(user: self, answer: answer, content: content) Comment.create!(user: self, answer: answer, content: content)
end end

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
require 'errors' require "errors"
class User class User
module Relationship module Relationship
@ -22,11 +22,7 @@ class User
def block(target_user) def block(target_user)
raise Errors::BlockingSelf if target_user == self raise Errors::BlockingSelf if target_user == self
unfollow(target_user) if following?(target_user) unfollow_and_remove(target_user)
target_user.unfollow(self) if target_user.following?(self)
target_user.inboxes.joins(:question).where(question: { user_id: id }).destroy_all
inboxes.joins(:question).where(questions: { user_id: target_user.id, author_is_anonymous: false }).destroy_all
ListMember.joins(:list).where(list: { user_id: target_user.id }, user_id: id).destroy_all
create_relationship(active_block_relationships, target_user) create_relationship(active_block_relationships, target_user)
end end
@ -39,6 +35,16 @@ class User
def blocking?(target_user) def blocking?(target_user)
relationship_active?(blocked_users, target_user) relationship_active?(blocked_users, target_user)
end end
private
def unfollow_and_remove(target_user)
unfollow(target_user) if following?(target_user)
target_user.unfollow(self) if target_user.following?(self)
target_user.inboxes.joins(:question).where(question: { user_id: id }).destroy_all
inboxes.joins(:question).where(questions: { user_id: target_user.id, author_is_anonymous: false }).destroy_all
ListMember.joins(:list).where(list: { user_id: target_user.id }, user_id: id).destroy_all
end
end end
end end
end end

View File

@ -21,8 +21,10 @@ class User
# Follow an user # Follow an user
def follow(target_user) def follow(target_user)
raise Errors::FollowingSelf if target_user == self raise Errors::FollowingSelf if target_user == self
# rubocop:disable Style/RedundantSelf
raise Errors::FollowingOtherBlockedSelf if target_user.blocking?(self) raise Errors::FollowingOtherBlockedSelf if target_user.blocking?(self)
raise Errors::FollowingSelfBlockedOther if self.blocking?(target_user) raise Errors::FollowingSelfBlockedOther if self.blocking?(target_user)
# rubocop:enable Style/RedundantSelf
create_relationship(active_follow_relationships, target_user) create_relationship(active_follow_relationships, target_user)
end end