FIX: Include post in staff action logs when silencing a user
This commit is contained in:
parent
ed114177e7
commit
7348513848
|
@ -289,7 +289,8 @@ class Admin::UsersController < Admin::AdminController
|
|||
silenced_till: params[:silenced_till],
|
||||
reason: params[:reason],
|
||||
message_body: message,
|
||||
keep_posts: true
|
||||
keep_posts: true,
|
||||
post_id: params[:post_id]
|
||||
)
|
||||
if silencer.silence && message.present?
|
||||
Jobs.enqueue(
|
||||
|
|
|
@ -289,13 +289,14 @@ class StaffActionLogger
|
|||
def log_silence_user(user, opts = {})
|
||||
raise Discourse::InvalidParameters.new(:user) unless user
|
||||
|
||||
UserHistory.create(
|
||||
params(opts).merge(
|
||||
action: UserHistory.actions[:silence_user],
|
||||
target_user_id: user.id,
|
||||
details: opts[:details]
|
||||
)
|
||||
create_args = params(opts).merge(
|
||||
action: UserHistory.actions[:silence_user],
|
||||
target_user_id: user.id,
|
||||
details: opts[:details]
|
||||
)
|
||||
create_args[:post_id] = opts[:post_id] if opts[:post_id]
|
||||
|
||||
UserHistory.create(create_args)
|
||||
end
|
||||
|
||||
def log_unsilence_user(user, opts = {})
|
||||
|
|
|
@ -33,10 +33,12 @@ class UserSilencer
|
|||
SystemMessage.create(@user, message_type)
|
||||
|
||||
if @by_user
|
||||
log_params = { context: context, details: details }
|
||||
log_params[:post_id] = @opts[:post_id].to_i if @opts[:post_id]
|
||||
|
||||
@user_history = StaffActionLogger.new(@by_user).log_silence_user(
|
||||
@user,
|
||||
context: context,
|
||||
details: details
|
||||
log_params
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -615,6 +615,31 @@ describe Admin::UsersController do
|
|||
expect(@reg_user).to be_silenced
|
||||
end
|
||||
|
||||
it "can have an associated post" do
|
||||
silence_post = Fabricate(:post, user: @reg_user)
|
||||
|
||||
put :silence, params: {
|
||||
user_id: @reg_user.id,
|
||||
post_id: silence_post.id,
|
||||
post_action: 'edit',
|
||||
post_edit: "this is the new contents for the post"
|
||||
}, format: :json
|
||||
expect(response).to be_success
|
||||
|
||||
silence_post.reload
|
||||
expect(silence_post.raw).to eq("this is the new contents for the post")
|
||||
|
||||
log = UserHistory.where(
|
||||
target_user_id: @reg_user.id,
|
||||
action: UserHistory.actions[:silence_user]
|
||||
).first
|
||||
expect(log).to be_present
|
||||
expect(log.post_id).to eq(silence_post.id)
|
||||
|
||||
@reg_user.reload
|
||||
expect(@reg_user).to be_silenced
|
||||
end
|
||||
|
||||
it "will set a length of time if provided" do
|
||||
future_date = 1.month.from_now.to_date
|
||||
put(
|
||||
|
|
|
@ -60,7 +60,7 @@ describe UserSilencer do
|
|||
end
|
||||
|
||||
it "logs it with context" do
|
||||
SystemMessage.stubs(:create).returns(Fabricate.build(:post))
|
||||
SystemMessage.stubs(:create)
|
||||
expect {
|
||||
UserSilencer.silence(user, Fabricate(:admin))
|
||||
}.to change { UserHistory.count }.by(1)
|
||||
|
|
Loading…
Reference in New Issue