A platform for community discussion. Free, open, simple.
FEATURE: create new topic while viewing restricted category or tag (#33495)
David Battersbye8bf70510453
diff --git a/app/assets/javascripts/discourse/app/components/create-topic-button.gjs b/app/assets/javascripts/discourse/app/components/create-topic-button.gjsindex f70364f98d1..0f1150ae9e4 100644--- a/app/assets/javascripts/discourse/app/components/create-topic-button.gjs+++ b/app/assets/javascripts/discourse/app/components/create-topic-button.gjs@@ -2,23 +2,13 @@ import Component from "@ember/component";import { tagName } from "@ember-decorators/component";import DButton from "discourse/components/d-button";import TopicDraftsDropdown from "discourse/components/topic-drafts-dropdown";-import { i18n } from "discourse-i18n";import DButtonTooltip from "float-kit/components/d-button-tooltip";-import DTooltip from "float-kit/components/d-tooltip";@tagName("")export default class CreateTopicButton extends Component {label = "topic.create";btnClass = "btn-default";- get disallowedReason() {- if (this.canCreateTopicOnTag === false) {- return "topic.create_disabled_tag";- } else if (this.disabled) {- return "topic.create_disabled_category";- }- }-<template>{{#if this.canCreateTopic}}<DButtonTooltip>@@ -26,20 +16,11 @@ export default class CreateTopicButton extends Component {<DButton@action={{this.action}}@icon="far-pen-to-square"- @disabled={{this.disabled}}@label={{this.label}}id="create-topic"class={{this.btnClass}}/></:button>- <:tooltip>- {{#if @disabled}}- <DTooltip- @icon="circle-info"- @content={{i18n this.disallowedReason}}- />- {{/if}}- </:tooltip></DButtonTooltip>{{#if @showDrafts}}diff --git a/app/assets/javascripts/discourse/app/components/d-navigation.gjs b/app/assets/javascripts/discourse/app/components/d-navigation.gjsindex 632379031a1..1689bfa6b1d 100644--- a/app/assets/javascripts/discourse/app/components/d-navigation.gjs+++ b/app/assets/javascripts/discourse/app/components/d-navigation.gjs@@ -4,7 +4,6 @@ import { hash } from "@ember/helper";import { action } from "@ember/object";import { dependentKeyCompat } from "@ember/object/compat";import { service } from "@ember/service";-import { htmlSafe } from "@ember/template";import { tagName } from "@ember-decorators/component";import { and, gt } from "truth-helpers";import BreadCrumbs from "discourse/components/bread-crumbs";@@ -117,35 +116,6 @@ export default class DNavigation extends Component {}}- @discourseComputed(- "createTopicDisabled",- "categoryReadOnlyBanner",- "canCreateTopicOnTag",- "tag.id"- )- createTopicButtonDisabled(- createTopicDisabled,- categoryReadOnlyBanner,- canCreateTopicOnTag,- tagId- ) {- if (tagId && !canCreateTopicOnTag) {- return true;- } else if (categoryReadOnlyBanner) {- return false;- }- return createTopicDisabled;- }-- @discourseComputed("categoryReadOnlyBanner")- createTopicClass(categoryReadOnlyBanner) {- let classNames = ["btn-default"];- if (categoryReadOnlyBanner) {- classNames.push("disabled");- }- return classNames.join(" ");- }-@discourseComputed("category.can_edit")showCategoryEdit(canEdit) {return canEdit;@@ -225,11 +195,7 @@ export default class DNavigation extends Component {@actionclickCreateTopicButton() {- if (this.categoryReadOnlyBanner) {- this.dialog.alert({ message: htmlSafe(this.categoryReadOnlyBanner) });- } else {- this.createTopic();- }+ this.createTopic();}<template>@@ -333,10 +299,7 @@ export default class DNavigation extends Component {<CreateTopicButton@canCreateTopic={{this.canCreateTopic}}@action={{this.clickCreateTopicButton}}- @disabled={{this.createTopicButtonDisabled}}@label={{this.createTopicLabel}}- @btnClass={{this.createTopicClass}}- @canCreateTopicOnTag={{this.canCreateTopicOnTag}}@showDrafts={{if (gt this.draftCount 0) true false}}/>diff --git a/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.js b/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.jsindex df8cfaf4c7c..a383e59a3a7 100644--- a/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.js@@ -50,11 +50,14 @@ acceptance("Category Banners", function (needs) {await visit("/c/test-read-only-with-banner");await click("#create-topic");- assert.dom(".dialog-body").exists("pops up a modal");+ assert.dom(".d-editor").exists("opens composer");++ assert+ .dom(".d-editor .selected-name[data-name='test-read-only-with-banner']")+ .doesNotExist("does not show read-only category in composer");- await click(".dialog-footer .btn-primary");- assert.dom(".dialog-body").doesNotExist("closes the modal");assert.dom(".category-read-only-banner").exists("shows a banner");+assert.dom(".category-read-only-banner .inner").exists({ count: 1 }, "allows staff to embed html in the message");diff --git a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js b/app/assets/javascripts/discourse/tests/acceptance/tags-test.jsindex ef2584810cb..177459f7c20 100644--- a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/tags-test.js@@ -228,14 +228,14 @@ acceptance("Tags listed by group", function (needs) {);});- test("new topic button is not available for staff-only tags", async function (assert) {+ test("new topic button works when viewing staff-only tags", async function (assert) {updateCurrentUser({ moderator: false, admin: false });await visit("/tag/regular-tag");assert.dom("#create-topic").isEnabled();await visit("/tag/staff-only-tag");- assert.dom("#create-topic").isDisabled();+ assert.dom("#create-topic").isEnabled();updateCurrentUser({ moderator: true });diff --git a/spec/system/composer/default_to_subcategory_spec.rb b/spec/system/composer/default_to_subcategory_spec.rbindex 83e289d3d23..272c80ad5fd 100644--- a/spec/system/composer/default_to_subcategory_spec.rb+++ b/spec/system/composer/default_to_subcategory_spec.rb@@ -41,9 +41,14 @@ describe "Default to Subcategory when parent Category doesn't allow posting", tyendenddescribe "Category does not have subcategory" do- it "should have the 'New Topic' button disabled" do+ it "should have the 'New Topic' button enabled and default category set in the composer" docategory_page.visit(category_with_no_subcategory)- expect(category_page).to have_button("New Topic", disabled: true)+ expect(category_page).to have_button("New Topic", disabled: false)++ category_page.new_topic_button.click+ select_kit =+ PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")+ expect(select_kit).to have_selected_value(default_latest_category.id)endendend@@ -66,9 +71,14 @@ describe "Default to Subcategory when parent Category doesn't allow posting", tyenddescribe "Can't post on parent category" dodescribe "Category does not have subcategory" do- it "should have the 'New Topic' button disabled" do+ it "opens composer without a preset topic" docategory_page.visit(category_with_no_subcategory)- expect(category_page).to have_button("New Topic", disabled: true)+ expect(category_page).to have_button("New Topic", disabled: false)+ category_page.find("#create-topic").click++ select_kit =+ PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")+ expect(select_kit).to have_selected_name("category…")endendend@@ -87,10 +97,18 @@ describe "Default to Subcategory when parent Category doesn't allow posting", tyenddescribe "Setting disabled and can't post on parent category" do- before { SiteSetting.default_subcategory_on_read_only_category = false }- it "should have 'New Topic' button disabled" do+ before do+ SiteSetting.default_subcategory_on_read_only_category = false+ SiteSetting.default_composer_category = default_latest_category.id+ end++ it "opens composer with default composer category selected" docategory_page.visit(category)- expect(category_page).to have_button("New Topic", disabled: true)+ expect(category_page).to have_button("New Topic", disabled: false)+ page.find("#create-topic").click++ select_kit = PageObjects::Components::SelectKit.new("#reply-control.open .category-chooser")+ expect(select_kit).to have_selected_name(default_latest_category.name)endendenddiff --git a/spec/system/drafts_dropdown_spec.rb b/spec/system/drafts_dropdown_spec.rbindex 7cd37aeaf3d..2583ec58838 100644--- a/spec/system/drafts_dropdown_spec.rb+++ b/spec/system/drafts_dropdown_spec.rb@@ -2,6 +2,7 @@describe "Drafts dropdown", type: :system dofab!(:user) { Fabricate(:user, refresh_auto_groups: true) }+ fab!(:category)let(:composer) { PageObjects::Components::Composer.new }let(:drafts_dropdown) { PageObjects::Components::DraftsMenu.new }let(:discard_draft_modal) { PageObjects::Modals::DiscardDraft.new }@@ -110,10 +111,10 @@ describe "Drafts dropdown", type: :system do)end- it "disables the drafts dropdown menu when new topic button is disabled" do+ it "is still enabled" docategory_page.visit(category)- expect(category_page).to have_button("New Topic", disabled: true)+ expect(category_page).to have_button("New Topic", disabled: false)expect(drafts_dropdown).to be_enabledendenddiff --git a/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs b/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjsindex c168b64fe19..6bac0c7ddcf 100644--- a/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs+++ b/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs@@ -41,30 +41,6 @@ export default class SidebarNewTopicButton extends Component {}}- get tagRestricted() {- return this.tag?.staff;- }-- get createTopicDisabled() {- return (- (this.category && !this.createTopicTargetCategory) ||- (this.tagRestricted && !this.currentUser.staff)- );- }-- get categoryReadOnlyBanner() {- if (this.category && this.currentUser && this.createTopicDisabled) {- return this.category.read_only_banner;- }- }-- get createTopicClass() {- const baseClasses = "btn-default sidebar-new-topic-button";- return this.categoryReadOnlyBanner- ? `${baseClasses} disabled`- : baseClasses;- }-@actioncreateNewTopic() {this.composer.openNewTopic({ category: this.category, tags: this.tag?.id });@@ -104,10 +80,8 @@ export default class SidebarNewTopicButton extends Component {<CreateTopicButton@canCreateTopic={{this.canCreateTopic}}@action={{this.createNewTopic}}- @disabled={{this.createTopicDisabled}}@label="topic.create"- @btnClass={{this.createTopicClass}}- @canCreateTopicOnTag={{not this.tagRestricted}}+ @btnClass="btn-default sidebar-new-topic-button"@showDrafts={{gt this.draftCount 0}}/></div>