Skip to content

Commit

Permalink
AO3-6714 Fix duplicate tag set ownership on create
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Milligan committed Jun 26, 2024
1 parent 555409f commit 3a2e032
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion app/controllers/owned_tag_sets_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,17 @@ def new

def create
@tag_set = OwnedTagSet.new(owned_tag_set_params)
@tag_set.add_owner(current_user.default_pseud)

# Check if the current user already owns the tag set, and only add them if they don't.
#
# This happens when the user adds themselves explicitly as an owner.
# This check is done by direct Enumerable.find rather than ActiveRecord `find_by`
# as we cannot use `find_by` before the record is stored in the database with `.save`
current_user_ownership = @tag_set.tag_set_ownerships.find do |ownership|
ownership.owner == true && ownership.pseud_id == current_user.default_pseud.id
end
@tag_set.add_owner(current_user.default_pseud) unless current_user_ownership

if @tag_set.save
flash[:notice] = ts('Tag Set was successfully created.')
redirect_to tag_set_path(@tag_set)
Expand Down
4 changes: 2 additions & 2 deletions features/tag_sets/tag_set.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Feature: Creating and editing tag sets
Then I should see a create confirmation message
And Maintainers should be "anotherowner tagsetter"

Scenario: A user should not be able to remove themselves as an owner (AO3-6714)
Scenario: A user should not be able to dupicate or remove themselves as an owner (AO3-6714)
Given I am logged in as "tagsetter"
And I set up the tag set "Duplicate Ownership" with owners "tagsetter" and the freeform tags "Clones"
Then I should see a create confirmation message
And I should see "tagsetter tagsetter" within ".meta"
And I should see "tagsetter" within ".meta"
When I go to the "Duplicate Ownership" tag set edit page
And I toggle the owners "tagsetter"
And I submit
Expand Down

0 comments on commit 3a2e032

Please sign in to comment.