FEATURE: Log staff actions for Category changes.

This commit is contained in:
Guo Xiang Tan
2015-09-17 15:51:32 +08:00
parent c29b7ce498
commit f39b9124b6
13 changed files with 228 additions and 7 deletions

View File

@ -4,6 +4,7 @@ class CategoriesController < ApplicationController
before_filter :ensure_logged_in, except: [:index, :show, :redirect]
before_filter :fetch_category, only: [:show, :update, :destroy]
before_filter :initialize_staff_action_logger, only: [:create, :update, :destroy]
skip_before_filter :check_xhr, only: [:index, :redirect]
def redirect
@ -81,10 +82,18 @@ class CategoriesController < ApplicationController
position = category_params.delete(:position)
@category = Category.create(category_params.merge(user: current_user))
return render_json_error(@category) unless @category.save
@category.move_to(position.to_i) if position
render_serialized(@category, CategorySerializer)
if @category.save
@category.move_to(position.to_i) if position
Scheduler::Defer.later "Log staff action create category" do
@staff_action_logger.log_category_creation(@category)
end
render_serialized(@category, CategorySerializer)
else
return render_json_error(@category) unless @category.save
end
end
def update
@ -103,8 +112,15 @@ class CategoriesController < ApplicationController
end
category_params.delete(:position)
old_permissions = Category.find(@category.id).permissions_params
cat.update_attributes(category_params)
if result = cat.update_attributes(category_params)
Scheduler::Defer.later "Log staff action change category settings" do
@staff_action_logger.log_category_settings_change(@category, category_params, old_permissions)
end
end
result
end
end
@ -133,6 +149,10 @@ class CategoriesController < ApplicationController
guardian.ensure_can_delete!(@category)
@category.destroy
Scheduler::Defer.later "Log staff action delete category" do
@staff_action_logger.log_category_deletion(@category)
end
render json: success_json
end
@ -175,4 +195,8 @@ class CategoriesController < ApplicationController
def fetch_category
@category = Category.find_by(slug: params[:id]) || Category.find_by(id: params[:id].to_i)
end
def initialize_staff_action_logger
@staff_action_logger = StaffActionLogger.new(current_user)
end
end