Fix account tags not being saved correctly (#11507)
* Fix account tags not being saved correctly
Regression from f371b32
Fix Tag#discoverable not returning tags where listable is nil instead of true
Add notice when saving hashtags in admin UI
Change public hashtag and directory pages to return 404 for forbidden tags
* Remove unused locale string
This commit is contained in:
parent
5e35aa8280
commit
ac33f1aedd
6 changed files with 7 additions and 15 deletions
|
@ -17,7 +17,7 @@ module Admin
|
||||||
authorize @tag, :update?
|
authorize @tag, :update?
|
||||||
|
|
||||||
if @tag.update(tag_params.merge(reviewed_at: Time.now.utc))
|
if @tag.update(tag_params.merge(reviewed_at: Time.now.utc))
|
||||||
redirect_to admin_tag_path(@tag.id)
|
redirect_to admin_tag_path(@tag.id), notice: I18n.t('admin.tags.updated_msg')
|
||||||
else
|
else
|
||||||
render :show
|
render :show
|
||||||
end
|
end
|
||||||
|
|
|
@ -25,7 +25,7 @@ class DirectoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_tag
|
def set_tag
|
||||||
@tag = Tag.discoverable.find_by!(name: params[:id].downcase)
|
@tag = Tag.discoverable.find_normalized!(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_tags
|
def set_tags
|
||||||
|
|
|
@ -47,7 +47,7 @@ class TagsController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_tag
|
def set_tag
|
||||||
@tag = Tag.find_normalized!(params[:id])
|
@tag = Tag.usable.find_normalized!(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_body_classes
|
def set_body_classes
|
||||||
|
|
|
@ -227,17 +227,7 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags_as_strings=(tag_names)
|
def tags_as_strings=(tag_names)
|
||||||
tag_names.map! { |name| name.mb_chars.downcase.to_s }
|
hashtags_map = Tag.find_or_create_by_names(tag_names).each_with_object({}) { |tag, h| h[tag.name] = tag }
|
||||||
tag_names.uniq!
|
|
||||||
|
|
||||||
# Existing hashtags
|
|
||||||
hashtags_map = Tag.where(name: tag_names).each_with_object({}) { |tag, h| h[tag.name] = tag }
|
|
||||||
|
|
||||||
# Initialize not yet existing hashtags
|
|
||||||
tag_names.each do |name|
|
|
||||||
next if hashtags_map.key?(name)
|
|
||||||
hashtags_map[name] = Tag.new(name: name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Remove hashtags that are to be deleted
|
# Remove hashtags that are to be deleted
|
||||||
tags.each do |tag|
|
tags.each do |tag|
|
||||||
|
|
|
@ -31,7 +31,8 @@ class Tag < ApplicationRecord
|
||||||
|
|
||||||
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
scope :reviewed, -> { where.not(reviewed_at: nil) }
|
||||||
scope :pending_review, -> { where(reviewed_at: nil).where.not(requested_review_at: nil) }
|
scope :pending_review, -> { where(reviewed_at: nil).where.not(requested_review_at: nil) }
|
||||||
scope :discoverable, -> { where.not(listable: false).joins(:account_tag_stat).where(AccountTagStat.arel_table[:accounts_count].gt(0)).order(Arel.sql('account_tag_stats.accounts_count desc')) }
|
scope :usable, -> { where(usable: [true, nil]) }
|
||||||
|
scope :discoverable, -> { where(listable: [true, nil]).joins(:account_tag_stat).where(AccountTagStat.arel_table[:accounts_count].gt(0)).order(Arel.sql('account_tag_stats.accounts_count desc')) }
|
||||||
scope :most_used, ->(account) { joins(:statuses).where(statuses: { account: account }).group(:id).order(Arel.sql('count(*) desc')) }
|
scope :most_used, ->(account) { joins(:statuses).where(statuses: { account: account }).group(:id).order(Arel.sql('count(*) desc')) }
|
||||||
|
|
||||||
delegate :accounts_count,
|
delegate :accounts_count,
|
||||||
|
|
|
@ -496,6 +496,7 @@ en:
|
||||||
title: Hashtags
|
title: Hashtags
|
||||||
trending_right_now: Trending right now
|
trending_right_now: Trending right now
|
||||||
unique_uses_today: "%{count} posting today"
|
unique_uses_today: "%{count} posting today"
|
||||||
|
updated_msg: Hashtag settings updated successfully
|
||||||
title: Administration
|
title: Administration
|
||||||
warning_presets:
|
warning_presets:
|
||||||
add_new: Add new
|
add_new: Add new
|
||||||
|
|
Loading…
Reference in a new issue