mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 14:42:46 +08:00
FEATURE: log site text changes
This commit is contained in:
parent
f48419526d
commit
4c967d11b4
|
@ -44,6 +44,8 @@ class Admin::SiteTextsController < Admin::AdminController
|
|||
def update
|
||||
site_text = find_site_text
|
||||
site_text[:value] = params[:site_text][:value]
|
||||
old_text = I18n.t(site_text[:id])
|
||||
StaffActionLogger.new(current_user).log_site_text_change(site_text[:id], site_text[:value], old_text)
|
||||
|
||||
TranslationOverride.upsert!(I18n.locale, site_text[:id], site_text[:value])
|
||||
render_serialized(site_text, SiteTextSerializer, root: 'site_text', rest_serializer: true)
|
||||
|
@ -51,8 +53,10 @@ class Admin::SiteTextsController < Admin::AdminController
|
|||
|
||||
def revert
|
||||
site_text = find_site_text
|
||||
old_text = I18n.t(site_text[:id])
|
||||
TranslationOverride.revert!(I18n.locale, site_text[:id])
|
||||
site_text = find_site_text
|
||||
StaffActionLogger.new(current_user).log_site_text_change(site_text[:id], site_text[:value], old_text)
|
||||
render_serialized(site_text, SiteTextSerializer, root: 'site_text', rest_serializer: true)
|
||||
end
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ class UserHistory < ActiveRecord::Base
|
|||
:change_site_setting,
|
||||
:change_site_customization,
|
||||
:delete_site_customization,
|
||||
:change_site_text,
|
||||
:checked_for_custom_avatar, # not used anymore
|
||||
:notified_about_avatar,
|
||||
:notified_about_sequential_replies,
|
||||
|
@ -53,6 +54,7 @@ class UserHistory < ActiveRecord::Base
|
|||
:change_site_setting,
|
||||
:change_site_customization,
|
||||
:delete_site_customization,
|
||||
:change_site_text,
|
||||
:suspend_user,
|
||||
:unsuspend_user,
|
||||
:grant_badge,
|
||||
|
|
|
@ -134,6 +134,18 @@ class StaffActionLogger
|
|||
}))
|
||||
end
|
||||
|
||||
def log_site_text_change(subject, new_text, old_text, opts={})
|
||||
raise Discourse::InvalidParameters.new(:subject) unless subject.present?
|
||||
raise Discourse::InvalidParameters.new(:new_text) unless new_text.present?
|
||||
raise Discourse::InvalidParameters.new(:old_text) unless old_text.present?
|
||||
UserHistory.create( params(opts).merge({
|
||||
action: UserHistory.actions[:change_site_text],
|
||||
subject: subject,
|
||||
previous_value: old_text,
|
||||
new_value: new_text
|
||||
}))
|
||||
end
|
||||
|
||||
def log_username_change(user, old_username, new_username, opts={})
|
||||
raise Discourse::InvalidParameters.new(:user) unless user
|
||||
UserHistory.create( params(opts).merge({
|
||||
|
|
|
@ -2253,6 +2253,7 @@ en:
|
|||
change_site_setting: "change site setting"
|
||||
change_site_customization: "change site customization"
|
||||
delete_site_customization: "delete site customization"
|
||||
change_site_text: "change site text"
|
||||
suspend_user: "suspend user"
|
||||
unsuspend_user: "unsuspend user"
|
||||
grant_badge: "grant badge"
|
||||
|
|
|
@ -75,6 +75,11 @@ describe Admin::SiteTextsController do
|
|||
xhr :put, :update, id: 'made_up_no_key_exists', site_text: {value: 'hello'}
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
|
||||
it 'logs the change' do
|
||||
StaffActionLogger.any_instance.expects(:log_site_text_change).once
|
||||
xhr :put, :update, id: 'title', site_text: {value: 'hello'}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -173,6 +173,18 @@ describe StaffActionLogger do
|
|||
end
|
||||
end
|
||||
|
||||
describe "log_site_text_change" do
|
||||
it "raises an error when params are invalid" do
|
||||
expect { logger.log_site_text_change(nil, 'new text', 'old text') }.to raise_error(Discourse::InvalidParameters)
|
||||
expect { logger.log_site_text_change('created', nil, 'old text') }.to raise_error(Discourse::InvalidParameters)
|
||||
expect { logger.log_site_text_change('created', 'new text', nil) }.to raise_error(Discourse::InvalidParameters)
|
||||
end
|
||||
|
||||
it "creates a new UserHistory record" do
|
||||
expect { logger.log_site_text_change('created', 'new text', 'old text') }.to change { UserHistory.count }.by(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "log_user_suspend" do
|
||||
let(:user) { Fabricate(:user, suspended_at: 10.minutes.ago, suspended_till: 1.day.from_now) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user