Skip to content
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: Proper registration of third-party RTE (CKEditor4 or 5, or other) #47

Merged
merged 4 commits into from
Dec 30, 2024

Conversation

fsbraun
Copy link
Member

@fsbraun fsbraun commented Dec 30, 2024

Fixes #46

Summary by Sourcery

Fix the registration of third-party rich text editors by correcting the configuration loading logic and caching. Enhance code maintainability by introducing a constant for maximum RTE length and ensure RTE names are truncated appropriately. Add an integration test to verify editor save functionality in Django CMS 4.

Bug Fixes:

  • Fix the registration process for third-party rich text editors by ensuring proper configuration loading and caching.

Enhancements:

  • Introduce a constant for maximum RTE length to improve code maintainability.
  • Ensure the RTE name is truncated to the maximum allowed length when saving models.

Tests:

  • Add a new integration test to verify that the editor saves content correctly in Django CMS 4.

Copy link
Contributor

sourcery-ai bot commented Dec 30, 2024

Reviewer's Guide by Sourcery

This pull request fixes an issue with third-party rich text editors not being registered correctly. The fix involves ensuring that the editor name is correctly extracted and used for registration, and that the editor name is truncated to a maximum length when saved to the database.

Sequence diagram for third-party RTE registration and usage

sequenceDiagram
    participant App as Application
    participant Config as Editor Config
    participant Registry as RTE Registry
    participant Model as Text Model

    App->>Config: get_editor_config(editor)
    Config->>Config: Extract config_name
    alt Third-party editor not registered
        Config->>Config: Import module
        Config->>Registry: register(rte_config_instance)
    end
    Config->>App: Return configuration
    App->>Model: Save text with RTE
    Note over Model: Truncate RTE name to
    Note over Model: max length (16 chars)
Loading

Class diagram showing Text model changes

classDiagram
    class AbstractText {
        +CharField rte
    }
    note for AbstractText "rte field max_length=16"

    class RTEConfig {
        +String name
        +register()
    }

    AbstractText --> RTEConfig: uses
Loading

File-Level Changes

Change Details Files
Fix registration of third-party RTEs
  • Corrected the extraction of the editor name from the configuration.
  • Used the corrected editor name for registration and caching.
  • Ensured that the editor name is truncated to a maximum length when saved to the database to avoid errors.
djangocms_text/editors.py
Add integration test for editor save functionality
  • Added a test to verify that the editor saves correctly when using CKEditor 4.
  • Included assertions to check for successful save operation.
tests/integration/test_ckeditor4.py
Set maximum length for RTE name field
  • Defined a constant for the maximum length of the RTE name field.
  • Used the constant to set the max_length attribute of the rte field in the AbstractText model.
  • Truncated the editor name to the maximum length before saving it to the model.
djangocms_text/models.py
djangocms_text/cms_plugins.py
Set height of ProseMirror editor to 100%
  • Set the height of the ProseMirror editor to 100% to improve usability.
private/css/cms.tiptap.css

Assessment against linked issues

Issue Objective Addressed Explanation
#46 Fix the 'value too long for type character varying(16)' error when creating or editing text plugins with CKEditor 4 or 5
#46 Ensure that the RTE (Rich Text Editor) name is properly truncated to fit within the database field length
#46 Modify the editor configuration registration to handle full module path editor configurations

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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

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.

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.20%. Comparing base (f2fbbac) to head (221c99b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #47      +/-   ##
==========================================
+ Coverage   81.16%   81.20%   +0.04%     
==========================================
  Files          17       17              
  Lines         929      931       +2     
  Branches      104      104              
==========================================
+ Hits          754      756       +2     
  Misses        132      132              
  Partials       43       43              

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

@fsbraun fsbraun merged commit 733bd84 into main Dec 30, 2024
31 checks passed
@fsbraun fsbraun deleted the fix/third-party-rte branch December 30, 2024 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create or edit a text plugin with CKEditor 4 or 5 fails on error 'value too long'
1 participant