-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Allow users to change version slug #11930
base: main
Are you sure you want to change the base?
Conversation
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.
These changes look very promising, in particular because they are pretty small. I did a quick test locally and I was able to change a slug and serve the documentation under the new URL 🎉
There are some things to consider still:
- I understand we don't need to touch the sync versions code because it's based on
verbose_name
and we are not changing that, right? - There is no need to save the "old slug" because if required it can be generated based on the
verbose_name
, as we are doing currently. - The dashboard uses
verbose_name
when mentioning versions; so there is going to be a mismatch for those versions where we change the slug. What would be a good solution for this? - Flyout Addon uses
slug
to sort versions, which will keep working with the changes from this PR. However, I was told that we should useverbose_name
there as well. In that case, sorting will break (Addons: useverbose_name
instead ofslug
for sorting versions #11182). Should we keep the sorting by slug then?
I guess everything is clear after the meeting, just answering for the record
No, we don't need to.
I don't think we need to have access to the old slug at all, we can try to guess the original slug by inferring it from the verbose_name, but that isn't necessarily true as slugs can't be duplicated, so some end with
I suggested we use another field instead (display_name) that users can change to show in the UI/version selector. That way we don't change verbose_name which is used to keep a one to one match with the versions from the repo.
I still think we shouldn't use the slug for sorting (the name we show to users in the listings won't match the order), if users want further customization, then sorting should be based on the new |
This could be useful for creating redirects, but perhaps we just do that automatically when they rename the slug? |
My idea would be to create a notification or show the message after the user has done the rename (about a link to create a redirect), we don't need to keep that information forever, specially if the user changes the slug again. |
Yea, I think honestly even just putting it in cache and checking for that on the redirects page for a suggested redirect. I'd like to do something similar with the filetreediff stuff and redirect suggestions as well. |
6f13b4a
to
a081a95
Compare
Instead of having a custom field with some extra complexity, we can achieve the same result by using a more standard django pattern, populating the field if isn't defined and using a validator. This will help to re-use this code in #11930.
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.
Looks good with some suggestions/changes.
# NOTE: we call clean_resources over the instance with the previous slug, | ||
# as all resources are associated with that slug. | ||
if "slug" in self.changed_data and self._was_active: | ||
self.instance.slug = self._previous_slug | ||
self.instance.clean_resources() | ||
self.instance.slug = self.cleaned_data["slug"] | ||
# We need to set the flag to False, | ||
# so the post_save method triggers a new build. | ||
self._was_active = False |
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.
This looks a little hacky to me: setting the previous slug to the current instance, and then re-set it to the one the user has chosen. I understand why we are doing this, but I wonder if there is a more explicit way to call this cleanup, like running clean_resources(project_slug, version_slug)
instead, or similar.
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.
Agreed, seems like a small refactor could make this nicer.
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.
This looks great to me overall, will let @humitos 👍 it once the last review items are addressed.
# NOTE: we call clean_resources over the instance with the previous slug, | ||
# as all resources are associated with that slug. | ||
if "slug" in self.changed_data and self._was_active: | ||
self.instance.slug = self._previous_slug | ||
self.instance.clean_resources() | ||
self.instance.slug = self.cleaned_data["slug"] | ||
# We need to set the flag to False, | ||
# so the post_save method triggers a new build. | ||
self._was_active = False |
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.
Agreed, seems like a small refactor could make this nicer.
Basically what I had in my old design doc #6273
project
is used as s hidden field, following the same pattern we already have for other forms (this way all normal validations like the unique constraint work instead of getting a 500).I was playing with using the "pattern" attribute for the input, so it validates the slug before submitting the form.
But I think showing the error with the suggested slug works better, maybe we can port that to JS instead as a future improvement.
Decisions
TODO
The idea implemented here comes from this comment: https://github.com/readthedocs/meta/discussions/147#discussioncomment-11789455
ref https://github.com/readthedocs/meta/discussions/147