mirror of
https://github.com/discourse/discourse.git
synced 2026-08-11 05:25:16 -05:00
FIX: Topic#invite_group failed to notify users on newly created topic (#12255)
When `PostCreator` creates a new topic it loads the `allowed_groups` of the topic. `Fabricate` doesn't do that and that's why the existing spec worked even though it should have failed, because `PostAlerter#notify_group_summary` didn't create a notification for a non-fabricated topic. `Topic#invite_group` added a new `TopicAllowedGroup` record without reloading `Topic.allowed_groups`. A subsequent call to `PostAlerter#notify_group_summary` didn't work because it didn't find the invited group in the topic's `allowed_groups` association.
This commit is contained in:
@@ -930,6 +930,7 @@ class Topic < ActiveRecord::Base
|
||||
group_user = topic_allowed_groups.find_by(group_id: group.id)
|
||||
if group_user
|
||||
group_user.destroy
|
||||
allowed_groups.reload
|
||||
add_small_action(removed_by, "removed_group", group.name)
|
||||
return true
|
||||
end
|
||||
@@ -968,6 +969,7 @@ class Topic < ActiveRecord::Base
|
||||
|
||||
def invite_group(user, group)
|
||||
TopicAllowedGroup.create!(topic_id: id, group_id: group.id)
|
||||
allowed_groups.reload
|
||||
|
||||
last_post = posts.order('post_number desc').where('not hidden AND posts.deleted_at IS NULL').first
|
||||
if last_post
|
||||
|
||||
Reference in New Issue
Block a user