Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,6 @@ export default class ComposerContainer extends Component {
disabled=this.composer.disableCategoryChooser
scopedCategoryId=this.composer.scopedCategoryId
prioritizedCategoryId=this.composer.prioritizedCategoryId
readOnlyCategoryId=this.composer.readOnlyCategoryId
}}
/>
<PluginOutlet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}} />
Expand Down
39 changes: 38 additions & 1 deletion app/assets/javascripts/discourse/app/components/d-navigation.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -196,7 +226,11 @@ export default class DNavigation extends Component {

@action
clickCreateTopicButton() {
this.createTopic();
if (this.categoryReadOnlyBanner) {
this.dialog.alert({ message: htmlSafe(this.categoryReadOnlyBanner) });
} else {
this.createTopic();
}
}

<template>
Expand Down Expand Up @@ -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}}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,8 @@ export default class DiscoveryListController extends Controller {

@action
createTopic() {
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))
Expand Down
5 changes: 0 additions & 5 deletions app/assets/javascripts/discourse/app/helpers/category-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}" `;
}
Expand Down
10 changes: 4 additions & 6 deletions app/assets/javascripts/discourse/app/models/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 1 addition & 16 deletions app/assets/javascripts/discourse/app/services/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ export default class ComposerService extends Service {
editReason = null;
scopedCategoryId = null;
prioritizedCategoryId = null;
readOnlyCategoryId = null;
lastValidatedAt = null;
isUploading = false;
isProcessingUpload = false;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1364,7 +1362,6 @@ export default class ComposerService extends Service {
editReason: null,
scopedCategoryId: null,
prioritizedCategoryId: null,
readOnlyCategoryId: null,
skipAutoSave: true,
});

Expand Down Expand Up @@ -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 &&
Expand Down Expand Up @@ -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,
Expand All @@ -1477,7 +1463,6 @@ export default class ComposerService extends Service {
draftKey: this.topicDraftKey,
draftSequence: 0,
locale: null,
readOnlyCategoryId,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
});
}

Expand Down Expand Up @@ -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 });
Expand All @@ -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();
Expand All @@ -154,7 +144,6 @@ export default class CategoryChooser extends ComboBoxComponent {
categoriesByScope({
scopedCategoryId = null,
prioritizedCategoryId = null,
readOnlyCategoryId = null,
} = {}) {
const categories = this.fixedCategoryPositionsOnCreate
? Category.list()
Expand All @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -126,7 +114,6 @@ export default class CategoryRow extends Component {
subcategoryCount: this.args.item?.category
? this.category.subcategory_count
: 0,
readOnly: this.isReadOnly,
})
);
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
Loading
Loading