journalduhacker/app/models/moderation.rb
chaica 9506b1ce10 I18n moderations (#301)
* translate moderation view, controller and model

* support for i18n in the moderation controller

* support for i18n in the moderation model - use interpolation for variables inside strings

* support for i18n in controller model - localize time and date string format for printing time and date of the moderation action
2016-07-05 10:02:14 -05:00

58 lines
1.7 KiB
Ruby

class Moderation < ActiveRecord::Base
belongs_to :moderator,
:class_name => "User",
:foreign_key => "moderator_user_id"
belongs_to :story
belongs_to :comment
belongs_to :user
after_create :send_message_to_moderated
def send_message_to_moderated
m = Message.new
m.author_user_id = self.moderator_user_id
# mark as deleted by author so they don't fill up moderator message boxes
m.deleted_by_author = true
if self.story
m.recipient_user_id = self.story.user_id
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}") <<
"\n" <<
"> *#{self.action}*\n"
if self.reason.present?
m.body << "\n" <<
I18n.t('models.moderation.reasongiven') <<
"\n" <<
"> *#{self.reason}*\n"
end
elsif self.comment
m.recipient_user_id = self.comment.user_id
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}") <<
"\n" <<
"> *#{self.comment.comment}*\n"
if self.reason.present?
m.body << "\n" <<
I18n.t('models.moderation.reasongiven') <<
"\n" <<
"> *#{self.reason}*\n"
end
else
# no point in alerting deleted users, they can't login to read it
return
end
m.body << "\n" <<
I18n.t('models.moderation.automatedmessage')
m.save
end
end