-
Notifications
You must be signed in to change notification settings - Fork 491
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
base: master
Are you sure you want to change the base?
AO3-6714 Fix duplicate tag set ownership on create #4864
Conversation
876510b
to
3a2e032
Compare
3a2e032
to
fd1f474
Compare
There was a problem hiding this 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.
And I should see "tagsetter" within ".meta" | ||
When I go to the "Duplicate Ownership" tag set edit page |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 ™️)
54b716f
to
d4de80b
Compare
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
otwarchive/config/locales/models/en.yml
Line 109 in dd6ec55
taken: You have already blocked that user. |
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!
Pull Request Checklist
as the first thing in your pull request title (e.g.
AO3-1234 Fix thing
)until they are reviewed and merged before creating new pull requests.
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 duplicateTagSetOwnership
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
Tom Milligan (they/them)