mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 10:12:32 +08:00
UX: Hide "Create Tag" option if user cannot create tag. (#7723)
This commit is contained in:
parent
1a731dcff1
commit
0b1146add4
|
@ -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);
|
||||
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
29
app/serializers/site_category_serializer.rb
Normal file
29
app/serializers/site_category_serializer.rb
Normal 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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user