Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
07378a1
Merge branch 'develop' into MoshiKoi/1025/remove-special-case-notifyi…
trichoplax Feb 8, 2026
5de4162
Change ThreadFollower to NewThreadFollower following merge
trichoplax Feb 8, 2026
95d468f
Add migration to make post authors follow new threads
trichoplax Feb 8, 2026
7e2010d
Make auto follow comment threads preference description explicit
trichoplax Feb 12, 2026
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
7 changes: 2 additions & 5 deletions app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CommentsController < ApplicationController
before_action :check_lock_thread_access, only: [:lock_thread]
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]
before_action :verify_moderator, only: [:thread_followers]

Expand Down Expand Up @@ -56,12 +56,9 @@ def create_thread

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

NewThreadFollower.where(post: @post).each do |ntf|
unless ntf.user.same_as?(current_user) || ntf.user.same_as?(@comment.post.user)
unless ntf.user.same_as?(current_user)
ntf.user.create_notification(notification, helpers.comment_link(@comment))
end
ThreadFollower.create(user: ntf.user, comment_thread: @comment_thread)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def create

if @post.save
@post.update(last_activity: @post.created_at, last_activity_by: current_user)
NewThreadFollower.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

before_save :bump_last_activity

# Gets threads appropriately scoped for a given user & post
Expand Down Expand Up @@ -121,15 +119,4 @@ def remove_follower(user)

ThreadFollower.where(comment_thread: self, user: user).destroy_all.any?
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
2 changes: 1 addition & 1 deletion config/config/preferences.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ display_import_labels:
auto_follow_comment_threads:
type: boolean
description: >
Automatically follow any comment thread you participate in.
Automatically follow any comment thread you create or participate in.
default: 'true'
global: true

Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20260208223211_follow_own_posts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class FollowOwnPosts < ActiveRecord::Migration[7.2]
def change
to_insert = Post.where.not(post_type_id: [PolicyDoc.post_type_id, HelpDoc.post_type_id])
.where.not(user_id: nil)
.pluck(:id, :user_id)
.map { |post_id, user_id| { post_id: post_id, user_id: user_id } }

NewThreadFollower.insert_all(to_insert)
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, NewThreadFollower.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, NewThreadFollower.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, NewThreadFollower.where(['post_id = ? AND user_id = ?', question, user]).count

try_post_follow(question)
assert_response(:found)

# Assert user follows post
assert_equal 1, NewThreadFollower.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 @@ -132,6 +132,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, NewThreadFollower.where(['post_id = ? AND user_id = ?', assigns(:post), user]).count
end

private

# Attempts to create a post
Expand Down