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