A platform for community discussion. Free, open, simple.
FEATURE: Add reviewable link to user notes (#36190)
Krzysztof Kotlarek8f17f477bb0b
diff --git a/plugins/discourse-user-notes/app/controllers/discourse_user_notes/user_notes_controller.rb b/plugins/discourse-user-notes/app/controllers/discourse_user_notes/user_notes_controller.rbindex 21171bf76b3..2f781341af3 100644--- a/plugins/discourse-user-notes/app/controllers/discourse_user_notes/user_notes_controller.rb+++ b/plugins/discourse-user-notes/app/controllers/discourse_user_notes/user_notes_controller.rb@@ -21,6 +21,9 @@ module DiscourseUserNotesif post_id = params[:user_note][:post_id]extras[:post_id] = post_idend+ if reviewable_id = params[:user_note][:reviewable_id]+ extras[:reviewable_id] = reviewable_id+ enduser_note =DiscourseUserNotes.add_note(user, params[:user_note][:raw], current_user.id, extras)diff --git a/plugins/discourse-user-notes/app/serializers/user_note_serializer.rb b/plugins/discourse-user-notes/app/serializers/user_note_serializer.rbindex a578ad7103a..76247a27603 100644--- a/plugins/discourse-user-notes/app/serializers/user_note_serializer.rb+++ b/plugins/discourse-user-notes/app/serializers/user_note_serializer.rb@@ -11,6 +11,7 @@ class ::UserNoteSerializer < ApplicationSerializer:post_id,:post_url,:post_title,+ :reviewable_id,)def id@@ -57,4 +58,8 @@ class ::UserNoteSerializer < ApplicationSerializerdef topic_idobject[:topic_id]end++ def reviewable_id+ object[:reviewable_id]+ endenddiff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/components/user-note.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/components/user-note.gjsindex 930ffab6d60..c93763566be 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/components/user-note.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/components/user-note.gjs@@ -1,4 +1,5 @@import { fn } from "@ember/helper";+import { LinkTo } from "@ember/routing";import CookText from "discourse/components/cook-text";import DButton from "discourse/components/d-button";import PluginOutlet from "discourse/components/plugin-outlet";@@ -23,15 +24,22 @@ const UserNote = <template><div class="note-info"><span class="username">{{@note.created_by.username}}</span><span class="post-date">{{ageWithTooltip @note.created_at}}</span>+ {{#if @note.reviewable_id}}+ <LinkTo+ @route="review.show"+ @model={{@note.reviewable_id}}+ class="btn btn-small btn-default show-reviewable"+ >+ {{i18n "user_notes.show_reviewable"}}+ </LinkTo>+ {{/if}}{{#if @note.can_delete}}- <span class="controls">- <DButton- @action={{fn @removeNote @note}}- @icon="far-trash-can"- @title="user_notes.remove"- class="btn-small btn-danger"- />- </span>+ <DButton+ @action={{fn @removeNote @note}}+ @icon="far-trash-can"+ @title="user_notes.remove"+ class="btn-small btn-danger"+ />{{/if}}</div>diff --git a/plugins/discourse-user-notes/assets/javascripts/discourse/initializers/enable-user-notes.gjs b/plugins/discourse-user-notes/assets/javascripts/discourse/initializers/enable-user-notes.gjsindex 793ad359845..a363af255ee 100644--- a/plugins/discourse-user-notes/assets/javascripts/discourse/initializers/enable-user-notes.gjs+++ b/plugins/discourse-user-notes/assets/javascripts/discourse/initializers/enable-user-notes.gjs@@ -130,6 +130,7 @@ function handleReviewableNoteCreation(api) {user_note: {user_id: reviewable.target_created_by.id,raw: data.content.trim(),+ reviewable_id: reviewable.id,},},});diff --git a/plugins/discourse-user-notes/assets/stylesheets/user_notes.scss b/plugins/discourse-user-notes/assets/stylesheets/user_notes.scssindex 78e99dc8e26..49273c890cc 100644--- a/plugins/discourse-user-notes/assets/stylesheets/user_notes.scss+++ b/plugins/discourse-user-notes/assets/stylesheets/user_notes.scss@@ -33,8 +33,18 @@}}- .controls {- float: right;+ .note-info {+ display: flex;+ justify-content: space-between;+ }++ .post-date {+ flex-grow: 1;+ margin-left: 0.5em;+ }++ .show-reviewable {+ margin-right: 0.5em;}}diff --git a/plugins/discourse-user-notes/config/locales/client.en.yml b/plugins/discourse-user-notes/config/locales/client.en.ymlindex 43610ac799b..89b251c9f18 100644--- a/plugins/discourse-user-notes/config/locales/client.en.yml+++ b/plugins/discourse-user-notes/config/locales/client.en.yml@@ -8,4 +8,5 @@ en:show: "User Notes (%{count})"delete_confirm: "Are you sure you want to delete that user note?"show_post: "Show Post"+ show_reviewable: "Show Reviewable"copy_reviewable_note: "Copy note to %{username}'s profile?"diff --git a/plugins/discourse-user-notes/spec/system/reviewable_user_notes_spec.rb b/plugins/discourse-user-notes/spec/system/reviewable_user_notes_spec.rbnew file mode 100644index 00000000000..e69e35cc8a0--- /dev/null+++ b/plugins/discourse-user-notes/spec/system/reviewable_user_notes_spec.rb@@ -0,0 +1,61 @@+# frozen_string_literal: true++RSpec.describe "Reviewable User Notes", type: :system do+ fab!(:admin)+ fab!(:user)+ fab!(:reviewable_flagged_post)++ let(:review_page) { PageObjects::Pages::RefreshedReview.new }+ let(:review_note_form) { PageObjects::Components::ReviewNoteForm.new }+ let(:user_notes_modal) { PageObjects::Modals::Base.new }++ before do+ SiteSetting.user_notes_enabled = true+ SiteSetting.reviewable_ui_refresh = "staff"+ sign_in(admin)+ end++ it "copies reviewable note to user notes with reviewable_id when checkbox is checked" do+ review_page.visit_reviewable(reviewable_flagged_post)+ review_page.click_timeline_tab++ review_note_form.form.fill_in("content", with: "This user needs attention")+ review_note_form.form.field("copy_note_to_user").toggle+ review_note_form.form.submit++ expect(page).to have_text("This user needs attention")++ visit(+ "/admin/users/#{reviewable_flagged_post.target_created_by.id}/#{reviewable_flagged_post.target_created_by.username}",+ )++ click_button(class: "show-user-notes-btn")++ expect(user_notes_modal).to be_open+ expect(user_notes_modal).to have_content("This user needs attention")++ expect(user_notes_modal).to have_link(+ I18n.t("js.user_notes.show_reviewable"),+ href: "/review/#{reviewable_flagged_post.id}",+ )+ end++ it "does not display reviewable link for regular user notes without reviewable_id" do+ visit("/admin/users/#{user.id}/#{user.username}")++ click_button(class: "show-user-notes-btn")+ expect(user_notes_modal).to be_open++ form = PageObjects::Components::FormKit.new(".user-notes-modal .form-kit")+ form.field("content").fill_in("Regular note without reviewable")+ form.submit++ expect(user_notes_modal).to be_open+ expect(user_notes_modal).to have_content("Regular note without reviewable")++ expect(user_notes_modal).not_to have_link(+ I18n.t("js.user_notes.show_reviewable"),+ href: "/review/#{reviewable_flagged_post.id}",+ )+ end+end