Skip to content

Commit

Permalink
Merge branch 'master' into AO3-5441__allowValuesForFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
BoldestDungeon committed Aug 8, 2024
2 parents 027cd11 + cd20f8e commit efb6893
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
bundler-cache: true

- name: erb-lint
uses: tk0miya/action-erblint@eda368e7a0d8a0e71c475bb7cc65d0d612e5148c
uses: tk0miya/action-erblint@b6e537f4616e4fa7a9eef209ca34ca944e1440dd
with:
use_bundler: true
reporter: github-pr-check
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.3.2)
rexml (3.3.3)
strscan
rollout (2.4.3)
rspec-core (3.13.0)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/autocomplete_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def noncanonical_tag
raise "Redshirt: Attempted to constantize invalid class initialize noncanonical_tag #{params[:type].classify}" unless Tag::TYPES.include?(params[:type].classify)

tag_class = params[:type].classify.constantize
one_tag = tag_class.find_by(canonical: false, name: params[:term])
one_tag = tag_class.find_by(canonical: false, name: params[:term]) if params[:term].present?
# If there is an exact match in the database, ensure it is the first thing suggested.
match = if one_tag
[one_tag.name]
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/tag_sets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def nomination_status(nomination=nil)
end

def nomination_tag_information(nominated_tag)
tag_object = nominated_tag.type.gsub(/Nomination/, '').constantize.find_by_name(nominated_tag.tagname)
tag_object = Tag.find_by(name: nominated_tag.tagname)
status = "nonexistent"
tooltip = ts("This tag has never been used before. Check the spelling!")
title = ts("nonexistent tag")
Expand Down
2 changes: 1 addition & 1 deletion app/models/tagset_models/cast_nomination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class CastNomination < TagNomination
has_one :owned_tag_set, through: :tag_set_nomination
belongs_to :fandom_nomination

