tags: remove tag category locks.
Remove the ability to lock a tag's category. Before a moderator could lock a tag such that only an admin could change the tag's category. Nowadays the ability to change a tag's category is based on the tag's size. Members can change tag categories for tags with up to 50 posts, and Builders can change categories for tags with up to 1000 posts. Manually locking tags is not necessary. We only had a few dozen locked tags, mostly random *_(cosplay) tags or company name tags. Most of these are holdovers from moderators randomly locking tags like ten years ago. The `is_locked` field is still in the database, so it is still returned by the /tags.json API, even though it is unused.
This commit is contained in:
@@ -269,7 +269,7 @@ class Tag < ApplicationRecord
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :is_locked, :category, :post_count, :name, :wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :category, :post_count, :name, :wiki_page, :artist, :antecedent_alias, :consequent_aliases, :antecedent_implications, :consequent_implications, :dtext_links)
|
||||
|
||||
if params[:fuzzy_name_matches].present?
|
||||
q = q.fuzzy_name_matches(params[:fuzzy_name_matches])
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
class TagPolicy < ApplicationPolicy
|
||||
def can_change_category?
|
||||
user.is_admin? ||
|
||||
(user.is_builder? && !record.is_locked? && record.post_count < 1_000) ||
|
||||
(user.is_member? && !record.is_locked? && record.post_count < 50)
|
||||
end
|
||||
|
||||
def can_lock?
|
||||
user.is_moderator?
|
||||
(user.is_builder? && record.post_count < 1_000) ||
|
||||
(user.is_member? && record.post_count < 50)
|
||||
end
|
||||
|
||||
def permitted_attributes
|
||||
[(:category if can_change_category?), (:is_locked if can_lock?)].compact
|
||||
[(:category if can_change_category?)].compact
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,15 +5,10 @@
|
||||
<%= edit_form_for(@tag) do |f| %>
|
||||
<% if policy(@tag).can_change_category? %>
|
||||
<%= f.input :category, collection: TagCategory.canonical_mapping.to_a, include_blank: false %>
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% else %>
|
||||
<p>Create a <%= link_to "bulk update request", new_bulk_update_request_path(bulk_update_request: { script: "category #{@tag.name} -> general" }) %> to change this tag's category.</p>
|
||||
<% end %>
|
||||
|
||||
<% if policy(@tag).can_lock? %>
|
||||
<%= f.input :is_locked, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>
|
||||
<% end %>
|
||||
|
||||
<%= f.button :submit, "Submit" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -98,20 +98,6 @@ class TagsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal(Tag.categories.general, @tag.reload.category)
|
||||
end
|
||||
|
||||
should "lock the tag for a moderator" do
|
||||
put_auth tag_path(@tag), @mod, params: { tag: { is_locked: true } }
|
||||
|
||||
assert_redirected_to @tag
|
||||
assert_equal(true, @tag.reload.is_locked)
|
||||
end
|
||||
|
||||
should "not lock the tag for a user" do
|
||||
put_auth tag_path(@tag), @user, params: {tag: { is_locked: true }}
|
||||
|
||||
assert_response 403
|
||||
assert_equal(false, @tag.reload.is_locked)
|
||||
end
|
||||
|
||||
context "for a tag with >50 posts" do
|
||||
setup do
|
||||
@tag.update(post_count: 100)
|
||||
|
||||
@@ -99,14 +99,6 @@ class TagTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "not change the category is the tag is locked" do
|
||||
tag = FactoryBot.create(:tag, :is_locked => true)
|
||||
assert_equal(true, tag.is_locked?)
|
||||
Tag.find_or_create_by_name("artist:#{tag.name}")
|
||||
tag.reload
|
||||
assert_equal(0, tag.category)
|
||||
end
|
||||
|
||||
should "not change category when the tag is too large to be changed by a builder" do
|
||||
tag = FactoryBot.create(:tag, post_count: 1001)
|
||||
Tag.find_or_create_by_name("artist:#{tag.name}", creator: @builder)
|
||||
|
||||
Reference in New Issue
Block a user