Skip to content

Commit

Permalink
Fix Settings::FeaturedTagsController (mastodon#19418)
Browse files Browse the repository at this point in the history
Regression from mastodon#19409
  • Loading branch information
ykzts authored and kadoshita committed Nov 19, 2022
1 parent ab4129f commit 06f367a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 3 additions & 6 deletions app/controllers/settings/featured_tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ def index
end

def create
if !featured_tag_exists?
CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name])
@featured_tag = CreateFeaturedTagService.new.call(current_account, featured_tag_params[:name], force: false)

if @featured_tag.valid?
redirect_to settings_featured_tags_path
else
set_featured_tags
Expand All @@ -28,10 +29,6 @@ def destroy

private

def featured_tag_exists?
current_account.featured_tags.by_name(featured_tag_params[:name]).exists?
end

def set_featured_tag
@featured_tag = current_account.featured_tags.find(params[:id])
end
Expand Down
10 changes: 7 additions & 3 deletions app/services/create_featured_tag_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06f367a

Please sign in to comment.