validate :known_fandom
validate :known_fandom, unless: :blank_tagname?
def known_fandom
return true if (!parent_tagname.blank? || self.fandom_nomination || from_fandom_nomination)
return true if (tag = Tag.find_by_name(self.tagname)) && tag.parents.any? {|p| p.is_a?(Fandom)}
Expand Down
32 changes: 17 additions & 15 deletions app/models/tagset_models/tag_nomination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ class TagNomination < ApplicationRecord
with: /\A[^,*<>^{}=`\\%]+\z/,
message: ts("^Tag nominations cannot include the following restricted characters: , &#94; * < > { } = ` \\ %")

validate :type_validity
validate :type_validity, unless: :blank_tagname?
def type_validity
if !tagname.blank? && (tag = Tag.find_by_name(tagname)) && "#{tag.type}Nomination" != self.type
errors.add(:base, ts("^The tag %{tagname} is already in the archive as a #{tag.type} tag. (All tags have to be unique.) Try being more specific, for instance tacking on the medium or the fandom.", tagname: self.tagname))
end
return unless (tag = Tag.find_by_name(tagname)) && "#{tag.type}Nomination" != self.type

errors.add(:base, ts("^The tag %{tagname} is already in the archive as a #{tag.type} tag. (All tags have to be unique.) Try being more specific, for instance tacking on the medium or the fandom.", tagname: self.tagname))
end

validate :not_already_reviewed, on: :update
Expand All @@ -32,7 +32,7 @@ def not_already_reviewed
end

# This makes sure no tagnames are nominated for different parents in this tag set
validate :require_unique_tagname_with_parent
validate :require_unique_tagname_with_parent, unless: :blank_tagname?
def require_unique_tagname_with_parent
query = TagNomination.for_tag_set(get_owned_tag_set).where(tagname: self.tagname).where("parent_tagname != ?", (self.get_parent_tagname || ''))
# let people change their own!
Expand All @@ -43,18 +43,15 @@ def require_unique_tagname_with_parent
end
end

after_save :destroy_if_blank
def destroy_if_blank
if tagname.blank?
self.destroy
end
end

def get_owned_tag_set
@tag_set || self.tag_set_nomination.owned_tag_set
end

before_save :set_tag_status
def blank_tagname?
tagname.blank?
end

before_save :set_tag_status, unless: :blank_tagname?
def set_tag_status
if (tag = Tag.find_by_name(tagname))
self.exists = true
Expand All @@ -69,7 +66,7 @@ def set_tag_status
true
end

before_save :set_parented
before_save :set_parented, unless: :blank_tagname?
def set_parented
if type == "FreeformNomination"
# skip freeforms
Expand All @@ -88,7 +85,7 @@ def set_parented

# sneaky bit: if the tag set moderator has already rejected or approved this tag, don't
# show it to them again.
before_save :set_approval_status
before_save :set_approval_status, unless: :blank_tagname?
def set_approval_status
set_noms = tag_set_nomination
set_noms = fandom_nomination.tag_set_nomination if !set_noms && from_fandom_nomination
Expand All @@ -105,6 +102,11 @@ def set_approval_status
true
end

after_save :destroy_if_blank
def destroy_if_blank
self.destroy if blank_tagname?
end

def self.for_tag_set(tag_set)
joins(tag_set_nomination: :owned_tag_set).
where("owned_tag_sets.id = ?", tag_set.id)
Expand Down
2 changes: 1 addition & 1 deletion config/initializers/sentry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
config.traces_sampler = lambda do |sampling_context|
next sampling_context[:parent_sampled] unless sampling_context[:parent_sampled].nil?

rack_env = sampling_context[:env]
rack_env = sampling_context[:env] || {}
rate_from_nginx = Float(rack_env["HTTP_X_SENTRY_RATE"], exception: false)
return rate_from_nginx if rate_from_nginx
return 0.01 if Rails.env.production?
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ services:
- redis
- es
- mc
# Make `docker compose attach web` work for debugging
stdin_open: true
tty: true
chrome:
profiles:
- test
Expand Down
20 changes: 20 additions & 0 deletions features/other_a/autocomplete.feature
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,23 @@ Feature: Display autocomplete for tags
Then I should see "日月" in the autocomplete
But I should not see "大小" in the autocomplete

@javascript
Scenario: Zero width space tag doesn't appear in the autocomplete for space
Given a canonical character "Gold"
And a zero width space tag exists
And I am logged in as a tag wrangler
When I go to the "Gold" tag edit page
Then I should see "This is the official name for the Character"
When I enter " " in the "tag_merger_string_autocomplete" autocomplete field
Then I should see "No suggestions found" in the autocomplete

@javascript
Scenario: Zero width space tag appears in the autocomplete for zero width space
Given a canonical character "Gold"
And a zero width space tag exists
And I am logged in as a tag wrangler
When I go to the "Gold" tag edit page
Then I should see "This is the official name for the Character"
# Zero width space tag
When I enter "​" in the "tag_merger_string_autocomplete" autocomplete field
Then I should not see "No suggestions found" in the autocomplete
10 changes: 9 additions & 1 deletion features/step_definitions/tag_set_steps.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
# encoding: utf-8
Given "a nominated tag set {string} with a tag nomination in the wrong category" do |tag_set_name|
pseud = FactoryBot.create(:pseud, user: FactoryBot.create(:user, login: "tagsetter"))
owned_tag_set = FactoryBot.create(:owned_tag_set, title: tag_set_name, owner: pseud)
tag_set_nomination = FactoryBot.create(:tag_set_nomination, pseud: pseud, owned_tag_set: owned_tag_set)
FactoryBot.create(:relationship, name: "rel tag")
invalid_nom = tag_set_nomination.fandom_nominations.build(tagname: "rel tag") # intentional mismatch in tag category
invalid_nom.save(validate: false)
end

When /^I follow the add new tag ?set link$/ do
step %{I follow "New Tag Set"}
end
Expand Down
5 changes: 5 additions & 0 deletions features/step_definitions/tag_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@
tag.destroy if tag.present?
end

Given "a zero width space tag exists" do
blank_tag = FactoryBot.build(:character, name: ["200B".hex].pack("U"))
blank_tag.save!(validate: true) # TODO: Change to validate: false when AO3-6777 is fixed
end

### WHEN

When /^the periodic tag count task is run$/i do
Expand Down
90 changes: 90 additions & 0 deletions features/tag_sets/tag_set_nominations.feature
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@ Feature: Nominating and reviewing nominations for a tag set
And I should see "My Favorite Character/Their Worst Enemy"
But I should not see "Their Best Friend"

Scenario: You should be able to delete a nominated character and its fandom at once
when the tagset doesn't allow fandom nominations
Given a canonical character "Common Character" in fandom "Canon"
And I am logged in as "tagsetter"
And I set up the nominated tag set "Nominated Tags" with 0 fandom noms and 3 character noms
When I follow "Nominate"
And I fill in "Character 1" with "Obscure Character"
And I fill in "Fandom?" with "Canon"
And I press "Submit"
Then I should see "Your nominations were successfully submitted."
And I should see "Obscure Character"
When I follow "Edit"
And I fill in "Character 1" with ""
And I fill in "Fandom?" with ""
And I press "Submit"
Then I should see "Your nominations were successfully updated."
And I should see "None nominated in this category."
But I should not see "We need to know what fandom belongs in."

Scenario: Owner of a tag set can clear all nominations
Given I am logged in as "tagsetter"
And I set up the nominated tag set "Nominated Tags" with 3 fandom noms and 3 character noms
Expand Down Expand Up @@ -232,3 +251,74 @@ Feature: Nominating and reviewing nominations for a tag set
And I submit
Then I should see "The tag Veronica Mars is already in the archive as a Character tag. (All tags have to be unique.) Try being more specific, for instance tacking on the medium or the fandom."

Scenario: If a tag was nominated as another type of tag, "My Nominations" and "Review Nominations" can still be accessed
Given a nominated tag set "bad" with a tag nomination in the wrong category
And I am logged in as "tagsetter"
And I go to the "bad" tag set page
# preexisting non-canonical tag
When I follow "My Nominations"
Then I should see "My Nominations for bad"
And I should see "rel tag"
When I review nominations for "bad"
Then I should see "Fandoms (1 left to review)"
And I should see "rel tag"
# canonical tag
When the tag "rel tag" is canonized
And I go to the "bad" tag set page
When I follow "My Nominations"
Then I should see "My Nominations for bad"
And I should see "rel tag"
When I review nominations for "bad"
Then I should see "Fandoms (1 left to review)"
And I should see "rel tag"
# synonym tag
When the tag "rel tag" is decanonized
And a canonical relationship "canon tag"
And a synonym "rel tag" of the tag "canon tag"
And I go to the "bad" tag set page
When I follow "My Nominations"
Then I should see "My Nominations for bad"
And I should see "rel tag"
When I review nominations for "bad"
Then I should see "Fandoms (1 left to review)"
And I should see "rel tag (canon tag)"

Scenario: The zero width space tag doesn't replace deleted tag nominations
Given a canonical fandom "Treasure Chest"
And a zero width space tag exists
And I am logged in as "tagsetter"
And I set up the nominated tag set "Nominated Tags" with 2 fandom noms and 3 character noms
And I nominate fandom "Treasure Chest" and character "Gold" in "Nominated Tags"
And I go to the "Nominated Tags" tag set page
And I follow "My Nominations"
Then I should see "Not Yet Reviewed (may be edited or deleted)"
When I follow "Edit"
And I fill in "Character" with ""
And I press "Submit"
Then I should see "Your nominations were successfully updated."
And I should see "Treasure Chest"
But I should not see "Gold"
And I should see "None nominated in this fandom."

Scenario: A tag nomination with the zero width space tag doesn't prevent removing other tag nominations
Given a canonical fandom "First"
And a canonical fandom "Treasure Chest"
And a zero width space tag exists
And I am logged in as "tagsetter"
And I set up the nominated tag set "Nominated Tags" with 2 fandom noms and 1 character noms
# Zero width space character tag in first fandom
And I nominate fandom "First,Treasure Chest" and character "​,Gold" in "Nominated Tags"
And I go to the "Nominated Tags" tag set page
And I follow "My Nominations"
Then I should see "First"
And I should not see "None nominated in this fandom."
And I should see "Treasure Chest"
And I should see "Gold"
When I follow "Edit"
# Empty second fandom character field
And I fill in "tag_set_nomination_fandom_nominations_attributes_1_character_nominations_attributes_0_tagname" with ""
And I press "Submit"
Then I should see "Your nominations were successfully updated."
And I should not see "Someone else has already nominated the tag for this set but in fandom First."
And I should not see "Gold"
And I should see "None nominated in this fandom."

0 comments on commit efb6893

Please sign in to comment.