2012-09-02 16:50:07 +02:00
|
|
|
class Moderation < ActiveRecord::Base
|
|
|
|
belongs_to :moderator,
|
|
|
|
:class_name => "User",
|
|
|
|
:foreign_key => "moderator_user_id"
|
|
|
|
belongs_to :story
|
|
|
|
belongs_to :comment
|
|
|
|
belongs_to :user
|
|
|
|
|
2012-09-09 01:32:56 +02:00
|
|
|
after_create :send_message_to_moderated
|
|
|
|
|
|
|
|
def send_message_to_moderated
|
|
|
|
m = Message.new
|
|
|
|
m.author_user_id = self.moderator_user_id
|
|
|
|
|
2013-01-24 21:06:10 +01:00
|
|
|
# mark as deleted by author so they don't fill up moderator message boxes
|
|
|
|
m.deleted_by_author = true
|
|
|
|
|
2012-09-09 01:32:56 +02:00
|
|
|
if self.story
|
|
|
|
m.recipient_user_id = self.story.user_id
|
2016-07-05 17:02:14 +02:00
|
|
|
m.subject = I18n.t('models.moderation.storyeditedby') <<
|
|
|
|
(self.is_from_suggestions? ? I18n.t('models.moderation.usersuggestions') : I18n.t('models.moderation.amoderator'))
|
|
|
|
m.body = I18n.t('models.moderation.storyeditedfor', :title=> "#{self.story.title}", :url=> "#{self.story.comments_url}") <<
|
2012-09-09 01:32:56 +02:00
|
|
|
"\n" <<
|
|
|
|
"> *#{self.action}*\n"
|
|
|
|
|
|
|
|
if self.reason.present?
|
|
|
|
m.body << "\n" <<
|
2016-07-05 17:02:14 +02:00
|
|
|
I18n.t('models.moderation.reasongiven') <<
|
2012-09-09 01:32:56 +02:00
|
|
|
"\n" <<
|
2014-01-07 18:40:36 +01:00
|
|
|
"> *#{self.reason}*\n"
|
2012-09-09 01:32:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
elsif self.comment
|
|
|
|
m.recipient_user_id = self.comment.user_id
|
2016-07-05 17:02:14 +02:00
|
|
|
m.subject = I18n.t('models.moderation.commentmoderated')
|
|
|
|
m.body = I18n.t('models.moderation.commentmoderatedwhy', :title=> "#{self.comment.story.title}", :url=> "#{self.comment.story.comments_url}") <<
|
2012-09-09 01:32:56 +02:00
|
|
|
"\n" <<
|
2014-01-07 18:40:36 +01:00
|
|
|
"> *#{self.comment.comment}*\n"
|
2012-09-09 01:32:56 +02:00
|
|
|
|
|
|
|
if self.reason.present?
|
|
|
|
m.body << "\n" <<
|
2016-07-05 17:02:14 +02:00
|
|
|
I18n.t('models.moderation.reasongiven') <<
|
2012-09-09 01:32:56 +02:00
|
|
|
"\n" <<
|
2014-01-07 18:40:36 +01:00
|
|
|
"> *#{self.reason}*\n"
|
2012-09-09 01:32:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
else
|
|
|
|
# no point in alerting deleted users, they can't login to read it
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2014-01-07 18:40:36 +01:00
|
|
|
m.body << "\n" <<
|
2016-07-05 17:02:14 +02:00
|
|
|
I18n.t('models.moderation.automatedmessage')
|
2014-01-07 18:40:36 +01:00
|
|
|
|
2012-09-09 01:32:56 +02:00
|
|
|
m.save
|
|
|
|
end
|
2012-09-02 16:50:07 +02:00
|
|
|
end
|