Module: MuckComments::Models::MuckComment

Extended by:
ActiveSupport::Concern
Defined in:
lib/muck-comments/models/comment.rb

Instance Method Summary collapse

Instance Method Details

#after_createObject

Send an email to everyone in the thread



26
27
28
# File 'lib/muck-comments/models/comment.rb', line 26

def after_create
  CommentMailer.new_comment(self).deliver if MuckComments.configuration.send_email_for_new_comments
end

#can_edit?(user) ⇒ Boolean

override this method to change the way permissions are handled on comments

Returns:

  • (Boolean)


36
37
38
39
# File 'lib/muck-comments/models/comment.rb', line 36

def can_edit?(user)
  return true if check_user(user)
  false
end

#has_children?Boolean

helper method to check if a comment has children

Returns:

  • (Boolean)


31
32
33
# File 'lib/muck-comments/models/comment.rb', line 31

def has_children?
  self.children.size > 0 
end

#sanitize_attributesObject

Sanitize content before saving. This prevent XSS attacks and other malicious html.



42
43
44
45
46
# File 'lib/muck-comments/models/comment.rb', line 42

def sanitize_attributes
  if self.sanitize_level
    self.body = Sanitize.clean(self.body, self.sanitize_level)
  end
end

#sanitize_levelObject

Override this method to control sanitization levels. Currently a user who is an admin will not have their content sanitized. A user in any role ‘editor’, ‘manager’, or ‘contributor’ will be given the ‘RELAXED’ settings while all other users will get ‘BASIC’.

By default the ‘creator’ of the content will be used to determine which level of sanitization is allowed. To change this set ‘current_editor’ before

Options are from sanitze: nil - no sanitize Sanitize::Config::RELAXED Sanitize::Config::BASIC Sanitize::Config::RESTRICTED for more details see: rgrove.github.com/sanitize/



62
63
64
65
66
67
# File 'lib/muck-comments/models/comment.rb', line 62

def sanitize_level
  return Sanitize::Config::BASIC if self.user.nil?
  return nil if self.user.admin?
  return Sanitize::Config::RELAXED if self.user.any_role?('editor', 'manager', 'contributor')
  Sanitize::Config::BASIC
end