mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-03-13 16:49:58 +01:00
Remove report method from User model
This commit is contained in:
parent
ae02840c69
commit
fa1d09ec44
2 changed files with 7 additions and 16 deletions
|
@ -148,21 +148,6 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
def admin? = has_cached_role?(:administrator)
|
def admin? = has_cached_role?(:administrator)
|
||||||
|
|
||||||
# region stuff used for reporting/moderation
|
|
||||||
def report(object, reason = nil)
|
|
||||||
target_user = if object.instance_of?(::User)
|
|
||||||
object
|
|
||||||
elsif object.respond_to? :user
|
|
||||||
object.user
|
|
||||||
end
|
|
||||||
|
|
||||||
existing = Report.find_by(type: "Reports::#{object.class}", target_id: object.id, user_id: id, target_user_id: target_user&.id, resolved: false)
|
|
||||||
if existing.nil?
|
|
||||||
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: id, target_user_id: target_user&.id, reason:)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
# endregion
|
|
||||||
|
|
||||||
def can_export?
|
def can_export?
|
||||||
return (Time.zone.now > export_created_at.in(1.week)) && !export_processing unless export_created_at.nil?
|
return (Time.zone.now > export_created_at.in(1.week)) && !export_processing unless export_created_at.nil?
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,13 @@ RSpec.describe User, type: :model do
|
||||||
describe "before_destroy" do
|
describe "before_destroy" do
|
||||||
it "marks reports about this user as deleted" do
|
it "marks reports about this user as deleted" do
|
||||||
other_user = FactoryBot.create(:user)
|
other_user = FactoryBot.create(:user)
|
||||||
other_user.report me, "va tutto benissimo"
|
|
||||||
|
UseCase::Report::Create.call(
|
||||||
|
reporter_id: other_user.id,
|
||||||
|
object_id: me.screen_name,
|
||||||
|
object_type: "User",
|
||||||
|
reason: "va tutto benissimo",
|
||||||
|
)
|
||||||
|
|
||||||
expect { me.destroy }
|
expect { me.destroy }
|
||||||
.to change { Reports::User.find_by(target_id: me.id).resolved? }
|
.to change { Reports::User.find_by(target_id: me.id).resolved? }
|
||||||
|
|
Loading…
Reference in a new issue