Remove description presence validation on collections (#38528)

This commit is contained in:
David Roetzel 2026-04-02 14:56:00 +02:00 committed by GitHub
parent 145dcfadce
commit 814cd61fd8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 1 additions and 9 deletions

View File

@ -36,11 +36,9 @@ class Collection < ApplicationRecord
validates :name, length: { maximum: 40 }, if: :local? validates :name, length: { maximum: 40 }, if: :local?
validates :name, length: { maximum: NAME_LENGTH_HARD_LIMIT }, if: :remote? validates :name, length: { maximum: NAME_LENGTH_HARD_LIMIT }, if: :remote?
validates :description, validates :description,
presence: true,
length: { maximum: 100 }, length: { maximum: 100 },
if: :local? if: :local?
validates :description_html, validates :description_html,
presence: true,
length: { maximum: DESCRIPTION_LENGTH_HARD_LIMIT }, length: { maximum: DESCRIPTION_LENGTH_HARD_LIMIT },
if: :remote? if: :remote?
validates :local, inclusion: [true, false] validates :local, inclusion: [true, false]

View File

@ -15,6 +15,7 @@ class REST::CollectionSerializer < ActiveModel::Serializer
def description def description
return object.description if object.local? return object.description if object.local?
return if object.description_html.nil?
Sanitize.fragment(object.description_html, Sanitize::Config::MASTODON_STRICT) Sanitize.fragment(object.description_html, Sanitize::Config::MASTODON_STRICT)
end end

View File

@ -10,8 +10,6 @@ RSpec.describe Collection do
it { is_expected.to validate_length_of(:name).is_at_most(40) } it { is_expected.to validate_length_of(:name).is_at_most(40) }
it { is_expected.to validate_presence_of(:description) }
it { is_expected.to validate_length_of(:description).is_at_most(100) } it { is_expected.to validate_length_of(:description).is_at_most(100) }
it { is_expected.to_not allow_value(nil).for(:local) } it { is_expected.to_not allow_value(nil).for(:local) }
@ -29,10 +27,6 @@ RSpec.describe Collection do
it { is_expected.to validate_length_of(:name).is_at_most(Collection::NAME_LENGTH_HARD_LIMIT) } it { is_expected.to validate_length_of(:name).is_at_most(Collection::NAME_LENGTH_HARD_LIMIT) }
it { is_expected.to_not validate_presence_of(:description) }
it { is_expected.to validate_presence_of(:description_html) }
it { is_expected.to validate_length_of(:description_html).is_at_most(Collection::DESCRIPTION_LENGTH_HARD_LIMIT) } it { is_expected.to validate_length_of(:description_html).is_at_most(Collection::DESCRIPTION_LENGTH_HARD_LIMIT) }
it { is_expected.to validate_presence_of(:uri) } it { is_expected.to validate_presence_of(:uri) }

View File

@ -180,7 +180,6 @@ RSpec.describe 'Api::V1Alpha::Collections', feature: :collections do
'error' => a_hash_including({ 'error' => a_hash_including({
'details' => a_hash_including({ 'details' => a_hash_including({
'name' => [{ 'error' => 'ERR_BLANK', 'description' => "can't be blank" }], 'name' => [{ 'error' => 'ERR_BLANK', 'description' => "can't be blank" }],
'description' => [{ 'error' => 'ERR_BLANK', 'description' => "can't be blank" }],
}), }),
}), }),
}) })