8000 fix: Page menu disappeared in edit or structure endpoints when refreshing the toolbar by fsbraun · Pull Request #8137 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

fix: Page menu disappeared in edit or structure endpoints when refreshing the toolbar #8137

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

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

fsbraun
Copy link
Member
@fsbraun fsbraun commented Feb 9, 2025

Description

This PR fixes #8136 and adds a test for it.

Related resources

Checklist

  • I have opened this pull request against develop-4
  • I have added or modified the tests when changing logic
  • I have followed the conventional commits guidelines to add meaningful information into the changelog
  • I have read the contribution guidelines and I have joined the channel #pr-reviews on our Discord Server to find a “pr review buddy” who is going to review my pull request.

Summary by Sourcery

Bug Fixes:

  • Fixes an issue where the toolbar was not correctly detecting the page when accessed from the edit endpoint, resulting in incorrect page information being displayed.

Copy link
Contributor
sourcery-ai bot commented Feb 9, 2025

Reviewer's Guide by Sourcery

This PR fixes the issue where the wrong page was detected when getting the toolbar for an endpoint. The changes are implemented by updating the toolbar retrieval logic to correctly handle PageContent instances, adding a dedicated test to validate the behavior, and standardizing string quotes in tests.

Sequence diagram for toolbar page detection process

sequenceDiagram
    actor User
    participant ToolbarHandler as get_toolbar()
    participant PageFetcher as get_page_from_request()
    participant PageContent

    User->>ToolbarHandler: Call get_toolbar(request)
    alt attached_obj is an instance of PageContent
        ToolbarHandler->>PageContent: Retrieve page (attached_obj.page)
    else attached_obj is not a PageContent
        ToolbarHandler->>PageFetcher: Call get_page_from_request(request, use_path, clean_path)
    end
    ToolbarHandler->>User: Return toolbar response or error
Loading

Sequence diagram for PageContent handling in admin form cleaning

sequenceDiagram
    participant AdminForm as clean()
    participant ModelClass
    participant AdminManager
    participant ORM

    AdminForm->>ModelClass: Determine model_class type
    alt model_class is a subclass of PageContent
        AdminForm->>AdminManager: admin_manager.select_related("page").get(pk)
    else model_class has admin_manager attribute
        AdminForm->>AdminManager: admin_manager.get(pk)
    else
        AdminForm->>ORM: objects.get(pk)
    end
    AdminForm->>AdminForm: Return generic_obj
Loading

File-Level Changes

Change Details Files
Enhance toolbar detection logic in the settings admin.
  • Updated the get_toolbar method to check if the attached object is a PageContent instance.
  • Assigned current_page based on the attached PageContent instead of solely relying on get_page_from_request.
cms/admin/settingsadmin.py
Adjust admin form handling for PageContent instances.
  • Modified the clean method to use issubclass check for PageContent.
  • Changed query logic to select related page data when the model is a PageContent subclass.
cms/admin/forms.py
Improve test coverage and consistency in placeholder admin tests.
  • Standardized string quotes from single to double quotes for consistency.
  • Added a new test (test_get_toolbar_endpoint) to validate that the toolbar endpoint returns the toolbar with the page menu.
  • Updated existing tests to ensure the toolbar and placeholder endpoints work as expected.
cms/tests/test_placeholder_admin.py

Assessment against linked issues

Issue Objective Addressed Explanation
#8136 Fix the issue where copying plugins removes menus from the toolbar
#8136 Ensure the toolbar retains its 'Page' menu when copying plugins
#8136 Detect the correct page context when getting the toolbar for an endpoint

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@fsbraun fsbraun requested a review from vinitkumar February 9, 2025 21:27
@fsbraun fsbraun added needs to be backported Commits need to be backported 5.0 labels Feb 9, 2025
Copy link
Contributor
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @fsbraun - I've reviewed your changes - here's some feedback:

Overall Comments:

  • In get_toolbar, consider adding a fallback or explicit error when attached_obj is provided but isn’t a PageContent instance, so unexpected types are handled clearly.
  • In forms.py, ensure model_class is a valid type before using issubclass to avoid potential type errors.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@fsbraun fsbraun changed the title fix: Detect page when getting toolbar for endpoint fix: Page menu disappeared in edit or structure endpoints when refreshing the toolbar Feb 9, 2025
Copy link
Member
@vinitkumar vinitkumar left a comment

Choose a reason for hiding this comment

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

Looks good to me. Let's get this merged and released 🚢 🚀

@vinitkumar vinitkumar merged commit 76cb708 into develop-4 Feb 10, 2025
56 checks passed
@fsbraun fsbraun deleted the fix/toolbar branch February 10, 2025 11:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 needs to be backported Commits need to be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Copying plugins removes menus from the toolbar
2 participants
0