0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-12 05:37:26 +08:00
discourse/plugins/automation/admin/assets/javascripts/admin/initializers/discourse-automation.js
Joffrey JAFFEUX 0587515a45
FIX: append by should work for non admin (#38567)
The backend only checks for `guardian.ensure_can_edit!(post)` and not
admin. However the initialiser was under admin folder, meaning the click
would only work for admins, even though they could have made the http
request directly.
2026-03-13 00:38:55 +01:00

30 lines
881 B
JavaScript
Vendored

import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { makeArray } from "discourse/lib/helpers";
import { withPluginApi } from "discourse/lib/plugin-api";
function _initializeGLobalUserNotices(api) {
const currentUser = api.getCurrentUser();
makeArray(currentUser?.global_notices).forEach((userGlobalNotice) => {
api.addGlobalNotice("", userGlobalNotice.identifier, {
html: userGlobalNotice.notice,
level: userGlobalNotice.level,
dismissable: true,
dismissDuration: moment.duration(1, "week"),
onDismiss() {
ajax(`/user-global-notices/${userGlobalNotice.id}.json`, {
type: "DELETE",
}).catch(popupAjaxError);
},
});
});
}
export default {
name: "discourse-automation",
initialize() {
withPluginApi(_initializeGLobalUserNotices);
},
};