2018-05-17 12:09:27 -04:00
|
|
|
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 11:03:24 -04:00
|
|
|
return value
|
|
|
|
? `<b>${I18n.t(label)}</b>: ${escape ? escapeExpression(value) : value}`
|
|
|
|
: "";
|
|
|
|
}
|
2015-11-20 20:27:06 -05:00
|
|
|
|
|
|
|
const StaffActionLog = Discourse.Model.extend({
|
2013-08-07 16:04:12 -04:00
|
|
|
showFullDetails: false,
|
|
|
|
|
2018-05-17 12:09:27 -04:00
|
|
|
@computed("action_name")
|
|
|
|
actionName(actionName) {
|
|
|
|
return I18n.t(`admin.logs.staff_actions.actions.${actionName}`);
|
|
|
|
},
|
|
|
|
|
2018-06-15 11:03:24 -04: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;
|
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
|
|
|
},
|
|
|
|
|
2018-05-17 12:09:27 -04:00
|
|
|
@computed("details")
|
|
|
|
useModalForDetails(details) {
|
|
|
|
return details && details.length > 100;
|
|
|
|
},
|
2013-08-21 12:33:05 -04:00
|
|
|
|
2018-05-17 12:09:27 -04:00
|
|
|
@computed("action_name")
|
|
|
|
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({
|
2018-05-17 12:09:27 -04:00
|
|
|
create(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);
|
|
|
|
},
|
|
|
|
|
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;
|