FIX: Prevent from creation of duplicated TopicAllowedUsers (#8169)

Ensure that we don't try to create duplicated TopicAllowedUsers

Related to https://meta.discourse.org/t/error-message-topic-allowed-users-is-invalid/130382/5

Spec amended to cover a case creating an overlap.
This commit is contained in:
Krzysztof Kotlarek 2019-10-11 17:44:29 +11:00 committed by Sam
parent 5c5845f3f2
commit 694a5bf229
2 changed files with 2 additions and 1 deletions

View File

@ -81,6 +81,7 @@ class TopicConverter
user.user_stat.save!
end
@topic.topic_allowed_users.build(user_id: @user.id) unless @topic.topic_allowed_users.where(user_id: @user.id).exists?
@topic.topic_allowed_users = @topic.topic_allowed_users.uniq(&:user_id)
# update topics count
@topic.user.user_stat.topic_count -= 1
@topic.user.user_stat.save!

View File

@ -114,7 +114,7 @@ describe TopicConverter do
context 'success' do
it "converts regular topic to private message" do
private_message = topic.convert_to_private_message(admin)
private_message = topic.convert_to_private_message(post.user)
expect(private_message).to be_valid
expect(topic.archetype).to eq("private_message")
expect(topic.category_id).to eq(nil)