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