mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 09:34:41 +08:00
FIX: Ensure revoke_ungranted_titles! works with user_ids (#31371)
When `revoke_ungranted_titles!` was invoked, the optional list of `user_ids` was not passed from the argument list to the query. This resulted in an exception because the placeholder `:user_ids` existed in the query.
This commit is contained in:
@ -504,9 +504,7 @@ class BadgeGranter
|
||||
end
|
||||
|
||||
def self.revoke_ungranted_titles!(user_ids = nil)
|
||||
user_ids = user_ids.join(", ") if user_ids
|
||||
|
||||
DB.exec <<~SQL
|
||||
DB.exec <<~SQL, user_ids: user_ids
|
||||
UPDATE users u
|
||||
SET title = ''
|
||||
FROM user_profiles up
|
||||
@ -525,7 +523,7 @@ class BadgeGranter
|
||||
#{user_ids.present? ? "AND u.id IN (:user_ids)" : ""}
|
||||
SQL
|
||||
|
||||
DB.exec <<~SQL
|
||||
DB.exec <<~SQL, user_ids: user_ids
|
||||
UPDATE user_profiles up
|
||||
SET granted_title_badge_id = NULL
|
||||
FROM users u
|
||||
|
@ -11,10 +11,24 @@ RSpec.describe BadgeGranter do
|
||||
BadgeGranter.clear_queue!
|
||||
end
|
||||
|
||||
describe "revoke_titles" do
|
||||
describe ".revoke_ungranted_titles!" do
|
||||
let(:user) { Fabricate(:user) }
|
||||
let(:other_user) { Fabricate(:user) }
|
||||
let(:badge) { Fabricate(:badge, allow_title: true) }
|
||||
|
||||
it "can revoke title of a single user" do
|
||||
BadgeGranter.grant(badge, user)
|
||||
user.update!(title: badge.name)
|
||||
BadgeGranter.grant(badge, other_user)
|
||||
other_user.update!(title: badge.name)
|
||||
|
||||
badge.update_column(:enabled, false)
|
||||
BadgeGranter.revoke_ungranted_titles!([user.id])
|
||||
|
||||
expect(user.reload.title).to be_blank
|
||||
expect(other_user.reload.title).to eq(badge.name)
|
||||
end
|
||||
|
||||
it "revokes title when badge is not allowed as title" do
|
||||
BadgeGranter.grant(badge, user)
|
||||
user.update!(title: badge.name)
|
||||
|
Reference in New Issue
Block a user