-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix: Slug uniqueness not checked when moving page #8185
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
fix: Slug uniqueness not checked when moving page #8185
Conversation
Reviewer's Guide by SourceryThis pull request fixes a bug where slug uniqueness was not checked when moving pages in the Django CMS admin interface. It implements slug validation in the No diagrams generated as the changes look simple and do not need a visual representation. File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @amandasavluchinske - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider adding a test case that specifically checks the scenario where moving a page would result in a slug collision.
- The MovePageForm's clean method could be simplified by extracting the slug uniqueness check into a separate, reusable function.
Here's what I looked at during the review
- 🟢 General issues: all looks good
- 🟢 Security: all looks good
- 🟡 Testing: 1 issue found
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@amandasavluchinske What do you think about the edge case moving a page next to itself? Can (or have) we cover this? Also, what do you think about sourcery's idea of factoring out the uniqueness check? |
7198e2d
to
b2e7cc3
Compare
Thanks for the suggestions @fsbraun ! The changes have been pushed :) |
In our private version of django-CMS we actually use these constraints to prevent inconsistencies while moving pages, etc.: |
ed4fa02
to
16824f6
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.
@amandasavluchinske I have not been able to find out what makes the tests fail on mysql. I'm still on it. In the meantime I have two questions.
Thanks @fsbraun , I'll reply to your comments as soon as I can, but in the meantime: I looked the error up, and it seems like it's related to the |
That seems reasonable. But I still try to wrap my head around why we need it. |
Yes, I'll review everything once I get some time. |
Hi @fsbraun ! I performed the requested changes. The condition wasn't needed after all. I tested manually and everything seems to be working as expected, but it would be good to have another pair of eyes on it as well. Thanks! |
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.
@amandasavluchinske I feel this is really getting somewhere! Sorry for the bickering, but I have two additional comments (see below) which could save us from having to duplicate the site
field and might improve DRY. What do you think?
cms/api.py
Outdated
# 3. The matching path is not the child of our page | ||
if existing_url_collision.exists(): | ||
# For parent pages, the collision is not a problem if it's their child | ||
if page.parent_id is not None: |
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 am wondering if we cen reduce the amount of repeated code if we use the validator here?
|
||
for lang in languages_to_check: | ||
# Check if the new path exists for this language on another page on the same site | ||
existing_url_collision = ( |
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.
Again I am wondering if the check can be done in the validator to improve DRY?
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.
Great work! Thank you, @amandasavluchinske !
Description
Closes #6840
Implements slug checking when a page is moved so that there are never two pages at the same level with the same slug.
Checklist
main
Summary by Sourcery
Bug Fixes: