FIX: bug when revoking badge as title (#8616)

When user revokes badge as title, UserHistory item is created. However,
that object is not accepting revoke_reson parameter.
This commit is contained in:
Krzysztof Kotlarek 2019-12-24 08:03:51 +11:00 committed by GitHub
parent 63323bd7a8
commit ac626a0dc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View File

@ -215,12 +215,13 @@ class UsersController < ApplicationController
user.save!
log_params = {
revoke_reason: 'user title was same as revoked badge name or custom badge name',
previous_value: previous_title
}
if current_user.staff? && current_user != user
StaffActionLogger.new(current_user).log_title_revoke(user, log_params)
StaffActionLogger
.new(current_user)
.log_title_revoke(user, log_params.merge(revoke_reason: 'user title was same as revoked badge name or custom badge name'))
else
UserHistory.create!(log_params.merge(target_user_id: user.id, action: UserHistory.actions[:revoke_title]))
end

View File

@ -1943,6 +1943,14 @@ describe UsersController do
expect(user.user_profile.granted_title_badge_id).to eq(nil)
end
it "is not raising an erroring when user revokes title" do
sign_in(user)
badge.update allow_title: true
put "/u/#{user.username}/preferences/badge_title.json", params: { user_badge_id: user_badge.id }
put "/u/#{user.username}/preferences/badge_title.json", params: { user_badge_id: 0 }
expect(response.status).to eq(200)
end
context "with overrided name" do
fab!(:badge) { Fabricate(:badge, name: 'Demogorgon', allow_title: true) }
let(:user_badge) { BadgeGranter.grant(badge, user) }