Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Commit 75a54e6

Browse files
authored
DEV: Add an option to copy reviewable notes when they're created. (#128)
1 parent 7ec9719 commit 75a54e6

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Component from "@glimmer/component";
2+
import { i18n } from "discourse-i18n";
3+
4+
export default class CopyReviewableNoteToUserOption extends Component {
5+
static shouldRender(args, context) {
6+
return (
7+
context.siteSettings.user_notes_enabled && context.currentUser?.staff
8+
);
9+
}
10+
11+
<template>
12+
<@form.CheckboxGroup as |group|>
13+
<group.Field
14+
@name="copy_note_to_user"
15+
@title={{i18n "user_notes.copy_reviewable_note"}}
16+
@format="full"
17+
as |field|
18+
>
19+
<field.Checkbox />
20+
</group.Field>
21+
</@form.CheckboxGroup>
22+
</template>
23+
}

assets/javascripts/discourse/initializers/enable-user-notes.gjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Component from "@glimmer/component";
2+
import { ajax } from "discourse/lib/ajax";
3+
import { popupAjaxError } from "discourse/lib/ajax-error";
24
import { withSilencedDeprecations } from "discourse/lib/deprecated";
35
import { iconNode } from "discourse/lib/icon-library";
46
import { withPluginApi } from "discourse/lib/plugin-api";
@@ -22,6 +24,7 @@ export default {
2224
withPluginApi((api) => {
2325
customizePost(api, container);
2426
customizePostMenu(api, container);
27+
handleReviewableNoteCreation(api);
2528
});
2629
},
2730
};
@@ -192,3 +195,35 @@ function customizePostMenu(api, container) {
192195
};
193196
});
194197
}
198+
199+
/**
200+
* Optionally creates a user note when a reviewable note is created.
201+
*
202+
* @param {Object} api - Plugin API instance
203+
*/
204+
function handleReviewableNoteCreation(api) {
205+
api.onAppEvent(
206+
"reviewablenote:created",
207+
async (data, reviewable, formApi) => {
208+
if (!data.copy_note_to_user || !reviewable.target_created_by) {
209+
return;
210+
}
211+
212+
try {
213+
await ajax("/user_notes", {
214+
type: "POST",
215+
data: {
216+
user_note: {
217+
user_id: reviewable.target_created_by.id,
218+
raw: data.content.trim(),
219+
},
220+
},
221+
});
222+
223+
formApi.set("copy_note_to_user", false);
224+
} catch (error) {
225+
popupAjaxError(error);
226+
}
227+
}
228+
);
229+
}

config/locales/client.en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ en:
77
show: "User Notes (%{count})"
88
delete_confirm: "Are you sure you want to delete that user note?"
99
show_post: "Show Post"
10+
copy_reviewable_note: "Copy note to user profile?"

0 commit comments

Comments
 (0)