From 174f88ecae6b40339d026e1c997c3abdd7853d6c Mon Sep 17 00:00:00 2001 From: Juan David Martinez Date: Fri, 7 Mar 2025 14:57:00 -0500 Subject: [PATCH] added suggested changes --- .../initializers/extend-for-assigns.js | 31 +++++++++---------- spec/system/assign_post_spec.rb | 18 ++++++++--- spec/system/assign_topic_spec.rb | 12 +++++++ 3 files changed, 41 insertions(+), 20 deletions(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-assigns.js b/assets/javascripts/discourse/initializers/extend-for-assigns.js index 89c8818..5d9e2f6 100644 --- a/assets/javascripts/discourse/initializers/extend-for-assigns.js +++ b/assets/javascripts/discourse/initializers/extend-for-assigns.js @@ -480,11 +480,11 @@ function initialize(api) { } const icon = iconHTML(assignee.username ? "user-plus" : "group-plus"); let name; - if (siteSettings.prioritize_full_name_in_ux || !assignee.username) { - name = assignee.name; - } else { - name = assignee.username; - } + + name = + this.siteSettings.prioritize_full_name_in_ux || !assignee.username + ? assignee.name || assignee.username + : assignee.username; const tagName = params.tagName || "a"; const href = @@ -578,13 +578,13 @@ function initialize(api) { }) )}`; }; + let displayedName = ""; if (assignedToUser) { - if (this.siteSettings.prioritize_full_name_in_ux) { - displayedName = assignedToUser.name; - } else { - displayedName = assignedToUser.username; - } + this.siteSettings.prioritize_full_name_in_ux + ? assignedToUser.name || assignedToUser.username + : assignedToUser.username; + assigneeElements.push( h( "span.assignee", @@ -617,12 +617,11 @@ function initialize(api) { Object.keys(indirectlyAssignedTo).map((postId) => { const assignee = indirectlyAssignedTo[postId].assigned_to; const postNumber = indirectlyAssignedTo[postId].post_number; - if (this.siteSettings.prioritize_full_name_in_ux || !assignee.username) { - displayedName = assignee.name; - } else{ - displayedName = assignee.username; - } - + displayedName = + this.siteSettings.prioritize_full_name_in_ux || !assignee.username + ? assignee.name || assignee.username + : assignee.username; + assigneeElements.push( h("span.assignee", [ h( diff --git a/spec/system/assign_post_spec.rb b/spec/system/assign_post_spec.rb index 2114ccc..1359621 100644 --- a/spec/system/assign_post_spec.rb +++ b/spec/system/assign_post_spec.rb @@ -12,9 +12,6 @@ describe "Assign | Assigning posts", type: :system do before do SiteSetting.assign_enabled = true - # # The system tests in this file are flaky and auth token related so turning this on - # SiteSetting.verbose_auth_token_logging = true - sign_in(admin) end @@ -43,7 +40,7 @@ describe "Assign | Assigning posts", type: :system do expect(page).to have_no_css("#topic .assigned-to") end - it "can submit form with shortcut from texatea" do + it "can submit modal form with shortcuts" do visit "/t/#{topic.id}" topic_page.click_assign_post(post2) @@ -70,6 +67,19 @@ describe "Assign | Assigning posts", type: :system do expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.name) expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.name) end + + it "show the user's username if there is no name" do + visit "/t/#{topic.id}" + staff_user.name = nil + staff_user.save + staff_user.reload + + topic_page.click_assign_post(post2) + assign_modal.assignee = staff_user + assign_modal.confirm + expect(topic_page.find_post_assign(post1.post_number)).to have_content(staff_user.username) + expect(topic_page.find_post_assign(post2.post_number)).to have_content(staff_user.username) + end end context "when assigns are not public" do diff --git a/spec/system/assign_topic_spec.rb b/spec/system/assign_topic_spec.rb index 8bc143a..b2fa6f0 100644 --- a/spec/system/assign_topic_spec.rb +++ b/spec/system/assign_topic_spec.rb @@ -61,6 +61,18 @@ describe "Assign | Assigning topics", type: :system do assign_modal.confirm expect(find("#topic .assigned-to")).to have_content(staff_user.name) end + + it "show the user's username if there is no name" do + visit "/t/#{topic.id}" + staff_user.name = nil + staff_user.save + staff_user.reload + + topic_page.click_assign_topic + assign_modal.assignee = staff_user + assign_modal.confirm + expect(find("#topic .assigned-to")).to have_content(staff_user.name) + end end context "when assigns are not public" do