A platform for community discussion. Free, open, simple.
UX: don't show shared issue button on deleted, disable for closed (#41351)
Krisfe260189db49
diff --git a/plugins/discourse-solved/assets/javascripts/discourse/components/solved-shared-issue-button.gjs b/plugins/discourse-solved/assets/javascripts/discourse/components/solved-shared-issue-button.gjsindex 806876a7fe8..9c779490fc5 100644--- a/plugins/discourse-solved/assets/javascripts/discourse/components/solved-shared-issue-button.gjs+++ b/plugins/discourse-solved/assets/javascripts/discourse/components/solved-shared-issue-button.gjs@@ -37,8 +37,31 @@ export default class SolvedSharedIssueButton extends Component {return this.currentUser && this.currentUser.id === this.args.post.user_id;}+ get isClosed() {+ return this.args.post.topic.closed;+ }++ get isArchived() {+ return this.args.post.topic.archived;+ }+get disabled() {- return this.saving || this.isTopicAuthor;+ return (+ this.saving || this.isTopicAuthor || this.isClosed || this.isArchived+ );+ }++ get titleKey() {+ if (this.isTopicAuthor) {+ return "solved.shared_issue.author_title";+ }+ if (this.isClosed) {+ return "solved.shared_issue.closed_title";+ }+ if (this.isArchived) {+ return "solved.shared_issue.archived_title";+ }+ return "solved.shared_issue.title";}get label() {@@ -54,7 +77,7 @@ export default class SolvedSharedIssueButton extends Component {@actionasync toggle() {- if (this.isTopicAuthor) {+ if (this.isTopicAuthor || this.isClosed || this.isArchived) {return;}@@ -89,18 +112,14 @@ export default class SolvedSharedIssueButton extends Component {"btn-default""post-action-menu__solved-shared-issue"(if this.hasSharedIssue "has-shared-issue")- (if this.isTopicAuthor "disabled")+ (if this.disabled "disabled")}}...attributes@action={{this.toggle}}@disabled={{this.disabled}}@icon="hand"@translatedLabel={{this.label}}- @title={{if- this.isTopicAuthor- "solved.shared_issue.author_title"- "solved.shared_issue.title"- }}+ @title={{this.titleKey}}/></div>{{/if}}diff --git a/plugins/discourse-solved/config/locales/client.en.yml b/plugins/discourse-solved/config/locales/client.en.ymlindex e7c9c220d31..14c872226a0 100644--- a/plugins/discourse-solved/config/locales/client.en.yml+++ b/plugins/discourse-solved/config/locales/client.en.yml@@ -64,6 +64,8 @@ en:label_with_count: "%{label} (%{count})"title: "I am also experiencing this issue"author_title: "You started this topic"+ closed_title: "This topic is closed"+ archived_title: "This topic is archived"no_answer:title: Has your question been answered?diff --git a/plugins/discourse-solved/lib/discourse_solved/guardian_extensions.rb b/plugins/discourse-solved/lib/discourse_solved/guardian_extensions.rbindex d87438c545a..405aa4e4fe1 100644--- a/plugins/discourse-solved/lib/discourse_solved/guardian_extensions.rb+++ b/plugins/discourse-solved/lib/discourse_solved/guardian_extensions.rb@@ -57,6 +57,7 @@ module DiscourseSolvedreturn false if topic.blank? || !authenticated?return false if topic.user_id == current_user.idreturn false if topic.private_message?+ return false if topic.trashed? || topic.closed? || topic.archived?return false if topic.solved.present? && !SiteSetting.solved_allow_multiple_solutionsreturn false unless topic_in_support_category?(topic)return false unless shared_issues_enabled_for_category?(topic)@@ -67,6 +68,7 @@ module DiscourseSolveddef shared_issue_visible?(topic)return false if topic.blank?return false if topic.private_message?+ return false if topic.trashed?return false unless topic_in_support_category?(topic)return false unless shared_issues_enabled_for_category?(topic)unless UpcomingChanges.enabled_for_user?(:enable_solved_shared_issues, current_user)diff --git a/plugins/discourse-solved/spec/requests/discourse_solved/shared_issue_controller_spec.rb b/plugins/discourse-solved/spec/requests/discourse_solved/shared_issue_controller_spec.rbindex a8e487ca93b..89465b5c52e 100644--- a/plugins/discourse-solved/spec/requests/discourse_solved/shared_issue_controller_spec.rb+++ b/plugins/discourse-solved/spec/requests/discourse_solved/shared_issue_controller_spec.rb@@ -64,6 +64,18 @@ RSpec.describe DiscourseSolved::SharedIssueController doexpect(response.status).to eq(403)end+ it "rejects when the topic is closed" do+ topic.update!(closed: true)+ post "/solution/shared_issue.json", params: { topic_id: topic.id }+ expect(response.status).to eq(403)+ end++ it "rejects when the topic is archived" do+ topic.update!(archived: true)+ post "/solution/shared_issue.json", params: { topic_id: topic.id }+ expect(response.status).to eq(403)+ end+it "returns 404 for unknown topic" dopost "/solution/shared_issue.json", params: { topic_id: -1 }expect(response.status).to eq(404)diff --git a/plugins/discourse-solved/spec/system/shared_issue_spec.rb b/plugins/discourse-solved/spec/system/shared_issue_spec.rbindex f59f3cee059..28001ca6031 100644--- a/plugins/discourse-solved/spec/system/shared_issue_spec.rb+++ b/plugins/discourse-solved/spec/system/shared_issue_spec.rb@@ -114,6 +114,26 @@ describe "Solved | Shared issue button" doexpect(shared_issue_button).to have_no_shared_issue_buttonend+ it "shows the button as read-only when the topic is closed" do+ topic.update!(closed: true)++ sign_in(member)+ topic_page.visit_topic(topic)++ expect(shared_issue_button).to have_shared_issue_button+ expect(shared_issue_button).to have_read_only+ end++ it "shows the button as read-only when the topic is archived" do+ topic.update!(archived: true)++ sign_in(member)+ topic_page.visit_topic(topic)++ expect(shared_issue_button).to have_shared_issue_button+ expect(shared_issue_button).to have_read_only+ end+it "shows the button as read-only for the topic author" dosign_in(author)topic_page.visit_topic(topic)