mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 06:33:55 +08:00
aab2987438
* FEATURE: Log tag group changes in staff action log This commit records every change (add, change, delete) to a tag group in the staff action log. It uses a modal that was originally called ThemeChangeModal to display changes, allowing staffs to see the specific changes clearly. The modal is renamed to StaffActionLogChangeModal in this PR. ref: https://meta.discourse.org/t/-/325011/14 Co-authored-by: Keegan George <kgeorge13@gmail.com>
116 lines
2.9 KiB
JavaScript
116 lines
2.9 KiB
JavaScript
import { ajax } from "discourse/lib/ajax";
|
|
import { escapeExpression } from "discourse/lib/utilities";
|
|
import RestModel from "discourse/models/rest";
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
|
import I18n from "discourse-i18n";
|
|
import AdminUser from "admin/models/admin-user";
|
|
|
|
function format(label, value, escape = true) {
|
|
return value
|
|
? `<b>${I18n.t(label)}</b>: ${escape ? escapeExpression(value) : value}`
|
|
: "";
|
|
}
|
|
|
|
export default class StaffActionLog extends RestModel {
|
|
static munge(json) {
|
|
if (json.acting_user) {
|
|
json.acting_user = AdminUser.create(json.acting_user);
|
|
}
|
|
if (json.target_user) {
|
|
json.target_user = AdminUser.create(json.target_user);
|
|
}
|
|
return json;
|
|
}
|
|
|
|
static findAll(data) {
|
|
return ajax("/admin/logs/staff_action_logs.json", { data }).then(
|
|
(result) => {
|
|
return {
|
|
staff_action_logs: result.staff_action_logs.map((s) =>
|
|
StaffActionLog.create(s)
|
|
),
|
|
user_history_actions: result.user_history_actions,
|
|
};
|
|
}
|
|
);
|
|
}
|
|
|
|
showFullDetails = false;
|
|
|
|
@discourseComputed("action_name")
|
|
actionName(actionName) {
|
|
return I18n.t(`admin.logs.staff_actions.actions.${actionName}`);
|
|
}
|
|
|
|
@discourseComputed(
|
|
"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;
|
|
|
|
const topicLink = topicId
|
|
? `<a href data-link-topic-id="${topicId}">${topicId}</a>`
|
|
: null;
|
|
|
|
let lines = [
|
|
format("email", email),
|
|
format("admin.logs.ip_address", ipAddress),
|
|
format("admin.logs.topic_id", topicLink, false),
|
|
format("admin.logs.post_id", postLink, false),
|
|
format("admin.logs.category_id", categoryId),
|
|
];
|
|
|
|
if (!useCustomModalForDetails) {
|
|
lines.push(format("admin.logs.staff_actions.new_value", newValue));
|
|
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/>" : "";
|
|
}
|
|
|
|
@discourseComputed("details")
|
|
useModalForDetails(details) {
|
|
return details && details.length > 100;
|
|
}
|
|
|
|
@discourseComputed("action_name")
|
|
useCustomModalForDetails(actionName) {
|
|
return [
|
|
"change_theme",
|
|
"delete_theme",
|
|
"tag_group_create",
|
|
"tag_group_destroy",
|
|
"tag_group_change",
|
|
].includes(actionName);
|
|
}
|
|
}
|