FEATURE: Can create warnings for users via PM

This commit is contained in:
Robin Ward
2014-09-05 15:40:25 -04:00
parent a8e4c4caa1
commit b0bfc1f93f
37 changed files with 243 additions and 18 deletions

View File

@ -98,7 +98,7 @@ class Notification < ActiveRecord::Base
def self.recent_report(user, count = nil)
count ||= 10
notifications = user.notifications.recent(count).includes(:topic).to_a
notifications = user.notifications.recent(count).includes({:topic => :warning}).to_a
if notifications.present?
notifications += user.notifications

View File

@ -100,6 +100,7 @@ class Topic < ActiveRecord::Base
has_many :invites, through: :topic_invites, source: :invite
has_many :revisions, foreign_key: :topic_id, class_name: 'TopicRevision'
has_one :warning
# When we want to temporarily attach some data to a forum topic (usually before serialization)
attr_accessor :user_data

View File

@ -35,6 +35,7 @@ class User < ActiveRecord::Base
has_many :invites, dependent: :destroy
has_many :topic_links, dependent: :destroy
has_many :uploads
has_many :warnings
has_one :user_avatar, dependent: :destroy
has_one :facebook_user_info, dependent: :destroy
@ -393,6 +394,10 @@ class User < ActiveRecord::Base
PostAction.where(user_id: id, post_action_type_id: PostActionType.flag_types.values).count
end
def warnings_received_count
warnings.count
end
def flags_received_count
posts.includes(:post_actions).where('post_actions.post_action_type_id' => PostActionType.flag_types.values).count
end

5
app/models/warning.rb Normal file
View File

@ -0,0 +1,5 @@
class Warning < ActiveRecord::Base
belongs_to :user
belongs_to :topic
belongs_to :created_by, class_name: 'User'
end