From 208b618918d3483da8b73befe33263196d735e1a Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 9 Dec 2021 13:20:26 -0600 Subject: [PATCH] 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. --- app/models/tag.rb | 2 +- app/policies/tag_policy.rb | 10 +++------- app/views/tags/edit.html.erb | 7 +------ test/functional/tags_controller_test.rb | 14 -------------- test/unit/tag_test.rb | 8 -------- 5 files changed, 5 insertions(+), 36 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index 2eab7fe6b..9ccfa309c 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -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]) diff --git a/app/policies/tag_policy.rb b/app/policies/tag_policy.rb index b5a02f2c9..88a48c10a 100644 --- a/app/policies/tag_policy.rb +++ b/app/policies/tag_policy.rb @@ -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 diff --git a/app/views/tags/edit.html.erb b/app/views/tags/edit.html.erb index 08f98f2d8..6cb39264c 100644 --- a/app/views/tags/edit.html.erb +++ b/app/views/tags/edit.html.erb @@ -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 %>

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.

<% end %> - - <% if policy(@tag).can_lock? %> - <%= f.input :is_locked, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> - <% end %> - - <%= f.button :submit, "Submit" %> <% end %> diff --git a/test/functional/tags_controller_test.rb b/test/functional/tags_controller_test.rb index 7da163454..266e0cd1b 100644 --- a/test/functional/tags_controller_test.rb +++ b/test/functional/tags_controller_test.rb @@ -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) diff --git a/test/unit/tag_test.rb b/test/unit/tag_test.rb index 419181214..03d4e3518 100644 --- a/test/unit/tag_test.rb +++ b/test/unit/tag_test.rb @@ -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)