UX: Hide "Create Tag" option if user cannot create tag. (#7723)

This commit is contained in:
Dan Ungureanu 2019-08-19 11:40:56 +03:00 committed by GitHub
parent 1a731dcff1
commit 0b1146add4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 22 deletions

View File

@ -1,3 +1,4 @@
import Category from "discourse/models/category";
import ComboBox from "select-kit/components/combo-box";
import TagsMixin from "select-kit/mixins/tags";
import { default as computed } from "ember-addons/ember-computed-decorators";
@ -51,6 +52,27 @@ export default ComboBox.extend(TagsMixin, {
);
},
@computed(
"computedValue",
"filter",
"collectionComputedContent.[]",
"hasReachedMaximum",
"hasReachedMinimum",
"categoryId"
)
shouldDisplayCreateRow() {
if (this.categoryId) {
const category = Category.findById(this.categoryId);
if (
(category.allowed_tags && category.allowed_tags.length > 0) ||
(category.allowed_tag_groups && category.allowed_tag_groups.length > 0)
) {
return category.allow_global_tags && this._super(...arguments);
}
}
return this._super(...arguments);
},
didInsertElement() {
this._super(...arguments);

View File

@ -34,7 +34,7 @@ class Site
def categories
@categories ||= begin
categories = Category
.includes(:uploaded_logo, :uploaded_background)
.includes(:uploaded_logo, :uploaded_background, :tags, :tag_groups)
.secured(@guardian)
.joins('LEFT JOIN topics t on t.id = categories.topic_id')
.select('categories.*, t.slug topic_slug')

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true
class CategorySerializer < BasicCategorySerializer
class CategorySerializer < SiteCategorySerializer
attributes :read_restricted,
:available_groups,
@ -18,9 +18,6 @@ class CategorySerializer < BasicCategorySerializer
:is_special,
:allow_badges,
:custom_fields,
:allowed_tags,
:allowed_tag_groups,
:allow_global_tags,
:topic_featured_link_allowed,
:search_priority,
:reviewable_by_group_name
@ -95,22 +92,6 @@ class CategorySerializer < BasicCategorySerializer
(user && CategoryUser.where(user: user, category: object).first.try(:notification_level))
end
def include_allowed_tags?
SiteSetting.tagging_enabled
end
def allowed_tags
object.tags.pluck(:name)
end
def include_allowed_tag_groups?
SiteSetting.tagging_enabled
end
def allowed_tag_groups
object.tag_groups.pluck(:name)
end
def custom_fields
object.custom_fields
end

View File

@ -0,0 +1,29 @@
# frozen_string_literal: true
class SiteCategorySerializer < BasicCategorySerializer
attributes :allowed_tags,
:allowed_tag_groups,
:allow_global_tags
def include_allowed_tags?
SiteSetting.tagging_enabled
end
def allowed_tags
object.tags.pluck(:name)
end
def include_allowed_tag_groups?
SiteSetting.tagging_enabled
end
def allowed_tag_groups
object.tag_groups.pluck(:name)
end
def include_allow_global_tags?
SiteSetting.tagging_enabled
end
end

View File

@ -34,7 +34,7 @@ class SiteSerializer < ApplicationSerializer
:shared_drafts_category_id
)
has_many :categories, serializer: BasicCategorySerializer, embed: :objects
has_many :categories, serializer: SiteCategorySerializer, embed: :objects
has_many :trust_levels, embed: :objects
has_many :archetypes, embed: :objects, serializer: ArchetypeSerializer
has_many :user_fields, embed: :objects, serializer: UserFieldSerializer