2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2018-05-18 00:09:27 +08:00
|
|
|
import { ajax } from "discourse/lib/ajax";
|
|
|
|
import AdminUser from "admin/models/admin-user";
|
|
|
|
import { escapeExpression } from "discourse/lib/utilities";
|
2019-08-14 01:55:05 +08:00
|
|
|
import RestModel from "discourse/models/rest";
|
2018-05-18 00:09:27 +08:00
|
|
|
|
|
|
|
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}`
|
|
|
|
: "";
|
|
|
|
}
|
2015-11-21 09:27:06 +08:00
|
|
|
|
2019-08-14 01:55:05 +08:00
|
|
|
const StaffActionLog = RestModel.extend({
|
2013-08-08 04:04:12 +08:00
|
|
|
showFullDetails: false,
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("action_name")
|
2018-05-18 00:09:27 +08:00
|
|
|
actionName(actionName) {
|
|
|
|
return I18n.t(`admin.logs.staff_actions.actions.${actionName}`);
|
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed(
|
2018-06-15 23:03:24 +08:00
|
|
|
"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;
|
2013-08-08 04:04:12 +08:00
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
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)
|
2018-05-18 00:09:27 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
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)
|
|
|
|
);
|
2013-11-01 22:47:03 +08:00
|
|
|
}
|
2013-08-20 04:58:38 +08:00
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
if (!useModalForDetails && details) {
|
|
|
|
lines = [...lines, ...escapeExpression(details).split("\n")];
|
2013-08-20 04:58:38 +08:00
|
|
|
}
|
2018-05-18 00:09:27 +08:00
|
|
|
|
|
|
|
const formatted = lines.filter(l => l.length > 0).join("<br/>");
|
|
|
|
return formatted.length > 0 ? formatted + "<br/>" : "";
|
2013-08-21 22:49:35 +08:00
|
|
|
},
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("details")
|
2018-05-18 00:09:27 +08:00
|
|
|
useModalForDetails(details) {
|
|
|
|
return details && details.length > 100;
|
|
|
|
},
|
2013-08-22 00:33:05 +08:00
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("action_name")
|
2018-05-18 00:09:27 +08:00
|
|
|
useCustomModalForDetails(actionName) {
|
|
|
|
return ["change_theme", "delete_theme"].includes(actionName);
|
|
|
|
}
|
2013-08-08 04:04:12 +08:00
|
|
|
});
|
|
|
|
|
2015-11-21 09:27:06 +08:00
|
|
|
StaffActionLog.reopenClass({
|
2019-08-14 01:55:05 +08:00
|
|
|
munge(json) {
|
|
|
|
if (json.acting_user) {
|
|
|
|
json.acting_user = AdminUser.create(json.acting_user);
|
2013-08-08 04:04:12 +08:00
|
|
|
}
|
2019-08-14 01:55:05 +08:00
|
|
|
if (json.target_user) {
|
|
|
|
json.target_user = AdminUser.create(json.target_user);
|
2013-08-08 04:04:12 +08:00
|
|
|
}
|
2019-08-14 01:55:05 +08:00
|
|
|
return json;
|
2013-08-08 04:04:12 +08:00
|
|
|
},
|
|
|
|
|
2018-05-18 00:09:27 +08:00
|
|
|
findAll(data) {
|
|
|
|
return ajax("/admin/logs/staff_action_logs.json", { data }).then(result => {
|
2017-05-30 23:25:42 +08:00
|
|
|
return {
|
2018-06-15 23:03:24 +08:00
|
|
|
staff_action_logs: result.staff_action_logs.map(s =>
|
|
|
|
StaffActionLog.create(s)
|
|
|
|
),
|
2018-05-18 00:09:27 +08:00
|
|
|
user_history_actions: result.user_history_actions
|
2017-05-30 23:25:42 +08:00
|
|
|
};
|
2013-08-08 04:04:12 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2015-11-21 09:27:06 +08:00
|
|
|
|
|
|
|
export default StaffActionLog;
|