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"}}
|
||||
@autofocus="true"
|
||||
/>
|
||||
<TextField
|
||||
@id="edit-description"
|
||||
|
||||
<Textarea
|
||||
id="edit-description"
|
||||
@value={{readonly this.tagInfo.description}}
|
||||
@placeholder={{i18n "tagging.description"}}
|
||||
@maxlength={{280}}
|
||||
@input={{action (mut this.newTagDescription) value="target.value"}}
|
||||
@autofocus="true"
|
||||
placeholder={{i18n "tagging.description"}}
|
||||
maxlength={{1000}}
|
||||
{{on
|
||||
"input"
|
||||
(action (mut this.newTagDescription) value="target.value")
|
||||
}}
|
||||
autofocus="true"
|
||||
/>
|
||||
|
||||
<div class="edit-controls">
|
||||
|
|
|
@ -337,10 +337,10 @@ section.tag-info {
|
|||
flex-wrap: wrap;
|
||||
margin-bottom: 1em;
|
||||
#edit-name {
|
||||
flex: 1 1 auto;
|
||||
margin-right: 0.5em;
|
||||
width: 100%;
|
||||
}
|
||||
#edit-description {
|
||||
height: 120px;
|
||||
flex: 10 1 auto;
|
||||
}
|
||||
.edit-controls {
|
||||
|
|
|
@ -19,7 +19,7 @@ class Tag < ActiveRecord::Base
|
|||
validate :target_tag_validator,
|
||||
if: Proc.new { |t| t.new_record? || t.will_save_change_to_target_tag_id? }
|
||||
validate :name_validator
|
||||
validates :description, length: { maximum: 280 }
|
||||
validates :description, length: { maximum: 1000 }
|
||||
|
||||
scope :where_name,
|
||||
->(name) {
|
||||
|
@ -265,7 +265,7 @@ end
|
|||
# updated_at :datetime not null
|
||||
# pm_topic_count :integer default(0), not null
|
||||
# target_tag_id :integer
|
||||
# description :string
|
||||
# description :string(1000)
|
||||
# public_topic_count :integer default(0), not null
|
||||
# staff_topic_count :integer default(0), not null
|
||||
#
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module TopicTagsMixin
|
||||
DESCRIPTION_LIMIT = 80
|
||||
|
||||
def self.included(klass)
|
||||
klass.attributes :tags
|
||||
klass.attributes :tags_descriptions
|
||||
|
@ -15,7 +17,10 @@ module TopicTagsMixin
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
let(:admin) { Fabricate(:admin) }
|
||||
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
|
||||
Fabricate(:tag_group, permissions: { "staff" => 1 }, tag_names: [hidden_tag.name])
|
||||
end
|
||||
|
@ -61,6 +61,11 @@ RSpec.describe TopicListItemSerializer do
|
|||
expect(json[:tags]).to eq([hidden_tag.name])
|
||||
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
|
||||
json = TopicListItemSerializer.new(topic, scope: Guardian.new(user), root: false).as_json
|
||||
|
||||
|
|
Loading…
Reference in New Issue