mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-05-31 00:41:20 +00:00
Purged git history and removed sensitive information.
This commit is contained in:
commit
6bcc8dc76b
862 changed files with 25312 additions and 0 deletions
50
app/models/comment.rb
Normal file
50
app/models/comment.rb
Normal file
|
@ -0,0 +1,50 @@
|
|||
require 'rbbcode'
|
||||
|
||||
class Comment < ActiveRecord::Base
|
||||
include Extra
|
||||
|
||||
attr_protected :id, :updated_at, :created_at, :user_id
|
||||
|
||||
scope :with_userteam, :include => {:user => :team}
|
||||
scope :recent, :order => "id DESC", :limit => 10
|
||||
scope :recent3, :order => "id DESC", :limit => 3
|
||||
scope :recent5, :order => "id DESC", :limit => 5, :group => "commentable_id, commentable_type"
|
||||
scope :filtered, :conditions => ["commentable_type != 'Issue'"]
|
||||
scope :ordered, :order => "id ASC"
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :commentable, :polymorphic => true
|
||||
|
||||
validates_presence_of :commentable, :user
|
||||
validates_length_of :text, :in => 1..10000
|
||||
|
||||
before_save :parse_text
|
||||
|
||||
# acts_as_indexed :fields => [:text]
|
||||
|
||||
def parse_text
|
||||
self.text_parsed = RbbCode::Parser.new.parse(text)
|
||||
end
|
||||
|
||||
def after_create
|
||||
# if commentable_type == "Movie" or commentable_type == "Article" and commentable.user and commentable.user.profile.notify_own_stuff
|
||||
# Notifications.deliver_comments commentable.user, commentable
|
||||
# end
|
||||
end
|
||||
|
||||
def can_create? cuser
|
||||
return false unless cuser
|
||||
#errors.add_to_base I18n.t(:comments_locked) if !commentable.lock.nil? and commentable.lock
|
||||
errors.add_to_base I18n.t(:bans_mute) if cuser.banned? Ban::TYPE_MUTE
|
||||
errors.add_to_base I18n.t(:registered_for_week) unless cuser.verified?
|
||||
return errors.count == 0
|
||||
end
|
||||
|
||||
def can_update? cuser
|
||||
cuser and user == cuser or cuser.admin?
|
||||
end
|
||||
|
||||
def can_destroy? cuser
|
||||
cuser and cuser.admin?
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue