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

DEV: Add an option to copy reviewable notes when they're created. #128

Merged
merged 2 commits into from
Jul 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Component from "@glimmer/component";
import { i18n } from "discourse-i18n";

export default class CopyReviewableNoteToUserOption extends Component {
static shouldRender(args, context) {
return (
context.siteSettings.user_notes_enabled && context.currentUser?.staff
);
}

<template>
<@form.CheckboxGroup as |group|>
<group.Field
@name="copy_note_to_user"
@title={{i18n "user_notes.copy_reviewable_note"}}
@format="full"
as |field|
>
<field.Checkbox />
</group.Field>
</@form.CheckboxGroup>
</template>
}
35 changes: 35 additions & 0 deletions assets/javascripts/discourse/initializers/enable-user-notes.gjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import Component from "@glimmer/component";
import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import { withSilencedDeprecations } from "discourse/lib/deprecated";
import { iconNode } from "discourse/lib/icon-library";
import { withPluginApi } from "discourse/lib/plugin-api";
Expand All @@ -22,6 +24,7 @@ export default {
withPluginApi((api) => {
customizePost(api, container);
customizePostMenu(api, container);
handleReviewableNoteCreation(api);
});
},
};
Expand Down Expand Up @@ -192,3 +195,35 @@ function customizePostMenu(api, container) {
};
});
}

/**
* Optionally creates a user note when a reviewable note is created.
*
* @param {Object} api - Plugin API instance
*/
function handleReviewableNoteCreation(api) {
api.onAppEvent(
"reviewablenote:created",
async (data, reviewable, formApi) => {
if (!data.copy_note_to_user || !reviewable.target_created_by) {
return;
}

try {
await ajax("/user_notes", {
type: "POST",
data: {
user_note: {
user_id: reviewable.target_created_by.id,
raw: data.content.trim(),
},
},
});

formApi.set("copy_note_to_user", false);
} catch (error) {
popupAjaxError(error);
}
}
);
}
1 change: 1 addition & 0 deletions config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ en:
show: "User Notes (%{count})"
delete_confirm: "Are you sure you want to delete that user note?"
show_post: "Show Post"
copy_reviewable_note: "Copy note to user profile?"