mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:09:00 +08:00
FIX: No small action created when a non-author removes itself from a PM (#20502)
Fixes a small issue where allowed user removes themselves from a private message before the post activity (small action) is created. I also added some test coverage to prevent regression. /t/92811
This commit is contained in:
parent
607c123d90
commit
96d03ea9c0
|
@ -1103,14 +1103,13 @@ class Topic < ActiveRecord::Base
|
|||
topic_user = topic_allowed_users.find_by(user_id: user.id)
|
||||
|
||||
if topic_user
|
||||
topic_user.destroy
|
||||
|
||||
if user.id == removed_by&.id
|
||||
add_small_action(removed_by, "user_left", user.username)
|
||||
else
|
||||
add_small_action(removed_by, "removed_user", user.username)
|
||||
end
|
||||
|
||||
topic_user.destroy
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3081,6 +3081,17 @@ RSpec.describe Topic do
|
|||
|
||||
describe "#remove_allowed_user" do
|
||||
fab!(:topic) { Fabricate(:topic) }
|
||||
fab!(:private_topic) do
|
||||
Fabricate(
|
||||
:private_message_topic,
|
||||
title: "Private message",
|
||||
user: admin,
|
||||
topic_allowed_users: [
|
||||
Fabricate.build(:topic_allowed_user, user: admin),
|
||||
Fabricate.build(:topic_allowed_user, user: user1),
|
||||
],
|
||||
)
|
||||
end
|
||||
|
||||
describe "removing oneself" do
|
||||
it "should remove onself" do
|
||||
|
@ -3095,6 +3106,12 @@ RSpec.describe Topic do
|
|||
expect(post.post_type).to eq(Post.types[:small_action])
|
||||
expect(post.action_code).to eq("user_left")
|
||||
end
|
||||
|
||||
it "should show a small action when user removes themselves from pm" do
|
||||
expect do private_topic.remove_allowed_user(user1, user1) end.to change {
|
||||
private_topic.posts.where(action_code: "user_left").count
|
||||
}.by(1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user