Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c716972
Remove special case notifying author of threads
MoshiKoi Apr 21, 2023
f0f5555
Fix duplicate ThreadFollowers
MoshiKoi May 17, 2023
6565b7c
Merge branch 'develop' into issue-1025
Taeir Nov 12, 2023
71c59f2
Merge branch 'develop' into issue-1025
trichoplax Mar 3, 2025
7d89490
Merge pull request #1037 from MoshiKoi/issue-1025
trichoplax Mar 3, 2025
21e5500
Remove now redundant private label
trichoplax Mar 3, 2025
2dc9035
Move followed_by? method to post model to simplify calling
trichoplax Mar 5, 2025
b3a17b9
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Mar 5, 2025
11f7e25
Split post_follow method to avoid toggling if called twice
trichoplax Mar 6, 2025
791ade7
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Mar 6, 2025
7b4f1ad
Allow follow/unfollow new threads on a locked post
trichoplax Mar 6, 2025
acbb325
Prevent adding a new comment thread to a locked post
trichoplax Mar 6, 2025
0696dff
Remove redundant check for admin (covered by moderator)
trichoplax Mar 6, 2025
a6fe076
Hide 'Start new comment thread' button when not permitted
trichoplax Mar 6, 2025
4ce1002
Tidy up tangled if blocks to keep like with like
trichoplax Mar 6, 2025
b0bc5bc
Allow moderators to reply to a restricted comment thread
trichoplax Mar 6, 2025
48198db
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Mar 6, 2025
39c31de
Add href to make anchor usable with system tests
trichoplax Mar 22, 2025
9a70236
Add labels to preferences for accessibility and to allow system tests
trichoplax Mar 22, 2025
0c39928
Add system tests for thread following
trichoplax Mar 22, 2025
9e6b0c3
Merge branch 'MoshiKoi/1025/remove-special-case-notifying-author-of-t…
trichoplax Mar 22, 2025
df9a153
Remove blank lines for rubocop
trichoplax Mar 22, 2025
9036feb
Make user a follower of their own post to fix test
trichoplax Mar 22, 2025
587644f
Add user to avoid confusing filter behaviour in tests
trichoplax Mar 22, 2025
2809664
Use standard user for tests now that filters are removed
trichoplax Mar 22, 2025
920deaa
Reassign overlooked filter defaults to filters_user for tests
trichoplax Mar 22, 2025
9512857
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Mar 22, 2025
a907b16
Add asserts to see if it lets CI system tests pass
trichoplax Mar 23, 2025
9d418a8
Attempt to fix system test timing problem
trichoplax Mar 23, 2025
3c15525
Add temporary system tests to analyse CI failures
trichoplax Mar 23, 2025
463cada
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Jun 13, 2025
2bb94a0
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Jun 13, 2025
56e042a
Add missing parentheses for Rubocop
trichoplax Jun 13, 2025
812260f
Improve notes to moderators on read only threads
trichoplax Jun 13, 2025
5a604b3
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Jun 17, 2025
5393736
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Jul 17, 2025
2580452
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Jul 17, 2025
e098faf
Add Participate ability for newly added fixture user
trichoplax Jul 19, 2025
36b7eec
Add Participate Everywhere ability for new filters user to fix test
trichoplax Jul 24, 2025
83d5e78
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
Oaphi Aug 14, 2025
abc5505
Remove attempts at system tests until underlying problems are fixed
trichoplax Aug 15, 2025
229efcb
Replace accidentally removed end from test class
trichoplax Aug 15, 2025
506e82b
Remove unnecessary change in otherwise untouched file
trichoplax Aug 15, 2025
e2a5342
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Aug 16, 2025
4341e29
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Aug 16, 2025
a4d096c
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Aug 18, 2025
7846110
Add tests after removing thread following special case for post author
trichoplax Aug 18, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# rubocop:disable Metrics/ClassLength
# Provides mainly web actions for using and making comments.
class CommentsController < ApplicationController
before_action :authenticate_user!, except: [:post, :show, :thread, :thread_content]
Expand All @@ -16,7 +15,7 @@ class CommentsController < ApplicationController
before_action :check_restrict_access, only: [:thread_restrict]
before_action :check_thread_access, only: [:thread, :thread_content, :thread_followers]
before_action :check_unrestrict_access, only: [:thread_unrestrict]
before_action :check_if_target_post_locked, only: [:create, :post_follow]
before_action :check_if_target_post_locked, only: [:create, :create_thread]
before_action :check_if_parent_post_locked, only: [:update, :destroy]

