Skip to content

A platform for community discussion. Free, open, simple.

FIX: append by should work for non admin (#38567)

Joffrey JAFFEUX0587515a4539
diff --git a/plugins/automation/admin/assets/javascripts/admin/initializers/discourse-automation.js b/plugins/automation/admin/assets/javascripts/admin/initializers/discourse-automation.js
index 2f012703b29..0316a66175e 100644
--- a/plugins/automation/admin/assets/javascripts/admin/initializers/discourse-automation.js
+++ b/plugins/automation/admin/assets/javascripts/admin/initializers/discourse-automation.js
@@ -3,36 +3,6 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
import { makeArray } from "discourse/lib/helpers";
import { withPluginApi } from "discourse/lib/plugin-api";
-function _handleLastCheckedByEvent(event) {
- ajax(`/append-last-checked-by/${event.currentTarget.postId}`, {
- type: "PUT",
- }).catch(popupAjaxError);
-}
-
-function _initializeDiscourseAutomation(api) {
- _initializeGLobalUserNotices(api);
-
- if (api.getCurrentUser()) {
- api.decorateCookedElement(_decorateCheckedButton, {
- id: "discourse-automation",
- });
- }
-}
-
-function _decorateCheckedButton(element, postDecorator) {
- if (!postDecorator) {
- return;
- }
-
- const elems = element.querySelectorAll(".btn-checked");
- const postModel = postDecorator.getModel();
-
- Array.from(elems).forEach((elem) => {
- elem.postId = postModel.id;
- elem.addEventListener("click", _handleLastCheckedByEvent, false);
- });
-}
-
function _initializeGLobalUserNotices(api) {
const currentUser = api.getCurrentUser();
@@ -55,6 +25,6 @@ export default {
name: "discourse-automation",
initialize() {
- withPluginApi(_initializeDiscourseAutomation);
+ withPluginApi(_initializeGLobalUserNotices);
},
};
diff --git a/plugins/automation/assets/javascripts/discourse/initializers/append-by-listener.js b/plugins/automation/assets/javascripts/discourse/initializers/append-by-listener.js
new file mode 100644
index 00000000000..e5e97570276
--- /dev/null
+++ b/plugins/automation/assets/javascripts/discourse/initializers/append-by-listener.js
@@ -0,0 +1,39 @@
+import { ajax } from "discourse/lib/ajax";
+import { popupAjaxError } from "discourse/lib/ajax-error";
+import { withPluginApi } from "discourse/lib/plugin-api";
+
+function _handleLastCheckedByEvent(event) {
+ ajax(`/append-last-checked-by/${event.currentTarget.postId}`, {
+ type: "PUT",
+ }).catch(popupAjaxError);
+}
+
+function _initializeAppendByListener(api) {
+ if (api.getCurrentUser()) {
+ api.decorateCookedElement(_decorateCheckedButton, {
+ id: "discourse-automation",
+ });
+ }
+}
+
+function _decorateCheckedButton(element, postDecorator) {
+ if (!postDecorator) {
+ return;
+ }
+
+ const elems = element.querySelectorAll(".btn-checked");
+ const postModel = postDecorator.getModel();
+
+ Array.from(elems).forEach((elem) => {
+ elem.postId = postModel.id;
+ elem.addEventListener("click", _handleLastCheckedByEvent, false);
+ });
+}
+
+export default {
+ name: "append-by-listener",
+
+ initialize() {
+ withPluginApi(_initializeAppendByListener);
+ },
+};