From e724a7ee698d5e031b0eb41b64af757e731d26db Mon Sep 17 00:00:00 2001 From: Kris Date: Thu, 2 Feb 2023 02:11:53 -0500 Subject: [PATCH] UX: class for small posts when assigns are private (#400) The goal is to add a class so when assigns are not public, their descriptions can be styled similar to whispers... this is a light way to reassure admins of assign message visibility. --- .../initializers/extend-for-assigns.js | 6 ++++++ assets/stylesheets/assigns.scss | 8 ++++++++ spec/system/assign_topic_spec.rb | 18 ++++++++++++++++++ spec/system/page_objects/pages/topic.rb | 5 ++++- 4 files changed, 36 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js index 90a4cc6..c99d6de 100644 --- a/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js +++ b/assets/javascripts/discourse-assign/initializers/extend-for-assigns.js @@ -489,6 +489,12 @@ function initialize(api) { } } + api.addPostSmallActionClassesCallback((post) => { + if (post.actionCode.includes("assigned") && !siteSettings.assigns_public) { + return ["private-assign"]; + } + }); + api.addAdvancedSearchOptions( api.getCurrentUser() && api.getCurrentUser().can_assign ? { diff --git a/assets/stylesheets/assigns.scss b/assets/stylesheets/assigns.scss index f4339c9..2ad414f 100644 --- a/assets/stylesheets/assigns.scss +++ b/assets/stylesheets/assigns.scss @@ -258,3 +258,11 @@ } } } + +.private-assign { + // when assigns are not public, make the description look like a whisper + .small-action-custom-message { + font-style: italic; + color: var(--primary-medium); + } +} diff --git a/spec/system/assign_topic_spec.rb b/spec/system/assign_topic_spec.rb index 455af25..4ece85c 100644 --- a/spec/system/assign_topic_spec.rb +++ b/spec/system/assign_topic_spec.rb @@ -30,6 +30,24 @@ describe "Assign | Assigning topics", type: :system, js: true do expect(page).to have_no_css("#topic .assigned-to") end + context "when assigns are not public" do + before { SiteSetting.assigns_public = false } + + it "assigned small action post has 'private-assign' in class attribute" do + visit "/t/#{topic.id}" + + topic_page.click_assign_topic + assign_modal.assignee = staff_user + assign_modal.confirm + + expect(topic_page).to have_assigned( + user: staff_user, + at_post: 2, + class_attribute: ".private-assign", + ) + end + end + context "when unassign_on_close is set to true" do before { SiteSetting.unassign_on_close = true } diff --git a/spec/system/page_objects/pages/topic.rb b/spec/system/page_objects/pages/topic.rb index ab85b61..fe70463 100644 --- a/spec/system/page_objects/pages/topic.rb +++ b/spec/system/page_objects/pages/topic.rb @@ -27,7 +27,10 @@ module PageObjects def has_assignment_action?(args) assignee = args[:group]&.name || args[:user]&.username - container = args[:at_post] ? find("#post_#{args[:at_post]}") : page + + container = + args[:at_post] ? find("#post_#{args[:at_post]}#{args[:class_attribute] || ""}") : page + container.has_content?( I18n.t("js.action_codes.#{args[:action]}", who: "@#{assignee}", when: "just now"), )