Improve enforcement of collection item limit (#39969)
This commit is contained in:
1 parent
467c933459
commit
f8337b04fe
4 files changed
+35
-13
No files matched your search
@@ -54,7 +54,7 @@ class Collection < ApplicationRecord
|
||||
if: :remote?
|
||||
validates :language, language: { if: :local?, allow_nil: true }
|
||||
validate :tag_is_usable
|
||||
validate :items_do_not_exceed_limit
|
||||
validate :items_do_not_exceed_limit, if: :local?
|
||||
validate :user_does_not_exceed_limit, on: :create
|
||||
|
||||
scope :with_items, -> { includes(:collection_items).merge(CollectionItem.with_accounts) }
|
||||
|
||||
@@ -17,9 +17,10 @@ class ActivityPub::ProcessFeaturedItemService
|
||||
return if non_matching_actor_and_approval_uris?
|
||||
return if non_supported_object_type?
|
||||
|
||||
with_redis_lock("collection_item:#{@item_json['id']}") do
|
||||
@collection_item = existing_item || pre_approved_item || new_item
|
||||
@collection_item = existing_item || pre_approved_item || new_item
|
||||
return if @collection_item.nil?
|
||||
|
||||
with_redis_lock("collection_item:#{@item_json['id']}") do
|
||||
@collection_item.position = position unless position.nil?
|
||||
@collection_item.update!(
|
||||
uri: @item_json['id'],
|
||||
@@ -45,6 +46,8 @@ class ActivityPub::ProcessFeaturedItemService
|
||||
end
|
||||
|
||||
def new_item
|
||||
return if @collection.collection_items.count >= ActivityPub::ProcessFeaturedCollectionService::ITEMS_LIMIT
|
||||
|
||||
@collection.collection_items.new(
|
||||
created_at: @item_json['published']
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user