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:
parent
5c5845f3f2
commit
694a5bf229
|
@ -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!
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue