Skip to content

Conversation

@fsbraun
Copy link
Member

@fsbraun fsbraun commented Aug 21, 2025

Description

In Django CMS 4+ placeholder changeability depends on the PlaceholderRelationField's check mechanism. In Django CMS 5 the structure board works for immutable models (such as published ones).

However, since the checks base on the PlaceholderRelationField, it means that placeholders belonging to different PlaceholderRelationFields might have different rules if they can be changed or not. This possibility has not been considered in the implementation.

While rare, this can happen within a model (with multiple RelaceholderRelationFields) or when displaying placeholders from a different model (e.g., static alias placeholders).

This PR fixes some inconsistencies in the frontend for such situations:

  1. Disallows dropping of plugins in the structure board if a placeholder is readonly
  2. Disallows drawing of plugins if a placeholder is readonly
  3. Remove drag handles for plugins inside a read-only placeholder

While rare, these events otherwise lead to inconsistent states between the backend and the frontend editor.

The solution introduces a small template filter for cms_admin tags that runs the placeholder.check_source(user) method to see if a placeholder is editable. This is the exact check that the backend uses.

Related resources

  • #...
  • #...

Checklist

Summary by Sourcery

Enforce backend placeholder changeability rules in the frontend by introducing a templating filter and context updates, disabling plugin interactions and updating styles for read-only placeholders to maintain consistent editor behavior

Bug Fixes:

  • Disable plugin drag-and-drop, drawing, and control buttons for read-only placeholders in the structure board and toolbar to match backend editability rules
  • Remove drag handles for plugins inside disabled placeholders to avoid inconsistent frontend states

Enhancements:

  • Add placeholder_is_editable template filter and pass placeholder into collect_plugin_data context to enable editability checks in templates
  • Refactor SCSS to adjust draggable item padding and hide drag handles for disabled placeholders

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 21, 2025

Reviewer's Guide

This PR enforces placeholder-specific editability in the frontend by introducing a placeholder_is_editable filter tied to the backend’s check_source method and wiring it into toolbar templates and styles to disable drag, drop, and plugin operations in read-only placeholders, alongside refactoring Sass spacing.

Class diagram for Placeholder and placeholder_is_editable filter

classDiagram
    class Placeholder {
        +check_source(user)
    }
    class placeholder_is_editable {
        <<filter>>
        +__call__(placeholder, user)
    }
    placeholder_is_editable --> Placeholder: uses check_source(user)
Loading

File-Level Changes

Change Details Files
Introduce placeholder_is_editable filter and pass placeholder context
  • Define placeholder_is_editable filter in cms_admin templatetag
  • Include placeholder in plugin context in collect_plugin_data
cms/templatetags/cms_admin.py
cms/toolbar/utils.py
Wire placeholder changeability checks into frontend templates to disable UI actions
  • Load cms_admin in dragitem, dragbar, toolbar_with_structure templates
  • Apply placeholder
placeholder_is_editable:request.user in conditionals to disable drag, drop, add, cut, paste controls
Refactor Sass for structure board spacing and hide drag handles in read-only placeholders
  • Remove hardcoded margin-inline-start and use $structure-draggable-inner-padding with math.div
  • Add CSS rule to remove drag handle background for .cms-drag-disabled
cms/static/cms/sass/components/_structureboard.scss

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!

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

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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `cms/templates/cms/toolbar/dragitem.html` </location>
<code_context>
+                {% if not allow_children or object_is_immutable or not placeholder|placeholder_is_editable:request.user %} cms-btn-disabled{% endif %}
</code_context>

<issue_to_address>
Tooltip message may not fully reflect all disabled states.

The tooltip should account for cases where the button is disabled due to permissions or immutability, not just the lack of allowed children.
</issue_to_address>

### Comment 2
<location> `cms/static/cms/sass/components/_structureboard.scss:453` </location>
<code_context>
             display: none !important;
         }
     }
+    .cms-drag-disabled.cms-draggable .cms-dragitem {
+        // Remove drag handle from read-only dragables
+        background-image: none;
</code_context>

<issue_to_address>
Selector specificity may cause unintended style overrides.

Please verify that this selector does not unintentionally affect styles for non-disabled drag items, particularly in nested contexts.
</issue_to_address>

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 requested a review from vinitkumar August 21, 2025 19:59
@codecov
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.61%. Comparing base (150c3bc) to head (f6b36bb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8317   +/-   ##
=======================================
  Coverage   89.60%   89.61%           
=======================================
  Files         129      129           
  Lines       12710    12721   +11     
=======================================
+ Hits        11389    11400   +11     
  Misses       1321     1321           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fsbraun fsbraun changed the title fix: Respect placeholder checks of different PlaceholderRelationFields fix: Respect individual placeholder checks if they can be changed Aug 21, 2025
@fsbraun fsbraun added needs to be backported Commits need to be backported and removed kind: bug labels Aug 21, 2025
@vinitkumar vinitkumar merged commit dc20af8 into main Aug 22, 2025
68 checks passed
@vinitkumar
Copy link
Member

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

fsbraun added a commit that referenced this pull request Aug 22, 2025
)

* fix: Respect placeholder checks of different PlaceholderRelationFields

* fix: tests

* fix: More specific css rule

* fix: Performance optimization

* Update cms/templates/cms/toolbar/dragbar.html

* feat: Add preview option

* feat: Add edit button icon

* tests: Add test for get_edit_url template tag

* fix: Avoid static pin to be selectable

* tests: add test for plcaeholder_is_immutable filter

* fix: ruff issues

* Fix: formatting (missing tab)
fsbraun added a commit that referenced this pull request Aug 22, 2025
) (#8318)

* fix: Respect placeholder checks of different PlaceholderRelationFields

* fix: tests

* fix: More specific css rule

* fix: Performance optimization

* Update cms/templates/cms/toolbar/dragbar.html

* feat: Add preview option

* feat: Add edit button icon

* tests: Add test for get_edit_url template tag

* fix: Avoid static pin to be selectable

* tests: add test for plcaeholder_is_immutable filter

* fix: ruff issues

* Fix: formatting (missing tab)
@fsbraun fsbraun deleted the fix/plugintree branch September 30, 2025 11:33
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.

3 participants