Class: Commontator::Comment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Commontator::Comment
- Defined in:
- app/models/commontator/comment.rb
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
-
#can_be_created_by?(user) ⇒ Boolean
Access Control #.
- #can_be_deleted_by?(user) ⇒ Boolean
- #can_be_edited_by?(user) ⇒ Boolean
- #can_be_voted_on? ⇒ Boolean
- #can_be_voted_on_by?(user) ⇒ Boolean
- #created_timestamp ⇒ Object
- #delete_by(user) ⇒ Object
- #get_vote_by(user) ⇒ Object
- #is_deleted? ⇒ Boolean
- #is_latest? ⇒ Boolean
- #is_modified? ⇒ Boolean
- #undelete_by(user) ⇒ Object
- #update_cached_votes(vote_scope = nil) ⇒ Object
- #updated_timestamp ⇒ Object
Class Method Details
.is_votable? ⇒ Boolean
25 26 27 |
# File 'app/models/commontator/comment.rb', line 25 def self.is_votable? is_votable end |
Instance Method Details
#body ⇒ Object
69 70 71 72 73 |
# File 'app/models/commontator/comment.rb', line 69 def body is_deleted? ? I18n.t( 'commontator.comment.status.deleted_by', deleter_name: Commontator.commontator_name(editor) ) : super end |
#can_be_created_by?(user) ⇒ Boolean
Access Control #
90 91 92 93 |
# File 'app/models/commontator/comment.rb', line 90 def can_be_created_by?(user) user == creator && !user.nil? && user.is_commontator && !thread.is_closed? && thread.can_be_read_by?(user) end |
#can_be_deleted_by?(user) ⇒ Boolean
104 105 106 107 108 109 110 111 |
# File 'app/models/commontator/comment.rb', line 104 def can_be_deleted_by?(user) mod_perm = thread.config..to_sym return true if thread.can_be_edited_by?(user) && (mod_perm == :e || mod_perm == :d) comment_del = thread.config.comment_deletion.to_sym !thread.is_closed? && user == creator && (!is_deleted? || editor == user) && comment_del != :n && (is_latest? || comment_del == :a) && thread.can_be_read_by?(user) end |
#can_be_edited_by?(user) ⇒ Boolean
95 96 97 98 99 100 101 102 |
# File 'app/models/commontator/comment.rb', line 95 def can_be_edited_by?(user) return true if thread.can_be_edited_by?(user) && thread.config..to_sym == :e comment_edit = thread.config.comment_editing.to_sym !thread.is_closed? && !is_deleted? && user == creator && (editor.nil? || user == editor) && comment_edit != :n && (is_latest? || comment_edit == :a) && thread.can_be_read_by?(user) end |
#can_be_voted_on? ⇒ Boolean
113 114 115 |
# File 'app/models/commontator/comment.rb', line 113 def can_be_voted_on? !thread.is_closed? && !is_deleted? && thread.is_votable? && self.class.is_votable? end |
#can_be_voted_on_by?(user) ⇒ Boolean
117 118 119 120 |
# File 'app/models/commontator/comment.rb', line 117 def can_be_voted_on_by?(user) !user.nil? && user.is_commontator && user != creator && thread.can_be_read_by?(user) && can_be_voted_on? end |
#created_timestamp ⇒ Object
75 76 77 78 |
# File 'app/models/commontator/comment.rb', line 75 def I18n.t 'commontator.comment.status.created_at', created_at: I18n.l(created_at, format: :commontator) end |
#delete_by(user) ⇒ Object
53 54 55 56 57 58 59 |
# File 'app/models/commontator/comment.rb', line 53 def delete_by(user) return false if is_deleted? self.deleted_at = Time.now self.editor = user self.save end |
#get_vote_by(user) ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/commontator/comment.rb', line 37 def get_vote_by(user) return nil unless self.class.is_votable? && !user.nil? && user.is_commontator # Preloaded with a condition in thread#nested_comments_for votes_for.to_a.find { |vote| vote.voter_id == user.id && vote.voter_type == user.class.name } end |
#is_deleted? ⇒ Boolean
49 50 51 |
# File 'app/models/commontator/comment.rb', line 49 def is_deleted? !deleted_at.nil? end |
#is_latest? ⇒ Boolean
33 34 35 |
# File 'app/models/commontator/comment.rb', line 33 def is_latest? thread.latest_comment(false) == self end |
#is_modified? ⇒ Boolean
29 30 31 |
# File 'app/models/commontator/comment.rb', line 29 def is_modified? !editor.nil? end |
#undelete_by(user) ⇒ Object
61 62 63 64 65 66 67 |
# File 'app/models/commontator/comment.rb', line 61 def undelete_by(user) return false unless is_deleted? self.deleted_at = nil self.editor = user self.save end |
#update_cached_votes(vote_scope = nil) ⇒ Object
44 45 46 47 |
# File 'app/models/commontator/comment.rb', line 44 def update_cached_votes(vote_scope = nil) self.update_column(:cached_votes_up, count_votes_up(true)) self.update_column(:cached_votes_down, count_votes_down(true)) end |
#updated_timestamp ⇒ Object
80 81 82 83 84 |
# File 'app/models/commontator/comment.rb', line 80 def I18n.t 'commontator.comment.status.updated_at', editor_name: Commontator.commontator_name(editor || creator), updated_at: I18n.l(updated_at, format: :commontator) end |