diff --git a/app/controllers/owned_tag_sets_controller.rb b/app/controllers/owned_tag_sets_controller.rb index 502aa4ad0fe..36f7fa98602 100644 --- a/app/controllers/owned_tag_sets_controller.rb +++ b/app/controllers/owned_tag_sets_controller.rb @@ -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) diff --git a/features/tag_sets/tag_set.feature b/features/tag_sets/tag_set.feature index d49dffaa1fa..18b387cd537 100644 --- a/features/tag_sets/tag_set.feature +++ b/features/tag_sets/tag_set.feature @@ -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