@@ -11,6 +11,9 @@ class CommentThread < ApplicationRecord
1111 scope :publicly_available , -> { where ( deleted : false ) . where ( 'reply_count > 0' ) }
1212 scope :archived , -> { where ( archived : true ) }
1313
14+ validate :maximum_title_length
15+ validates :title , presence : { message : I18n . t ( 'comments.errors.title_presence' ) }
16+
1417 after_create :create_follower
1518
1619 def self . post_followed? ( post , user )
@@ -21,10 +24,16 @@ def read_only?
2124 locked? || archived? || deleted?
2225 end
2326
27+ # Is a given user a follower of the thread?
28+ # @param user [User] user to check
29+ # @return [Boolean] check result
2430 def followed_by? ( user )
2531 ThreadFollower . where ( comment_thread : self , user : user ) . any?
2632 end
2733
34+ # Does a given user have access to the thread?
35+ # @param user [User] user to check access for
36+ # @return [Boolean] check result
2837 def can_access? ( user )
2938 ( !deleted? || user &.privilege? ( 'flag_curate' ) || user &.post_privilege? ( 'flag_curate' , post ) ) &&
3039 post . can_access? ( user )
@@ -53,6 +62,13 @@ def pingable
5362 ActiveRecord ::Base . connection . execute ( query ) . to_a . flatten
5463 end
5564
65+ def maximum_title_length
66+ max_len = SiteSetting [ 'MaxThreadTitleLength' ] || 255
67+ if title . length > [ max_len , 255 ] . min
68+ errors . add ( :title , "can't be more than #{ max_len } characters" )
69+ end
70+ end
71+
5672 private
5773
5874 # Comment author and post author are automatically followed to the thread. Question author is NOT
0 commit comments