A platform for community discussion. Free, open, simple.
Revert "FEATURE: enable topic creation button for read only categorie… (#34334)
David Battersby0c4ea0324407
diff --git a/app/assets/javascripts/discourse/app/components/composer-container.gjs b/app/assets/javascripts/discourse/app/components/composer-container.gjsindex a206ba502cd..118b8db9834 100644--- a/app/assets/javascripts/discourse/app/components/composer-container.gjs+++ b/app/assets/javascripts/discourse/app/components/composer-container.gjs@@ -254,7 +254,6 @@ export default class ComposerContainer extends Component {disabled=this.composer.disableCategoryChooserscopedCategoryId=this.composer.scopedCategoryIdprioritizedCategoryId=this.composer.prioritizedCategoryId- readOnlyCategoryId=this.composer.readOnlyCategoryId}}/><PluginOutletdiff --git a/app/assets/javascripts/discourse/app/components/create-topic-button.gjs b/app/assets/javascripts/discourse/app/components/create-topic-button.gjsindex 194578adca8..fbd0d9ce9b1 100644--- a/app/assets/javascripts/discourse/app/components/create-topic-button.gjs+++ b/app/assets/javascripts/discourse/app/components/create-topic-button.gjs@@ -3,21 +3,45 @@ 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}}- <DButton- @action={{this.action}}- @icon="far-pen-to-square"- @label={{this.label}}- id="create-topic"- class={{this.btnClass}}- />+ <DButtonTooltip>+ <:button>+ <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}}<TopicDraftsDropdown @disabled={{false}} />diff --git a/app/assets/javascripts/discourse/app/components/d-navigation.gjs b/app/assets/javascripts/discourse/app/components/d-navigation.gjsindex 2257c9bdd0b..d1a785a599c 100644--- a/app/assets/javascripts/discourse/app/components/d-navigation.gjs+++ b/app/assets/javascripts/discourse/app/components/d-navigation.gjs@@ -5,6 +5,7 @@ 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,6 +118,35 @@ 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;@@ -196,7 +226,11 @@ export default class DNavigation extends Component {@actionclickCreateTopicButton() {- this.createTopic();+ if (this.categoryReadOnlyBanner) {+ this.dialog.alert({ message: htmlSafe(this.categoryReadOnlyBanner) });+ } else {+ this.createTopic();+ }}<template>@@ -300,7 +334,10 @@ 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/app/controllers/discovery/list.js b/app/assets/javascripts/discourse/app/controllers/discovery/list.jsindex fe9bf5f48bc..f352dc3b6cb 100644--- a/app/assets/javascripts/discourse/app/controllers/discovery/list.js+++ b/app/assets/javascripts/discourse/app/controllers/discovery/list.js@@ -164,13 +164,8 @@ export default class DiscoveryListController extends Controller {@actioncreateTopic() {- const readOnlyCategoryId = this.createTopicDisabled- ? this.model.category.id- : null;-this.composer.openNewTopic({category: this.createTopicTargetCategory,- readOnlyCategoryId,tags: [this.model.tag?.id, ...(this.model.additionalTags ?? [])].filter(Boolean).reject((t) => ["none", "all"].includes(t))diff --git a/app/assets/javascripts/discourse/app/helpers/category-link.js b/app/assets/javascripts/discourse/app/helpers/category-link.jsindex 1924fba3cef..c8061c1e96b 100644--- a/app/assets/javascripts/discourse/app/helpers/category-link.js+++ b/app/assets/javascripts/discourse/app/helpers/category-link.js@@ -231,11 +231,6 @@ export function defaultCategoryLinkRenderer(category, opts) {)}</span>`;}- if (opts.readOnly) {- const desc = i18n("category_row.read_only");- html += `<span class="read-only" aria-label="${desc}">${desc}</span>`;- }-if (href) {href = ` href="${href}" `;}diff --git a/app/assets/javascripts/discourse/app/models/composer.js b/app/assets/javascripts/discourse/app/models/composer.jsindex 1ae9a9288a5..6f9de3f22a7 100644--- a/app/assets/javascripts/discourse/app/models/composer.js+++ b/app/assets/javascripts/discourse/app/models/composer.js@@ -948,12 +948,10 @@ export default class Composer extends RestModel {});// We set the category id separately for topic templates on opening of composer- if (!opts.readOnlyCategoryId) {- this.set(- "categoryId",- opts.topicCategoryId || opts.categoryId || this.get("topic.category.id")- );- }+ this.set(+ "categoryId",+ opts.topicCategoryId || opts.categoryId || this.get("topic.category.id")+ );if (!this.categoryId && this.creatingTopic) {const categories = this.site.categories;diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.jsindex 289862d15e2..c9bdbc895eb 100644--- a/app/assets/javascripts/discourse/app/services/composer.js+++ b/app/assets/javascripts/discourse/app/services/composer.js@@ -118,7 +118,6 @@ export default class ComposerService extends Service {editReason = null;scopedCategoryId = null;prioritizedCategoryId = null;- readOnlyCategoryId = null;lastValidatedAt = null;isUploading = false;isProcessingUpload = false;@@ -1336,7 +1335,6 @@ export default class ComposerService extends Service {@param {Boolean} [opts.disableScopedCategory]@param {Number} [opts.categoryId] Sets `scopedCategoryId` and `categoryId` on the Composer model@param {Number} [opts.prioritizedCategoryId]- @param {Number} [opts.readOnlyCategoryId] Shows category as read-only in category chooser, with a read-only badge@param {Number} [opts.formTemplateId]@param {String} [opts.draftSequence]@param {Boolean} [opts.skipJumpOnSave] Option to skip navigating to the post when saved in this composer session@@ -1364,7 +1362,6 @@ export default class ComposerService extends Service {editReason: null,scopedCategoryId: null,prioritizedCategoryId: null,- readOnlyCategoryId: null,skipAutoSave: true,});@@ -1396,10 +1393,6 @@ export default class ComposerService extends Service {}}- if (opts.readOnlyCategoryId) {- this.set("readOnlyCategoryId", opts.readOnlyCategoryId);- }-// If we want a different draft than the current composer, close it and clear our model.if (composerModel &&@@ -1458,14 +1451,7 @@ export default class ComposerService extends Service {}@action- async openNewTopic({- title,- body,- category,- readOnlyCategoryId,- tags,- formTemplate,- } = {}) {+ async openNewTopic({ title, body, category, tags, formTemplate } = {}) {return this.open({prioritizedCategoryId: category?.id,topicCategoryId: category?.id,@@ -1477,7 +1463,6 @@ export default class ComposerService extends Service {draftKey: this.topicDraftKey,draftSequence: 0,locale: null,- readOnlyCategoryId,});}diff --git a/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.js b/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.jsindex ccd50dcb0ba..df8cfaf4c7c 100644--- a/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.js+++ b/app/assets/javascripts/discourse/tests/acceptance/category-banner-test.js@@ -50,12 +50,10 @@ acceptance("Category Banners", function (needs) {await visit("/c/test-read-only-with-banner");await click("#create-topic");- 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");+ assert.dom(".dialog-body").exists("pops up a modal");+ 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")diff --git a/app/assets/javascripts/discourse/tests/acceptance/tags-test.js b/app/assets/javascripts/discourse/tests/acceptance/tags-test.jsindex d3bd60df1ee..4104bdbfc9a 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 works when viewing staff-only tags", async function (assert) {+ test("new topic button is not available for 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").isEnabled();+ assert.dom("#create-topic").isDisabled();updateCurrentUser({ moderator: true });diff --git a/app/assets/javascripts/select-kit/addon/components/category-chooser.js b/app/assets/javascripts/select-kit/addon/components/category-chooser.jsindex 6e3ada75186..2d16ea3e2a8 100644--- a/app/assets/javascripts/select-kit/addon/components/category-chooser.js+++ b/app/assets/javascripts/select-kit/addon/components/category-chooser.js@@ -21,7 +21,6 @@ import { pluginApiIdentifiers, selectKitOptions } from "./select-kit";excludeCategoryId: null,scopedCategoryId: null,prioritizedCategoryId: null,- readOnlyCategoryId: null,})@pluginApiIdentifiers(["category-chooser"])export default class CategoryChooser extends ComboBoxComponent {@@ -56,8 +55,6 @@ export default class CategoryChooser extends ComboBoxComponent {null,htmlSafe(i18n(isString ? this.selectKit.options.none : "category.none")));- } else if (this.selectKit.options.readOnlyCategoryId) {- return this.defaultItem(null, htmlSafe(i18n("category.choose")));} else if (this.selectKit.options.allowUncategorized) {return Category.findUncategorized();} else {@@ -99,7 +96,6 @@ export default class CategoryChooser extends ComboBoxComponent {rejectCategoryIds: [this.selectKit.options.excludeCategoryId],scopedCategoryId: this.selectKit.options.scopedCategoryId,prioritizedCategoryId: this.selectKit.options.prioritizedCategoryId,- readOnlyCategoryId: this.selectKit.options.readOnlyCategoryId,});}@@ -127,13 +123,11 @@ export default class CategoryChooser extends ComboBoxComponent {@computed("selectKit.filter","selectKit.options.scopedCategoryId",- "selectKit.options.prioritizedCategoryId",- "selectKit.options.readOnlyCategoryId"+ "selectKit.options.prioritizedCategoryId")get content() {if (!this.selectKit.filter) {- let { scopedCategoryId, prioritizedCategoryId, readOnlyCategoryId } =- this.selectKit.options;+ let { scopedCategoryId, prioritizedCategoryId } = this.selectKit.options;if (scopedCategoryId) {return this.categoriesByScope({ scopedCategoryId });@@ -142,10 +136,6 @@ export default class CategoryChooser extends ComboBoxComponent {if (prioritizedCategoryId) {return this.categoriesByScope({ prioritizedCategoryId });}-- if (readOnlyCategoryId) {- return this.categoriesByScope({ readOnlyCategoryId });- }}return this.categoriesByScope();@@ -154,7 +144,6 @@ export default class CategoryChooser extends ComboBoxComponent {categoriesByScope({scopedCategoryId = null,prioritizedCategoryId = null,- readOnlyCategoryId = null,} = {}) {const categories = this.fixedCategoryPositionsOnCreate? Category.list()@@ -175,10 +164,6 @@ export default class CategoryChooser extends ComboBoxComponent {let scopedCategories = categories.filter((category) => {const categoryId = this.getValue(category);- if (readOnlyCategoryId === categoryId) {- return true;- }-if (scopedCategoryId &&categoryId !== scopedCategoryId &&diff --git a/app/assets/javascripts/select-kit/addon/components/category-row.gjs b/app/assets/javascripts/select-kit/addon/components/category-row.gjsindex 688fe62c977..f62e34b37b9 100644--- a/app/assets/javascripts/select-kit/addon/components/category-row.gjs+++ b/app/assets/javascripts/select-kit/addon/components/category-row.gjs@@ -31,18 +31,6 @@ export default class CategoryRow extends Component {return this.rowValue === this.args.value;}- get isReadOnly() {- if (!this.readOnlyCategoryId) {- return false;- }-- return this.rowValue === this.readOnlyCategoryId;- }-- get readOnlyCategoryId() {- return this.args.selectKit.options.readOnlyCategoryId;- }-get hideParentCategory() {return this.args.selectKit.options.hideParentCategory;}@@ -126,7 +114,6 @@ export default class CategoryRow extends Component {subcategoryCount: this.args.item?.category? this.category.subcategory_count: 0,- readOnly: this.isReadOnly,}));}@@ -200,11 +187,6 @@ export default class CategoryRow extends Component {handleClick(event) {event.preventDefault();event.stopPropagation();-- if (this.isReadOnly) {- return false;- }-this.args.selectKit.select(this.rowValue, this.args.item);return false;}@@ -243,16 +225,11 @@ export default class CategoryRow extends Component {event.preventDefault();} else if (event.key === "Enter") {event.stopImmediatePropagation();- event.preventDefault();-- if (this.isReadOnly) {- return false;- }-this.args.selectKit.select(this.args.selectKit.highlighted.id,this.args.selectKit.highlighted);+ event.preventDefault();} else if (event.key === "Escape") {this.args.selectKit.close(event);this.args.selectKit.headerElement().focus();diff --git a/app/assets/stylesheets/common/select-kit/category-row.scss b/app/assets/stylesheets/common/select-kit/category-row.scssindex de91ba84790..264405cd9b5 100644--- a/app/assets/stylesheets/common/select-kit/category-row.scss+++ b/app/assets/stylesheets/common/select-kit/category-row.scss@@ -24,14 +24,5 @@.topic-count {white-space: nowrap;}-- .read-only {- padding: 0.2em 0.5em;- margin: 0 0 0.25em 0.5em;- border-radius: 8px;- color: var(--secondary);- font-size: var(--font-down-1);- background: var(--primary-low-mid);- }}}diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex b2abebfd27b..31f416a77cf 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -2812,7 +2812,6 @@ en:topic_count:one: "%{count} topic in this category"other: "%{count} topics in this category"- read_only: "read-only"timezone_input:ambiguous_ist: "IST is ambiguous, please select a specific timezone (eg: Asia/Kolkata)"@@ -3582,6 +3581,8 @@ en:one: "%{count} post in topic"other: "%{count} posts in topic"create: "New Topic"+ create_disabled_category: "You're not allowed to create topics in this category"+ create_disabled_tag: "You're not allowed to create topics with this tag"create_long: "Create a new Topic"open_draft: "Open Draft"private_message: "Start a message"diff --git a/spec/system/composer/default_to_subcategory_spec.rb b/spec/system/composer/default_to_subcategory_spec.rbindex bb6eee9819f..83e289d3d23 100644--- a/spec/system/composer/default_to_subcategory_spec.rb+++ b/spec/system/composer/default_to_subcategory_spec.rb@@ -41,15 +41,9 @@ 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 enabled and no category set in the composer" do+ it "should have the 'New Topic' button disabled" docategory_page.visit(category_with_no_subcategory)- 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_name("category…")+ expect(category_page).to have_button("New Topic", disabled: true)endendend@@ -72,14 +66,9 @@ 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 "opens composer with no category selected" do+ it "should have the 'New Topic' button disabled" docategory_page.visit(category_with_no_subcategory)- 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_name("category…")+ expect(category_page).to have_button("New Topic", disabled: true)endendend@@ -98,18 +87,10 @@ describe "Default to Subcategory when parent Category doesn't allow posting", tyenddescribe "Setting disabled and can't post on parent category" do- before do- SiteSetting.default_subcategory_on_read_only_category = false- SiteSetting.default_composer_category = default_latest_category.id- end-- it "opens composer with no category selected" do+ before { SiteSetting.default_subcategory_on_read_only_category = false }+ it "should have 'New Topic' button disabled" docategory_page.visit(category)- 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("category…")+ expect(category_page).to have_button("New Topic", disabled: true)endendenddiff --git a/spec/system/drafts_dropdown_spec.rb b/spec/system/drafts_dropdown_spec.rbindex 2583ec58838..7cd37aeaf3d 100644--- a/spec/system/drafts_dropdown_spec.rb+++ b/spec/system/drafts_dropdown_spec.rb@@ -2,7 +2,6 @@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 }@@ -111,10 +110,10 @@ describe "Drafts dropdown", type: :system do)end- it "is still enabled" do+ it "disables the drafts dropdown menu when new topic button is disabled" docategory_page.visit(category)- expect(category_page).to have_button("New Topic", disabled: false)+ expect(category_page).to have_button("New Topic", disabled: true)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 25cdbb6101f..c168b64fe19 100644--- a/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs+++ b/themes/horizon/javascripts/discourse/components/sidebar-new-topic-button.gjs@@ -5,7 +5,7 @@ import didInsert from "@ember/render-modifiers/modifiers/did-insert";import didUpdate from "@ember/render-modifiers/modifiers/did-update";import willDestroy from "@ember/render-modifiers/modifiers/will-destroy";import { service } from "@ember/service";-import { gt } from "truth-helpers";+import { gt, not } from "truth-helpers";import CreateTopicButton from "discourse/components/create-topic-button";export default class SidebarNewTopicButton extends Component {@@ -41,6 +41,30 @@ 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 });@@ -80,8 +104,10 @@ export default class SidebarNewTopicButton extends Component {<CreateTopicButton@canCreateTopic={{this.canCreateTopic}}@action={{this.createNewTopic}}+ @disabled={{this.createTopicDisabled}}@label="topic.create"- @btnClass="btn-default sidebar-new-topic-button"+ @btnClass={{this.createTopicClass}}+ @canCreateTopicOnTag={{not this.tagRestricted}}@showDrafts={{gt this.draftCount 0}}/></div>diff --git a/themes/horizon/spec/system/sidebar_topic_button_spec.rb b/themes/horizon/spec/system/sidebar_topic_button_spec.rbindex 54c2155e565..875612401e7 100644--- a/themes/horizon/spec/system/sidebar_topic_button_spec.rb+++ b/themes/horizon/spec/system/sidebar_topic_button_spec.rb@@ -34,10 +34,10 @@ RSpec.describe "Sidebar New Topic Button", system: true doexpect(page).to have_css(".sidebar-new-topic-button__wrapper .topic-drafts-menu-trigger")end- it "does not disable button when visiting read-only category" do+ it "disables button when visiting read-only category" dovisit("/c/#{private_category.slug}/#{private_category.id}")- expect(page).to have_no_css(".sidebar-new-topic-button[disabled]")+ expect(page).to have_css(".sidebar-new-topic-button[disabled]")visit("/c/#{category.slug}/#{category.id}")