FEATURE: dropdown to filter staff action logs

This commit is contained in:
Sam 2017-05-30 11:25:42 -04:00
parent 22b488704e
commit 607998af33
8 changed files with 105 additions and 51 deletions

View File

@ -5,9 +5,20 @@ import StaffActionLog from 'admin/models/staff-action-log';
export default Ember.Controller.extend({ export default Ember.Controller.extend({
loading: false, loading: false,
filters: null, filters: null,
userHistoryActions: [],
filtersExists: Ember.computed.gt('filterCount', 0), filtersExists: Ember.computed.gt('filterCount', 0),
filterActionIdChanged: function(){
const filterActionId = this.get('filterActionId');
if (filterActionId) {
this._changeFilters({
action_name: this.get('userHistoryActions').findBy("id", parseInt(filterActionId,10)).name_raw,
action_id: filterActionId
});
}
}.observes('filterActionId'),
actionFilter: function() { actionFilter: function() {
var name = this.get('filters.action_name'); var name = this.get('filters.action_name');
if (name) { if (name) {
@ -20,7 +31,6 @@ export default Ember.Controller.extend({
showInstructions: Ember.computed.gt('model.length', 0), showInstructions: Ember.computed.gt('model.length', 0),
refresh: function() { refresh: function() {
var self = this;
this.set('loading', true); this.set('loading', true);
var filters = this.get('filters'), var filters = this.get('filters'),
@ -37,10 +47,21 @@ export default Ember.Controller.extend({
}); });
this.set('filterCount', count); this.set('filterCount', count);
StaffActionLog.findAll(params).then(function(result) { StaffActionLog.findAll(params).then((result) => {
self.set('model', result); this.set('model', result.staff_action_logs);
}).finally(function() { if (this.get('userHistoryActions').length === 0) {
self.set('loading', false); let actionTypes = result.user_history_actions.map(pair => {
return {
id: pair.id,
name: I18n.t("admin.logs.staff_actions.actions." + pair.name),
name_raw: pair.name
};
});
actionTypes = _.sortBy(actionTypes, row => row.name);
this.set('userHistoryActions', actionTypes);
}
}).finally(()=>{
this.set('loading', false);
}); });
}, },
@ -63,6 +84,7 @@ export default Ember.Controller.extend({
changed.action_name = null; changed.action_name = null;
changed.action_id = null; changed.action_id = null;
changed.custom_type = null; changed.custom_type = null;
this.set("filterActionId", null);
} else { } else {
changed[key] = null; changed[key] = null;
} }
@ -70,6 +92,7 @@ export default Ember.Controller.extend({
}, },
clearAllFilters: function() { clearAllFilters: function() {
this.set("filterActionId", null);
this.resetFilters(); this.resetFilters();
}, },

View File

@ -57,10 +57,13 @@ StaffActionLog.reopenClass({
}, },
findAll: function(filters) { findAll: function(filters) {
return ajax("/admin/logs/staff_action_logs.json", { data: filters }).then(function(staff_actions) { return ajax("/admin/logs/staff_action_logs.json", { data: filters }).then((data) => {
return staff_actions.map(function(s) { return {
staff_action_logs: data.staff_action_logs.map(function(s) {
return StaffActionLog.create(s); return StaffActionLog.create(s);
}); }),
user_history_actions: data.user_history_actions
};
}); });
} }
}); });

View File

@ -1,5 +1,7 @@
<div class="staff-action-logs-controls"> <div class="staff-action-logs-controls">
<a {{action "clearAllFilters"}} class="clear-filters filter {{unless filtersExists 'invisible'}}"> {{#if filtersExists}}
<div>
<a {{action "clearAllFilters"}} class="clear-filters filter">
<span class="label">{{i18n 'admin.logs.staff_actions.clear_filters'}}</span> <span class="label">{{i18n 'admin.logs.staff_actions.clear_filters'}}</span>
</a> </a>
{{#if actionFilter}} {{#if actionFilter}}
@ -26,16 +28,16 @@
{{fa-icon "times-circle"}} {{fa-icon "times-circle"}}
</a> </a>
{{/if}} {{/if}}
</div> </div>
{{else}}
{{i18n "admin.logs.staff_actions.filter"}} {{combo-box content=userHistoryActions nameProperty="name" value=filterActionId none="admin.logs.staff_actions.all"}}
{{/if}}
<div class="pull-right"> <div class="pull-right">
{{d-button action="exportStaffActionLogs" label="admin.export_csv.button_text" icon="download"}} {{d-button action="exportStaffActionLogs" label="admin.export_csv.button_text" icon="download"}}
</div>
</div> </div>
<br> <div class="clearfix"></div>
<div class="staff-action-logs-instructions {{unless showInstructions 'invisible'}}">
{{i18n 'admin.logs.staff_actions.instructions'}}
</div>
<div class='table staff-actions'> <div class='table staff-actions'>
<div class="heading-container"> <div class="heading-container">

View File

@ -1305,10 +1305,6 @@ table.api-keys {
} }
} }
.staff-action-logs-instructions {
margin: 0 0 10px 10px;
}
// Ember.ListView // Ember.ListView
.ember-list-view { .ember-list-view {

View File

@ -2,8 +2,12 @@ class Admin::StaffActionLogsController < Admin::AdminController
def index def index
filters = params.slice(*UserHistory.staff_filters) filters = params.slice(*UserHistory.staff_filters)
staff_action_logs = UserHistory.staff_action_records(current_user, filters).to_a staff_action_logs = UserHistory.staff_action_records(current_user, filters).to_a
render_serialized(staff_action_logs, UserHistorySerializer) render json: StaffActionLogsSerializer.new({
staff_action_logs: staff_action_logs,
user_history_actions: UserHistory.staff_actions.sort.map{|name| {id: UserHistory.actions[name], name: name}}
}, root: false)
end end
def diff def diff

View File

@ -0,0 +1,12 @@
class StaffActionLogsSerializer < ApplicationSerializer
attributes :user_history_actions
has_many :staff_action_logs, serializer: UserHistorySerializer, embed: :objects
def staff_action_logs
object[:staff_action_logs]
end
def user_history_actions
object[:user_history_actions]
end
end

View File

@ -3025,8 +3025,9 @@ en:
block: "block" block: "block"
do_nothing: "do nothing" do_nothing: "do nothing"
staff_actions: staff_actions:
all: "all"
filter: "Filter:"
title: "Staff Actions" title: "Staff Actions"
instructions: "Click usernames and actions to filter the list. Click profile pictures to go to user pages."
clear_filters: "Show Everything" clear_filters: "Show Everything"
staff_user: "Staff User" staff_user: "Staff User"
target_user: "Target User" target_user: "Target User"
@ -3079,6 +3080,8 @@ en:
change_readonly_mode: "change readonly mode" change_readonly_mode: "change readonly mode"
backup_download: "download backup" backup_download: "download backup"
backup_destroy: "destroy backup" backup_destroy: "destroy backup"
reviewed_post: "reviewed post"
custom_staff: "plugin custom action"
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."

View File

@ -9,10 +9,21 @@ describe Admin::StaffActionLogsController do
context '.index' do context '.index' do
it 'works' do it 'generates logs' do
xhr :get, :index
topic = Fabricate(:topic)
_record = StaffActionLogger.new(Discourse.system_user).log_topic_deletion(topic)
xhr :get, :index, action_id: UserHistory.actions[:delete_topic]
json = JSON.parse(response.body)
expect(response).to be_success expect(response).to be_success
expect(::JSON.parse(response.body)).to be_a(Array)
expect(json["staff_action_logs"].length).to eq(1)
expect(json["staff_action_logs"][0]["action_name"]).to eq("delete_topic")
expect(json["user_history_actions"]).to include({"id" => UserHistory.actions[:delete_topic], "name" => 'delete_topic'})
end end
end end