discourse/app/assets/javascripts/admin/models/staff-action-log.js.es6

108 lines
2.6 KiB
Plaintext
Raw Normal View History

import computed from "ember-addons/ember-computed-decorators";
import { ajax } from "discourse/lib/ajax";
import AdminUser from "admin/models/admin-user";
import { escapeExpression } from "discourse/lib/utilities";
function format(label, value, escape = true) {
2018-06-15 23:03:24 +08:00
return value
? `<b>${I18n.t(label)}</b>: ${escape ? escapeExpression(value) : value}`
: "";
}
const StaffActionLog = Discourse.Model.extend({
showFullDetails: false,
@computed("action_name")
actionName(actionName) {
return I18n.t(`admin.logs.staff_actions.actions.${actionName}`);
},
2018-06-15 23:03:24 +08:00
@computed(
"email",
"ip_address",
"topic_id",
"post_id",
"category_id",
"new_value",
"previous_value",
"details",
"useCustomModalForDetails",
"useModalForDetails"
)
formattedDetails(
email,
ipAddress,
topicId,
postId,
categoryId,
newValue,
previousValue,
details,
useCustomModalForDetails,
useModalForDetails
) {
const postLink = postId
? `<a href data-link-post-id="${postId}">${postId}</a>`
: null;
let lines = [
format("email", email),
format("admin.logs.ip_address", ipAddress),
format("admin.logs.topic_id", topicId),
format("admin.logs.post_id", postLink, false),
2018-06-15 23:03:24 +08:00
format("admin.logs.category_id", categoryId)
];
if (!useCustomModalForDetails) {
lines.push(format("admin.logs.staff_actions.new_value", newValue));
2018-06-15 23:03:24 +08:00
lines.push(
format("admin.logs.staff_actions.previous_value", previousValue)
);
}
if (!useModalForDetails && details) {
lines = [...lines, ...escapeExpression(details).split("\n")];
}
const formatted = lines.filter(l => l.length > 0).join("<br/>");
return formatted.length > 0 ? formatted + "<br/>" : "";
},
@computed("details")
useModalForDetails(details) {
return details && details.length > 100;
},
@computed("action_name")
useCustomModalForDetails(actionName) {
return ["change_theme", "delete_theme"].includes(actionName);
}
});
StaffActionLog.reopenClass({
create(attrs) {
2013-10-30 01:01:42 +08:00
attrs = attrs || {};
2013-09-11 09:21:16 +08:00
if (attrs.acting_user) {
attrs.acting_user = AdminUser.create(attrs.acting_user);
}
if (attrs.target_user) {
attrs.target_user = AdminUser.create(attrs.target_user);
}
return this._super(attrs);
},
findAll(data) {
return ajax("/admin/logs/staff_action_logs.json", { data }).then(result => {
return {
2018-06-15 23:03:24 +08:00
staff_action_logs: result.staff_action_logs.map(s =>
StaffActionLog.create(s)
),
user_history_actions: result.user_history_actions
};
});
}
});
export default StaffActionLog;