2016-07-01 01:55:44 +08:00
|
|
|
import { ajax } from 'discourse/lib/ajax';
|
2015-11-21 09:27:06 +08:00
|
|
|
import AdminUser from 'admin/models/admin-user';
|
2016-06-15 02:31:51 +08:00
|
|
|
import { escapeExpression } from 'discourse/lib/utilities';
|
2015-11-21 09:27:06 +08:00
|
|
|
|
|
|
|
const StaffActionLog = Discourse.Model.extend({
|
2013-08-08 04:04:12 +08:00
|
|
|
showFullDetails: false,
|
|
|
|
|
|
|
|
actionName: function() {
|
|
|
|
return I18n.t("admin.logs.staff_actions.actions." + this.get('action_name'));
|
|
|
|
}.property('action_name'),
|
|
|
|
|
|
|
|
formattedDetails: function() {
|
|
|
|
var formatted = "";
|
2013-08-20 04:58:38 +08:00
|
|
|
formatted += this.format('email', 'email');
|
2013-08-23 07:04:17 +08:00
|
|
|
formatted += this.format('admin.logs.ip_address', 'ip_address');
|
2014-10-01 23:40:13 +08:00
|
|
|
formatted += this.format('admin.logs.topic_id', 'topic_id');
|
|
|
|
formatted += this.format('admin.logs.post_id', 'post_id');
|
2015-09-17 15:51:32 +08:00
|
|
|
formatted += this.format('admin.logs.category_id', 'category_id');
|
2013-08-22 00:33:05 +08:00
|
|
|
if (!this.get('useCustomModalForDetails')) {
|
2013-08-21 22:49:35 +08:00
|
|
|
formatted += this.format('admin.logs.staff_actions.new_value', 'new_value');
|
|
|
|
formatted += this.format('admin.logs.staff_actions.previous_value', 'previous_value');
|
|
|
|
}
|
2013-11-01 22:47:03 +08:00
|
|
|
if (!this.get('useModalForDetails')) {
|
2016-06-15 02:31:51 +08:00
|
|
|
if (this.get('details')) formatted += escapeExpression(this.get('details')) + '<br/>';
|
2013-11-01 22:47:03 +08:00
|
|
|
}
|
2013-08-08 04:04:12 +08:00
|
|
|
return formatted;
|
2015-09-17 15:51:32 +08:00
|
|
|
}.property('ip_address', 'email', 'topic_id', 'post_id', 'category_id'),
|
2013-08-20 04:58:38 +08:00
|
|
|
|
|
|
|
format: function(label, propertyName) {
|
|
|
|
if (this.get(propertyName)) {
|
2016-06-15 02:31:51 +08:00
|
|
|
return ('<b>' + I18n.t(label) + ':</b> ' + escapeExpression(this.get(propertyName)) + '<br/>');
|
2013-08-20 04:58:38 +08:00
|
|
|
} else {
|
|
|
|
return '';
|
|
|
|
}
|
2013-08-21 22:49:35 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
useModalForDetails: function() {
|
2013-11-01 22:47:03 +08:00
|
|
|
return (this.get('details') && this.get('details').length > 100);
|
2013-08-22 00:33:05 +08:00
|
|
|
}.property('action_name'),
|
|
|
|
|
|
|
|
useCustomModalForDetails: function() {
|
2013-08-22 00:03:21 +08:00
|
|
|
return _.contains(['change_site_customization', 'delete_site_customization'], this.get('action_name'));
|
2013-08-21 22:49:35 +08:00
|
|
|
}.property('action_name')
|
2013-08-08 04:04:12 +08:00
|
|
|
});
|
|
|
|
|
2015-11-21 09:27:06 +08:00
|
|
|
StaffActionLog.reopenClass({
|
2013-08-08 04:04:12 +08:00
|
|
|
create: function(attrs) {
|
2013-10-30 01:01:42 +08:00
|
|
|
attrs = attrs || {};
|
|
|
|
|
2013-09-11 09:21:16 +08:00
|
|
|
if (attrs.acting_user) {
|
2015-11-21 09:27:06 +08:00
|
|
|
attrs.acting_user = AdminUser.create(attrs.acting_user);
|
2013-08-08 04:04:12 +08:00
|
|
|
}
|
|
|
|
if (attrs.target_user) {
|
2015-11-21 09:27:06 +08:00
|
|
|
attrs.target_user = AdminUser.create(attrs.target_user);
|
2013-08-08 04:04:12 +08:00
|
|
|
}
|
|
|
|
return this._super(attrs);
|
|
|
|
},
|
|
|
|
|
2013-08-09 22:06:02 +08:00
|
|
|
findAll: function(filters) {
|
2016-07-01 01:55:44 +08:00
|
|
|
return ajax("/admin/logs/staff_action_logs.json", { data: filters }).then(function(staff_actions) {
|
2013-08-08 04:04:12 +08:00
|
|
|
return staff_actions.map(function(s) {
|
2015-11-21 09:27:06 +08:00
|
|
|
return StaffActionLog.create(s);
|
2013-08-08 04:04:12 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-11-21 09:27:06 +08:00
|
|
|
|
|
|
|
export default StaffActionLog;
|