def create_thread
Expand Down Expand Up @@ -46,12 +45,9 @@ def create_thread

if success
notification = "New comment thread on #{@comment.root.title}: #{@comment_thread.title}"
unless @comment.post.user == current_user
@comment.post.user.create_notification(notification, helpers.comment_link(@comment))
end

ThreadFollower.where(post: @post).each do |tf|
unless tf.user == current_user || tf.user == @comment.post.user
unless tf.user == current_user
tf.user.create_notification(notification, helpers.comment_link(@comment))
end
ThreadFollower.create(user: tf.user, comment_thread: @comment_thread)
Expand Down Expand Up @@ -253,8 +249,7 @@ def thread_unrestrict
end
@comment_thread.update(deleted: false, deleted_by: nil)
when 'follow'
tf = ThreadFollower.find_by(comment_thread: @comment_thread, user: current_user)
tf&.destroy
ThreadFollower.where(comment_thread: @comment_thread, user: current_user).destroy_all
else
return not_found!
end
Expand Down Expand Up @@ -428,4 +423,3 @@ def audit(event_type, comment, audit_comment = '')
user: current_user)
end
end
# rubocop:enable Metrics/ClassLength
1 change: 1 addition & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def create

if @post.save
@post.update(last_activity: @post.created_at, last_activity_by: current_user)
ThreadFollower.create user: @post.user, post: @post
if @post_type.has_parent?
unless @post.user_id == @post.parent.user_id
@post.parent.user.create_notification("New response to your post #{@post.parent.title}",
Expand Down
13 changes: 0 additions & 13 deletions app/models/comment_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ class CommentThread < ApplicationRecord
validate :maximum_title_length
validates :title, presence: { message: I18n.t('comments.errors.title_presence') }

after_create :create_follower

# Gets threads appropriately scoped for a given user & post
# @param user [User, nil] user to check
# @para post [Post] post to check
Expand Down Expand Up @@ -78,15 +76,4 @@ def maximum_title_length
errors.add(:title, "can't be more than #{max_len} characters")
end
end

private

# Comment author and post author are automatically followed to the thread. Question author is NOT
# automatically followed on new answer comment threads. Comment author follower creation is done
# on the Comment model.
def create_follower
if post.user.preference('auto_follow_comment_threads') == 'true'
ThreadFollower.create comment_thread: self, user: post.user
end
end
end
21 changes: 21 additions & 0 deletions test/controllers/comments/post_follow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,25 @@ class CommentsControllerTest < ActionController::TestCase
# Assert user still only follows post once
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
end

test 'post author can unfollow post then follow' do
user = users(:standard_user)
sign_in user
question = posts(:question_one)

# Assert user follows post
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count

try_post_unfollow(question)
assert_response(:found)

# Assert user does not follow post
assert_equal 0, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count

try_post_follow(question)
assert_response(:found)

# Assert user follows post
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count
end
end
10 changes: 10 additions & 0 deletions test/controllers/posts/create_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ class PostsControllerTest < ActionController::TestCase
assert_redirected_to_sign_in
end

test 'should make post author a thread follower of the post' do
user = users(:standard_user)
sign_in user
try_create_post
assert_response(:found)

# Assert user follows post
assert_equal 1, ThreadFollower.where(['post_id = ? AND user_id = ?', assigns(:post), user]).count
end

private

# Attempts to create a post
Expand Down