Log when a site customization is deleted
This commit is contained in:
parent
a95303fcd8
commit
47add6da70
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
The modal for viewing the details of a staff action log record.
|
The modal for viewing the details of a staff action log record
|
||||||
|
for when a site customization is created or changed.
|
||||||
|
|
||||||
@class ChangeSiteCustomizationDetailsController
|
@class ChangeSiteCustomizationDetailsController
|
||||||
@extends Discourse.Controller
|
@extends Discourse.Controller
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
/**
|
||||||
|
The modal for viewing the details of a staff action log record
|
||||||
|
for when a site customization is deleted.
|
||||||
|
|
||||||
|
@class DeleteSiteCustomizationDetailsController
|
||||||
|
@extends Discourse.Controller
|
||||||
|
@namespace Discourse
|
||||||
|
@uses Discourse.ModalFunctionality
|
||||||
|
@module Discourse
|
||||||
|
**/
|
||||||
|
Discourse.DeleteSiteCustomizationDetailsController = Discourse.ChangeSiteCustomizationDetailsController.extend({
|
||||||
|
onShow: function() {
|
||||||
|
this.selectPrevious();
|
||||||
|
}
|
||||||
|
});
|
|
@ -33,7 +33,7 @@ Discourse.StaffActionLog = Discourse.Model.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
useModalForDetails: function() {
|
useModalForDetails: function() {
|
||||||
return (this.get('action_name') === 'change_site_customization');
|
return _.contains(['change_site_customization', 'delete_site_customization'], this.get('action_name'));
|
||||||
}.property('action_name')
|
}.property('action_name')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -9,9 +9,13 @@
|
||||||
</ul>
|
</ul>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<div {{bindAttr class=":modal-tab :new-tab newSelected::invisible"}}>
|
<div {{bindAttr class=":modal-tab :new-tab newSelected::invisible"}}>
|
||||||
{{#with new_value}}
|
{{#if new_value}}
|
||||||
{{partial "admin/templates/logs/site_customization_change_details"}}
|
{{#with new_value}}
|
||||||
{{/with}}
|
{{partial "admin/templates/logs/site_customization_change_details"}}
|
||||||
|
{{/with}}
|
||||||
|
{{else}}
|
||||||
|
{{i18n admin.logs.staff_actions.deleted}}
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
<div {{bindAttr class=":modal-tab :previous-tab previousSelected::invisible"}}>
|
<div {{bindAttr class=":modal-tab :previous-tab previousSelected::invisible"}}>
|
||||||
{{#if previous_value}}
|
{{#if previous_value}}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
A modal view for details of a staff action log record in a modal.
|
A modal view for details of a staff action log record in a modal
|
||||||
|
for when a site customization is created or changed.
|
||||||
|
|
||||||
@class ChangeSiteCustomizationDetailsView
|
@class ChangeSiteCustomizationDetailsView
|
||||||
@extends Discourse.ModalBodyView
|
@extends Discourse.ModalBodyView
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
/**
|
||||||
|
A modal view for details of a staff action log record in a modal
|
||||||
|
for when a site customization is deleted.
|
||||||
|
|
||||||
|
@class DeleteSiteCustomizationDetailsView
|
||||||
|
@extends Discourse.ModalBodyView
|
||||||
|
@namespace Discourse
|
||||||
|
@module Discourse
|
||||||
|
**/
|
||||||
|
Discourse.DeleteSiteCustomizationDetailsView = Discourse.ModalBodyView.extend({
|
||||||
|
templateName: 'admin/templates/logs/site_customization_change_modal',
|
||||||
|
title: I18n.t('admin.logs.staff_actions.modal_title')
|
||||||
|
});
|
|
@ -38,10 +38,9 @@ class Admin::SiteCustomizationsController < Admin::AdminController
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@site_customization = SiteCustomization.find(params[:id])
|
@site_customization = SiteCustomization.find(params[:id])
|
||||||
|
StaffActionLogger.new(current_user).log_site_customization_destroy(@site_customization)
|
||||||
@site_customization.destroy
|
@site_customization.destroy
|
||||||
|
|
||||||
# TODO: log this
|
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json { head :no_content }
|
format.json { head :no_content }
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,7 +9,11 @@ class StaffActionLog < ActiveRecord::Base
|
||||||
validates_presence_of :action
|
validates_presence_of :action
|
||||||
|
|
||||||
def self.actions
|
def self.actions
|
||||||
@actions ||= Enum.new(:delete_user, :change_trust_level, :change_site_setting, :change_site_customization)
|
@actions ||= Enum.new( :delete_user,
|
||||||
|
:change_trust_level,
|
||||||
|
:change_site_setting,
|
||||||
|
:change_site_customization,
|
||||||
|
:delete_site_customization)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.with_filters(filters)
|
def self.with_filters(filters)
|
||||||
|
@ -27,7 +31,7 @@ class StaffActionLog < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_value_is_json?
|
def new_value_is_json?
|
||||||
action == StaffActionLog.actions[:change_site_customization]
|
[StaffActionLog.actions[:change_site_customization], StaffActionLog.actions[:delete_site_customization]].include?(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
def previous_value_is_json?
|
def previous_value_is_json?
|
||||||
|
|
|
@ -37,14 +37,24 @@ class StaffActionLogger
|
||||||
}))
|
}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
SITE_CUSTOMIZATION_LOGGED_ATTRS = ['stylesheet', 'header', 'position', 'enabled', 'key', 'override_default_style']
|
||||||
|
|
||||||
def log_site_customization_change(old_record, site_customization_params, opts={})
|
def log_site_customization_change(old_record, site_customization_params, opts={})
|
||||||
raise Discourse::InvalidParameters.new('site_customization_params is nil') unless site_customization_params
|
raise Discourse::InvalidParameters.new('site_customization_params is nil') unless site_customization_params
|
||||||
logged_attrs = ['stylesheet', 'header', 'position', 'enabled', 'key', 'override_default_style']
|
|
||||||
StaffActionLog.create( params(opts).merge({
|
StaffActionLog.create( params(opts).merge({
|
||||||
action: StaffActionLog.actions[:change_site_customization],
|
action: StaffActionLog.actions[:change_site_customization],
|
||||||
subject: site_customization_params[:name],
|
subject: site_customization_params[:name],
|
||||||
previous_value: old_record ? old_record.attributes.slice(*logged_attrs).to_json : nil,
|
previous_value: old_record ? old_record.attributes.slice(*SITE_CUSTOMIZATION_LOGGED_ATTRS).to_json : nil,
|
||||||
new_value: site_customization_params.slice(*(logged_attrs.map(&:to_sym))).to_json
|
new_value: site_customization_params.slice(*(SITE_CUSTOMIZATION_LOGGED_ATTRS.map(&:to_sym))).to_json
|
||||||
|
}))
|
||||||
|
end
|
||||||
|
|
||||||
|
def log_site_customization_destroy(site_customization, opts={})
|
||||||
|
raise Discourse::InvalidParameters.new('site_customization is nil') unless site_customization
|
||||||
|
StaffActionLog.create( params(opts).merge({
|
||||||
|
action: StaffActionLog.actions[:delete_site_customization],
|
||||||
|
subject: site_customization.name,
|
||||||
|
previous_value: site_customization.attributes.slice(*SITE_CUSTOMIZATION_LOGGED_ATTRS).to_json
|
||||||
}))
|
}))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,4 +63,5 @@ class StaffActionLogger
|
||||||
def params(opts)
|
def params(opts)
|
||||||
{staff_user_id: @admin.id, context: opts[:context]}
|
{staff_user_id: @admin.id, context: opts[:context]}
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1203,11 +1203,13 @@ en:
|
||||||
show: "Show"
|
show: "Show"
|
||||||
modal_title: "Details"
|
modal_title: "Details"
|
||||||
no_previous: "There is no previous value."
|
no_previous: "There is no previous value."
|
||||||
|
deleted: "No new value. The record was deleted."
|
||||||
actions:
|
actions:
|
||||||
delete_user: "delete user"
|
delete_user: "delete user"
|
||||||
change_trust_level: "change trust level"
|
change_trust_level: "change trust level"
|
||||||
change_site_setting: "change site setting"
|
change_site_setting: "change site setting"
|
||||||
change_site_customization: "change site customization"
|
change_site_customization: "change site customization"
|
||||||
|
delete_site_customization: "delete site customization"
|
||||||
screened_emails:
|
screened_emails:
|
||||||
title: "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."
|
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."
|
||||||
|
|
|
@ -100,4 +100,20 @@ describe StaffActionLogger do
|
||||||
json['header'].should == existing.header
|
json['header'].should == existing.header
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "log_site_customization_destroy" do
|
||||||
|
it "raises an error when params are invalid" do
|
||||||
|
expect { logger.log_site_customization_destroy(nil) }.to raise_error(Discourse::InvalidParameters)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "creates a new StaffActionLog record" do
|
||||||
|
site_customization = SiteCustomization.new(name: 'Banana', stylesheet: "body {color: yellow;}", header: "h1 {color: brown;}")
|
||||||
|
log_record = logger.log_site_customization_destroy(site_customization)
|
||||||
|
log_record.previous_value.should be_present
|
||||||
|
log_record.new_value.should be_nil
|
||||||
|
json = ::JSON.parse(log_record.previous_value)
|
||||||
|
json['stylesheet'].should == site_customization.stylesheet
|
||||||
|
json['header'].should == site_customization.header
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue