Derp x2 (Retrospring/bugs#41)
This commit is contained in:
parent
832dc1c1e4
commit
1c80c70dd9
|
@ -17,7 +17,7 @@ class Answer < ActiveRecord::Base
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
# mark a report as deleted if it exists
|
# mark a report as deleted if it exists
|
||||||
rep = Report.where(target_id: self.id, type: Reports::Answer)
|
rep = Report.where(target_id: self.id, type: 'Reports::Answer')
|
||||||
rep.each do |r|
|
rep.each do |r|
|
||||||
unless r.nil?
|
unless r.nil?
|
||||||
r.deleted = true
|
r.deleted = true
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Comment < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
rep = Report.where(target_id: self.id, type: Reports::Comment)
|
rep = Report.where(target_id: self.id, type: 'Reports::Comment')
|
||||||
rep.each do |r|
|
rep.each do |r|
|
||||||
unless r.nil?
|
unless r.nil?
|
||||||
r.deleted = true
|
r.deleted = true
|
||||||
|
|
|
@ -6,7 +6,7 @@ class Question < ActiveRecord::Base
|
||||||
validates :content, length: { maximum: 255 }
|
validates :content, length: { maximum: 255 }
|
||||||
|
|
||||||
before_destroy do
|
before_destroy do
|
||||||
rep = Report.where(target_id: self.id, type: Reports::Question)
|
rep = Report.where(target_id: self.id, type: 'Reports::Question')
|
||||||
rep.each do |r|
|
rep.each do |r|
|
||||||
unless r.nil?
|
unless r.nil?
|
||||||
r.deleted = true
|
r.deleted = true
|
||||||
|
|
|
@ -61,7 +61,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
# when a user deleted himself, all reports relating to the user are invalid
|
# when a user deleted himself, all reports relating to the user are invalid
|
||||||
before_destroy do
|
before_destroy do
|
||||||
rep = Report.where(target_id: self.id, type: Reports::User)
|
rep = Report.where(target_id: self.id, type: 'Reports::User')
|
||||||
rep.each do |r|
|
rep.each do |r|
|
||||||
unless r.nil?
|
unless r.nil?
|
||||||
r.deleted = true
|
r.deleted = true
|
||||||
|
@ -161,7 +161,7 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
# region stuff used for reporting/moderation
|
# region stuff used for reporting/moderation
|
||||||
def report(object, reason = nil)
|
def report(object, reason = nil)
|
||||||
existing = Report.find_by(target_id: object.id, user_id: self.id, deleted: false)
|
existing = Report.find_by(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id, deleted: false)
|
||||||
if existing.nil?
|
if existing.nil?
|
||||||
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id, reason: reason)
|
Report.create(type: "Reports::#{object.class}", target_id: object.id, user_id: self.id, reason: reason)
|
||||||
elsif not reason.nil? and reason.length > 0
|
elsif not reason.nil? and reason.length > 0
|
||||||
|
|
Loading…
Reference in New Issue