Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6714 Fix duplicate tag set ownership on create #4864

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tommilligan
Copy link
Contributor

@tommilligan tommilligan commented Jun 26, 2024

Pull Request Checklist

Issue

https://otwarchive.atlassian.net/browse/AO3-6714

Purpose

This PR is based on #4863

This PR implements point 1. of the "What should happen" section of AO3-6714.

This PR prevents a OwnedTagSet being created with duplicate TagSetOwnership relationships. This happens when the currently logged in user explicitly adds themselves as an owner via the UI.

Notes

As this PR blocks creating tag sets with duplicate owners in the first place, the test case added in #4863 cannot be maintained without directly constructing an invalid state, with which to continue testing. I didn't do this; please let me know if you think it's required.

Testing Instructions

Manually follow the recreation steps in the issue. Verify that when adding your username as an explicit owner, the created tag set only lists the currently logged in username as a maintainer once.

References

N/A

Credit

What name and pronouns should we use to credit you in the Archive of Our Own's Release Notes?

Tom Milligan (they/them)

Copy link
Member

@brianjaustin brianjaustin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! A couple of comments (mostly about tests) for you, but overall your approach looks reasonable to me.

On a more general note: I talked over the owners field with some of the other devs, and at some point we'd like to rework it so it's more like the tags field (where you can click an "X" to remove things instead of, somewhat confusingly, adding the pseud to the list to mean it should be removed). If you'd like to tackle that now, great! But that definitely would add a lot more scope, so we are happy to put a Jira ticket in for that to be done later.

features/step_definitions/tag_set_steps.rb Outdated Show resolved Hide resolved
features/tag_sets/tag_set.feature Outdated Show resolved Hide resolved
features/step_definitions/tag_set_steps.rb Outdated Show resolved Hide resolved
And I should see "tagsetter" within ".meta"
When I go to the "Duplicate Ownership" tag set edit page
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to get the duplication to happen on edit, just on creation. I think it would be a good idea to replicate the steps to reproduce from the bug ticket, which also triggers the duplication behaviour while creating the tag set

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean here - the steps to reproduce the duplication are here, where we specify an additional owner on creation who is the same as the logged in user: https://github.com/otwcode/otwarchive/pull/4864/files#diff-7aa40c6f60753ed081b2a3c186f775734fc427fdc9adcb714b424ff5007e8e40R26

Possibly the step should be phrased "additional owners" to make this clear?

    And I set up the tag set "Duplicate Ownership" with additional owners "tagsetter" and the freeform tags "Clones"

So I think this test is already reproducing the bug ticket.

You can verify that these setup steps would have reproduced the failure, by looking at this test from the first PR I submitted: 64092e8#diff-7aa40c6f60753ed081b2a3c186f775734fc427fdc9adcb714b424ff5007e8e40R28

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, got it. Yes, I like that proposed wording, I think it makes things a bit clearer (especially given the current UX is Weird ™️)

app/models/tagset_models/owned_tag_set.rb Outdated Show resolved Hide resolved
@tommilligan tommilligan force-pushed the AO3-6714-check-add-owner-at-create branch from 54b716f to d4de80b Compare July 21, 2024 12:10
Comment on lines +153 to +156
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking I'd prefer this to live in the model somewhere, but bouncing some ideas around right now (with a few clarifications I think the Jira story could use) so feel free to wait on any other changes until I have an answer for you on that

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think we can do this with a model validation in https://github.com/otwcode/otwarchive/blob/1bdb4441e193ca269bb31f8c4a78ab5db7d1b663/app/models/tagset_models/tag_set_ownership.rb:

class TagSetOwnership < ApplicationRecord
  belongs_to :pseud
  belongs_to :owned_tag_set

  validates :pseud, uniqueness: { scope: :owned_tag_set_id }
end

(credit to @Bilka2 for the above). This will validate that the pseud is unique and only appears for moderator or owner, not both. The message can be taken care of with Rails I18n, similar to

taken: You have already blocked that user.
(docs: https://github.com/otwcode/otwarchive/wiki/Internationalization-%28i18n%29-Standards#overriding-a-default-error-message); please let me know if additional examples would be helpful there.

With that validation in place, we won't need to worry about removing owners multiple times. So, instead of special-casing in the model, could you write a one-time Rake task to find and fix any duplicate owners?

Sorry for the wall of text, please don't hesitate to let us know if you have any questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants