mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: increase tag description limit to 1000 (#24561)
Admin can add tag description up to 1000 characters. Full description is displayed on tag page, however on topic list it is truncated to 80 characters.
This commit is contained in:
parent
633deb5af8
commit
5551a71c55
@ -10,13 +10,17 @@
|
|||||||
@input={{action (mut this.newTagName) value="target.value"}}
|
@input={{action (mut this.newTagName) value="target.value"}}
|
||||||
@autofocus="true"
|
@autofocus="true"
|
||||||
/>
|
/>
|
||||||
<TextField
|
|
||||||
@id="edit-description"
|
<Textarea
|
||||||
|
id="edit-description"
|
||||||
@value={{readonly this.tagInfo.description}}
|
@value={{readonly this.tagInfo.description}}
|
||||||
@placeholder={{i18n "tagging.description"}}
|
placeholder={{i18n "tagging.description"}}
|
||||||
@maxlength={{280}}
|
maxlength={{1000}}
|
||||||
@input={{action (mut this.newTagDescription) value="target.value"}}
|
{{on
|
||||||
@autofocus="true"
|
"input"
|
||||||
|
(action (mut this.newTagDescription) value="target.value")
|
||||||
|
}}
|
||||||
|
autofocus="true"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="edit-controls">
|
<div class="edit-controls">
|
||||||
|
@ -337,10 +337,10 @@ section.tag-info {
|
|||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
#edit-name {
|
#edit-name {
|
||||||
flex: 1 1 auto;
|
width: 100%;
|
||||||
margin-right: 0.5em;
|
|
||||||
}
|
}
|
||||||
#edit-description {
|
#edit-description {
|
||||||
|
height: 120px;
|
||||||
flex: 10 1 auto;
|
flex: 10 1 auto;
|
||||||
}
|
}
|
||||||
.edit-controls {
|
.edit-controls {
|
||||||
|
@ -19,7 +19,7 @@ class Tag < ActiveRecord::Base
|
|||||||
validate :target_tag_validator,
|
validate :target_tag_validator,
|
||||||
if: Proc.new { |t| t.new_record? || t.will_save_change_to_target_tag_id? }
|
if: Proc.new { |t| t.new_record? || t.will_save_change_to_target_tag_id? }
|
||||||
validate :name_validator
|
validate :name_validator
|
||||||
validates :description, length: { maximum: 280 }
|
validates :description, length: { maximum: 1000 }
|
||||||
|
|
||||||
scope :where_name,
|
scope :where_name,
|
||||||
->(name) {
|
->(name) {
|
||||||
@ -265,7 +265,7 @@ end
|
|||||||
# updated_at :datetime not null
|
# updated_at :datetime not null
|
||||||
# pm_topic_count :integer default(0), not null
|
# pm_topic_count :integer default(0), not null
|
||||||
# target_tag_id :integer
|
# target_tag_id :integer
|
||||||
# description :string
|
# description :string(1000)
|
||||||
# public_topic_count :integer default(0), not null
|
# public_topic_count :integer default(0), not null
|
||||||
# staff_topic_count :integer default(0), not null
|
# staff_topic_count :integer default(0), not null
|
||||||
#
|
#
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module TopicTagsMixin
|
module TopicTagsMixin
|
||||||
|
DESCRIPTION_LIMIT = 80
|
||||||
|
|
||||||
def self.included(klass)
|
def self.included(klass)
|
||||||
klass.attributes :tags
|
klass.attributes :tags
|
||||||
klass.attributes :tags_descriptions
|
klass.attributes :tags_descriptions
|
||||||
@ -15,7 +17,10 @@ module TopicTagsMixin
|
|||||||
end
|
end
|
||||||
|
|
||||||
def tags_descriptions
|
def tags_descriptions
|
||||||
all_tags.each.with_object({}) { |tag, acc| acc[tag.name] = tag.description }.compact
|
all_tags
|
||||||
|
.each
|
||||||
|
.with_object({}) { |tag, acc| acc[tag.name] = tag.description&.truncate(DESCRIPTION_LIMIT) }
|
||||||
|
.compact
|
||||||
end
|
end
|
||||||
|
|
||||||
def topic
|
def topic
|
||||||
|
@ -0,0 +1,7 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class IncreaseSizeOfTagDescriptions < ActiveRecord::Migration[7.0]
|
||||||
|
def change
|
||||||
|
change_column :tags, :description, :string, limit: 1000
|
||||||
|
end
|
||||||
|
end
|
@ -44,7 +44,7 @@ RSpec.describe TopicListItemSerializer do
|
|||||||
describe "hidden tags" do
|
describe "hidden tags" do
|
||||||
let(:admin) { Fabricate(:admin) }
|
let(:admin) { Fabricate(:admin) }
|
||||||
let(:user) { Fabricate(:user) }
|
let(:user) { Fabricate(:user) }
|
||||||
let(:hidden_tag) { Fabricate(:tag, name: "hidden") }
|
let(:hidden_tag) { Fabricate(:tag, name: "hidden", description: "a" * 1000) }
|
||||||
let(:staff_tag_group) do
|
let(:staff_tag_group) do
|
||||||
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
|
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
|
||||||
end
|
end
|
||||||
@ -61,6 +61,11 @@ RSpec.describe TopicListItemSerializer do
|
|||||||
expect(json[:tags]).to eq([hidden_tag.name])
|
expect(json[:tags]).to eq([hidden_tag.name])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "trucates description" do
|
||||||
|
json = TopicListItemSerializer.new(topic, scope: Guardian.new(admin), root: false).as_json
|
||||||
|
expect(json[:tags_descriptions]).to eq({ "hidden" => "a" * 77 + "..." })
|
||||||
|
end
|
||||||
|
|
||||||
it "does not return hidden tag to non-staff" do
|
it "does not return hidden tag to non-staff" do
|
||||||
json = TopicListItemSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
json = TopicListItemSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user