about summary refs log tree commit diff
path: root/app/services/create_featured_tag_service.rb
diff options
context:
space:
mode:
authorYamagishi Kazutoshi <ykzts@desire.sh>2022-10-23 06:14:58 +0900
committerGitHub <noreply@github.com>2022-10-22 23:14:58 +0200
commit45d3b324883c1e72ad5f9820d3c23f7f779f28db (patch)
treebc9e7e7882f2c06ca6f99d21d6dcbcd7e6cc469d /app/services/create_featured_tag_service.rb
parent74ead7d10698c7f18ca22c07d2f04ff81f419097 (diff)
Fix `Settings::FeaturedTagsController` (#19418)
Regression from #19409
Diffstat (limited to 'app/services/create_featured_tag_service.rb')
-rw-r--r--app/services/create_featured_tag_service.rb10
1 files changed, 7 insertions, 3 deletions
diff --git a/app/services/create_featured_tag_service.rb b/app/services/create_featured_tag_service.rb
index c99d16113..3cc59156d 100644
--- a/app/services/create_featured_tag_service.rb
+++ b/app/services/create_featured_tag_service.rb
@@ -3,14 +3,18 @@
 class CreateFeaturedTagService < BaseService
   include Payloadable
 
-  def call(account, name)
+  def call(account, name, force: true)
     @account = account
 
     FeaturedTag.create!(account: account, name: name).tap do |featured_tag|
       ActivityPub::AccountRawDistributionWorker.perform_async(build_json(featured_tag), account.id) if @account.local?
     end
-  rescue ActiveRecord::RecordNotUnique
-    FeaturedTag.by_name(name).find_by!(account: account)
+  rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid => e
+    if force && e.is_a(ActiveRecord::RecordNotUnique)
+      FeaturedTag.by_name(name).find_by!(account: account)
+    else
+      account.featured_tags.new(name: name)
+    end
   end
 
   private