FEATURE: Log admin action when readonly mode is changed.
This commit is contained in:
parent
240c4870cf
commit
515f50e42e
|
@ -103,6 +103,8 @@ class Admin::BackupsController < Admin::AdminController
|
|||
Discourse.disable_readonly_mode(readonly_mode_key)
|
||||
end
|
||||
|
||||
StaffActionLogger.new(current_user).log_change_readonly_mode(enable)
|
||||
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
|
|
|
@ -58,7 +58,8 @@ class UserHistory < ActiveRecord::Base
|
|||
wizard_step: 40,
|
||||
lock_trust_level: 41,
|
||||
unlock_trust_level: 42,
|
||||
activate_user: 43
|
||||
activate_user: 43,
|
||||
change_readonly_mode: 44
|
||||
)
|
||||
end
|
||||
|
||||
|
@ -97,7 +98,8 @@ class UserHistory < ActiveRecord::Base
|
|||
:deactivate_user,
|
||||
:lock_trust_level,
|
||||
:unlock_trust_level,
|
||||
:activate_user]
|
||||
:activate_user,
|
||||
:change_readonly_mode]
|
||||
end
|
||||
|
||||
def self.staff_action_ids
|
||||
|
|
|
@ -373,11 +373,18 @@ class StaffActionLogger
|
|||
raise Discourse::InvalidParameters.new(:step) unless step
|
||||
UserHistory.create(params(opts).merge({
|
||||
action: UserHistory.actions[:wizard_step],
|
||||
acting_user_id: @admin.id,
|
||||
context: step.id
|
||||
}))
|
||||
end
|
||||
|
||||
def log_change_readonly_mode(state)
|
||||
UserHistory.create(params.merge({
|
||||
action: UserHistory.actions[:change_readonly_mode],
|
||||
previous_value: !state,
|
||||
new_value: state
|
||||
}))
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def params(opts=nil)
|
||||
|
|
|
@ -2919,6 +2919,7 @@ en:
|
|||
unlock_trust_level: "unlock trust level"
|
||||
activate_user: "activate user"
|
||||
deactivate_user: "deactivate user"
|
||||
change_readonly_mode: "change readonly mode"
|
||||
screened_emails:
|
||||
title: "Screened Emails"
|
||||
description: "When someone tries to create a new account, the following email addresses will be checked and the registration will be blocked, or some other action performed."
|
||||
|
|
|
@ -179,17 +179,29 @@ describe Admin::BackupsController do
|
|||
it "enables readonly mode" do
|
||||
Discourse.expects(:enable_readonly_mode)
|
||||
|
||||
xhr :put, :readonly, enable: true
|
||||
expect { xhr :put, :readonly, enable: true }
|
||||
.to change { UserHistory.count }.by(1)
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
user_history = UserHistory.last
|
||||
|
||||
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_readonly_mode])
|
||||
expect(UserHistory.last.new_value).to eq('t')
|
||||
end
|
||||
|
||||
it "disables readonly mode" do
|
||||
Discourse.expects(:disable_readonly_mode)
|
||||
|
||||
xhr :put, :readonly, enable: false
|
||||
expect { xhr :put, :readonly, enable: false }
|
||||
.to change { UserHistory.count }.by(1)
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
user_history = UserHistory.last
|
||||
|
||||
expect(UserHistory.last.action).to eq(UserHistory.actions[:change_readonly_mode])
|
||||
expect(UserHistory.last.new_value).to eq('f')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -370,6 +370,7 @@ describe StaffActionLogger do
|
|||
end
|
||||
end
|
||||
|
||||
<<<<<<< 240c4870cfa43dea222ed52d4ce57b6ac186588d
|
||||
describe 'log_lock_trust_level' do
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
|
@ -406,5 +407,24 @@ describe StaffActionLogger do
|
|||
expect(user_history.action).to eq(UserHistory.actions[:activate_user])
|
||||
expect(user_history.details).to eq(reason)
|
||||
end
|
||||
|
||||
describe '#log_readonly_mode' do
|
||||
it "creates a new record" do
|
||||
expect { logger.log_change_readonly_mode(true) }.to change { UserHistory.count }.by(1)
|
||||
|
||||
user_history = UserHistory.last
|
||||
|
||||
expect(user_history.action).to eq(UserHistory.actions[:change_readonly_mode])
|
||||
expect(user_history.new_value).to eq('t')
|
||||
expect(user_history.previous_value).to eq('f')
|
||||
|
||||
expect { logger.log_change_readonly_mode(false) }.to change { UserHistory.count }.by(1)
|
||||
|
||||
user_history = UserHistory.last
|
||||
|
||||
expect(user_history.action).to eq(UserHistory.actions[:change_readonly_mode])
|
||||
expect(user_history.new_value).to eq('f')
|
||||
expect(user_history.previous_value).to eq('t')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue