diff --git a/app/assets/javascripts/admin/controllers/change_site_customization_details_controller.js b/app/assets/javascripts/admin/controllers/change_site_customization_details_controller.js
index 7fe0d014f08..121fb2a0032 100644
--- a/app/assets/javascripts/admin/controllers/change_site_customization_details_controller.js
+++ b/app/assets/javascripts/admin/controllers/change_site_customization_details_controller.js
@@ -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
@extends Discourse.Controller
diff --git a/app/assets/javascripts/admin/controllers/delete_site_customization_details_controller.js b/app/assets/javascripts/admin/controllers/delete_site_customization_details_controller.js
new file mode 100644
index 00000000000..53a54c5054b
--- /dev/null
+++ b/app/assets/javascripts/admin/controllers/delete_site_customization_details_controller.js
@@ -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();
+ }
+});
diff --git a/app/assets/javascripts/admin/models/staff_action_log.js b/app/assets/javascripts/admin/models/staff_action_log.js
index aa5a93ea6f4..93484194365 100644
--- a/app/assets/javascripts/admin/models/staff_action_log.js
+++ b/app/assets/javascripts/admin/models/staff_action_log.js
@@ -33,7 +33,7 @@ Discourse.StaffActionLog = Discourse.Model.extend({
},
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')
});
diff --git a/app/assets/javascripts/admin/templates/logs/site_customization_change_modal.js.handlebars b/app/assets/javascripts/admin/templates/logs/site_customization_change_modal.js.handlebars
index ca30597ed67..5d0e96ab3ab 100644
--- a/app/assets/javascripts/admin/templates/logs/site_customization_change_modal.js.handlebars
+++ b/app/assets/javascripts/admin/templates/logs/site_customization_change_modal.js.handlebars
@@ -9,9 +9,13 @@
- {{#with new_value}}
- {{partial "admin/templates/logs/site_customization_change_details"}}
- {{/with}}
+ {{#if new_value}}
+ {{#with new_value}}
+ {{partial "admin/templates/logs/site_customization_change_details"}}
+ {{/with}}
+ {{else}}
+ {{i18n admin.logs.staff_actions.deleted}}
+ {{/if}}
{{#if previous_value}}
diff --git a/app/assets/javascripts/admin/views/modals/change_site_customization_details_view.js b/app/assets/javascripts/admin/views/modals/change_site_customization_details_view.js
index 1bafebf0d34..7728bf7775c 100644
--- a/app/assets/javascripts/admin/views/modals/change_site_customization_details_view.js
+++ b/app/assets/javascripts/admin/views/modals/change_site_customization_details_view.js
@@ -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
@extends Discourse.ModalBodyView
diff --git a/app/assets/javascripts/admin/views/modals/delete_site_customization_details_view.js b/app/assets/javascripts/admin/views/modals/delete_site_customization_details_view.js
new file mode 100644
index 00000000000..a4670c69749
--- /dev/null
+++ b/app/assets/javascripts/admin/views/modals/delete_site_customization_details_view.js
@@ -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')
+});
diff --git a/app/controllers/admin/site_customizations_controller.rb b/app/controllers/admin/site_customizations_controller.rb
index d55caa076f2..855b947bd9b 100644
--- a/app/controllers/admin/site_customizations_controller.rb
+++ b/app/controllers/admin/site_customizations_controller.rb
@@ -38,10 +38,9 @@ class Admin::SiteCustomizationsController < Admin::AdminController
def destroy
@site_customization = SiteCustomization.find(params[:id])
+ StaffActionLogger.new(current_user).log_site_customization_destroy(@site_customization)
@site_customization.destroy
- # TODO: log this
-
respond_to do |format|
format.json { head :no_content }
end
diff --git a/app/models/staff_action_log.rb b/app/models/staff_action_log.rb
index 4bc3477a74e..bee6d61e0bc 100644
--- a/app/models/staff_action_log.rb
+++ b/app/models/staff_action_log.rb
@@ -9,7 +9,11 @@ class StaffActionLog < ActiveRecord::Base
validates_presence_of :action
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
def self.with_filters(filters)
@@ -27,7 +31,7 @@ class StaffActionLog < ActiveRecord::Base
end
def new_value_is_json?
- action == StaffActionLog.actions[:change_site_customization]
+ [StaffActionLog.actions[:change_site_customization], StaffActionLog.actions[:delete_site_customization]].include?(action)
end
def previous_value_is_json?
diff --git a/app/services/staff_action_logger.rb b/app/services/staff_action_logger.rb
index 8ad76453b83..aa2bdbaa450 100644
--- a/app/services/staff_action_logger.rb
+++ b/app/services/staff_action_logger.rb
@@ -37,14 +37,24 @@ class StaffActionLogger
}))
end
+ SITE_CUSTOMIZATION_LOGGED_ATTRS = ['stylesheet', 'header', 'position', 'enabled', 'key', 'override_default_style']
+
def log_site_customization_change(old_record, site_customization_params, opts={})
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({
action: StaffActionLog.actions[:change_site_customization],
subject: site_customization_params[:name],
- previous_value: old_record ? old_record.attributes.slice(*logged_attrs).to_json : nil,
- new_value: site_customization_params.slice(*(logged_attrs.map(&:to_sym))).to_json
+ previous_value: old_record ? old_record.attributes.slice(*SITE_CUSTOMIZATION_LOGGED_ATTRS).to_json : nil,
+ 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
@@ -53,4 +63,5 @@ class StaffActionLogger
def params(opts)
{staff_user_id: @admin.id, context: opts[:context]}
end
+
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index d00f5318c10..a589b804186 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1203,11 +1203,13 @@ en:
show: "Show"
modal_title: "Details"
no_previous: "There is no previous value."
+ deleted: "No new value. The record was deleted."
actions:
delete_user: "delete user"
change_trust_level: "change trust level"
change_site_setting: "change site setting"
change_site_customization: "change site customization"
+ delete_site_customization: "delete site customization"
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."
diff --git a/spec/services/staff_action_logger_spec.rb b/spec/services/staff_action_logger_spec.rb
index ca6a9ed5e06..3259857f639 100644
--- a/spec/services/staff_action_logger_spec.rb
+++ b/spec/services/staff_action_logger_spec.rb
@@ -100,4 +100,20 @@ describe StaffActionLogger do
json['header'].should == existing.header
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