FEATURE: log manual bounce reset (#20758)
DEV: rename the route "/admin/users/:id/reset_bounce_score" to use dashes instead of underscores
This commit is contained in:
parent
7ccc7b75b2
commit
37609897e8
|
@ -63,7 +63,7 @@ export default class AdminUser extends User {
|
|||
}
|
||||
|
||||
resetBounceScore() {
|
||||
return ajax(`/admin/users/${this.id}/reset_bounce_score`, {
|
||||
return ajax(`/admin/users/${this.id}/reset-bounce-score`, {
|
||||
type: "POST",
|
||||
}).then(() =>
|
||||
this.setProperties({
|
||||
|
|
|
@ -588,6 +588,7 @@ class Admin::UsersController < Admin::StaffController
|
|||
def reset_bounce_score
|
||||
guardian.ensure_can_reset_bounce_score!(@user)
|
||||
@user.user_stat&.reset_bounce_score!
|
||||
StaffActionLogger.new(current_user).log_reset_bounce_score(@user)
|
||||
render json: success_json
|
||||
end
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ class UserHistory < ActiveRecord::Base
|
|||
create_public_sidebar_section: 101,
|
||||
update_public_sidebar_section: 102,
|
||||
destroy_public_sidebar_section: 103,
|
||||
reset_bounce_score: 104,
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -221,6 +222,7 @@ class UserHistory < ActiveRecord::Base
|
|||
create_public_sidebar_section
|
||||
update_public_sidebar_section
|
||||
destroy_public_sidebar_section
|
||||
reset_bounce_score
|
||||
]
|
||||
end
|
||||
|
||||
|
|
|
@ -990,6 +990,14 @@ class StaffActionLogger
|
|||
)
|
||||
end
|
||||
|
||||
def log_reset_bounce_score(user, opts = {})
|
||||
raise Discourse::InvalidParameters.new(:user) unless user
|
||||
|
||||
UserHistory.create!(
|
||||
params(opts).merge(action: UserHistory.actions[:reset_bounce_score], target_user_id: user.id),
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_changes(changes)
|
||||
|
|
|
@ -156,7 +156,7 @@ Discourse::Application.routes.draw do
|
|||
get "tl3_requirements"
|
||||
put "anonymize"
|
||||
post "merge"
|
||||
post "reset_bounce_score"
|
||||
post "reset-bounce-score"
|
||||
put "disable_second_factor"
|
||||
delete "sso_record"
|
||||
end
|
||||
|
|
|
@ -2265,4 +2265,31 @@ RSpec.describe Admin::UsersController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#reset_bounce_score" do
|
||||
before { user.user_stat.update!(bounce_score: 10) }
|
||||
|
||||
context "when logged in as a moderator" do
|
||||
before { sign_in(moderator) }
|
||||
|
||||
it "will reset the bounce score" do
|
||||
post "/admin/users/#{user.id}/reset-bounce-score.json"
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
expect(user.reload.user_stat.bounce_score).to eq(0)
|
||||
expect(UserHistory.last.action).to eq(UserHistory.actions[:reset_bounce_score])
|
||||
end
|
||||
end
|
||||
|
||||
context "when logged in as a non-staff user" do
|
||||
before { sign_in(user) }
|
||||
|
||||
it "prevents resetting the bounce score with a 404 response" do
|
||||
post "/admin/users/#{user.id}/reset-bounce-score.json"
|
||||
|
||||
expect(response.status).to eq(404)
|
||||
expect(user.reload.user_stat.bounce_score).to eq(10)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue