FIX: admins could never remove self from messages

This commit is contained in:
Sam 2017-05-16 16:06:24 -04:00
parent 6ddd8d9166
commit 4b449914b8
2 changed files with 16 additions and 1 deletions

View File

@ -698,6 +698,9 @@ SQL
topic_user = topic_allowed_users.find_by(user_id: user.id)
if topic_user
topic_user.destroy
# we can not remove ourselves cause then we will end up adding
# ourselves in add_small_action
removed_by = Discourse.system_user if user.id == removed_by.id
add_small_action(removed_by, "removed_user", user.username)
return true
end

View File

@ -1134,9 +1134,21 @@ describe TopicsController do
xhr :put, :make_banner, topic_id: topic.id
expect(response).to be_success
end
end
end
describe 'remove_allowed_user' do
it 'admin can be removed from a pm' do
admin = log_in :admin
user = Fabricate(:user)
pm = create_post(user: user, archetype: 'private_message', target_usernames: [user.username, admin.username])
xhr :put, :remove_allowed_user, topic_id: pm.topic_id, username: admin.username
expect(response.status).to eq(200)
expect(TopicAllowedUser.where(topic_id: pm.topic_id, user_id: admin.id).first).to eq(nil)
end
end
describe 'remove_banner' do