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

Implement feature to allow Admin to create/update FAQ content #412

Closed

Conversation

lcduong
Copy link
Contributor

@lcduong lcduong commented Oct 25, 2024

This issue part of #383

  • In common component, add another setting page (only visible for admin)

image

  • Admin can create/update FAQ title, content

image

Summary by Sourcery

Implement a new feature allowing admins to create and update FAQ content using a rich text editor. This includes a new settings page accessible only to admins and the integration of the Quill editor for content management.

New Features:

  • Add a feature for admins to create and update FAQ content through a new settings page.

Enhancements:

  • Integrate Quill rich text editor for enhanced content editing capabilities.

Documentation:

  • Add user-facing documentation for the new FAQ feature, including instructions on how to use the editor.

Copy link

sourcery-ai bot commented Oct 25, 2024

Reviewer's Guide by Sourcery

This PR implements a feature that allows admin users to create and update FAQ content through a new admin page. The implementation includes integration of the Quill rich text editor for content management, with support for text formatting, images, and other rich content features.

Class diagram for PageSettingsForm and PageCreate

classDiagram
    class PageSettingsForm {
        +I18nFormField faq_title
        +I18nFormField faq_content
        +_store_image(image_src) ContentFile
        +clean_faq_content() I18nFormField
        +clean() dict
    }
    class PageCreate {
        +get_context_data() dict
        +form_valid(form) HttpResponse
        +form_invalid(form) HttpResponse
        +get_success_url() str
    }
    PageCreate --> PageSettingsForm
    note for PageSettingsForm "Handles FAQ title and content with image storage"
    note for PageCreate "Admin page for creating and updating FAQ content"
Loading

File-Level Changes

Change Details Files
Added new admin page for FAQ content management
  • Created new PageCreate view for FAQ content management
  • Added PageSettingsForm to handle FAQ title and content fields
  • Added ShowPageView to display FAQ content to users
  • Implemented image upload and storage functionality for rich content
src/pretix/eventyay_common/forms/page.py
src/pretix/eventyay_common/views/pages.py
src/pretix/eventyay_common/templates/eventyay_common/pages/show.html
Integrated Quill rich text editor
  • Added Quill editor core JavaScript library
  • Added Quill editor CSS styles and themes
  • Created custom editor initialization and configuration script
  • Added support for text formatting, lists, alignment, and images
src/pretix/static/pages/js/quill.core.js
src/pretix/static/pages/css/quill.snow.css
src/pretix/static/pages/css/quill.bubble.css
src/pretix/static/pages/css/quill.core.css
src/pretix/static/pages/js/editor.js
Updated navigation and routing
  • Added FAQ link to navigation bar
  • Added new URL patterns for FAQ pages
  • Updated global navigation to include FAQ section for admin users
src/pretix/control/templates/pretixcontrol/auth/base.html
src/pretix/eventyay_common/context.py
src/pretix/eventyay_common/urls.py
src/pretix/api/urls.py

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

@lcduong lcduong marked this pull request as ready for review October 28, 2024 03:17
Copy link

@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 @lcduong - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding size limits for content and image uploads to prevent abuse of storage resources. You may want to validate both the overall content size and individual image sizes before saving.
  • The current image upload flow of converting data URIs to files works but could be inefficient for large images. Consider implementing direct file uploads instead, which would be more efficient and give you better control over the upload process.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟡 Security: 2 issues found
  • 🟢 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.

"image/webp": "webp",
}

def _store_image(self, image_src):
Copy link

Choose a reason for hiding this comment

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

🚨 issue (security): Image storage needs additional validation and configurable paths

The image storage should validate file size and dimensions, use configurable paths instead of hardcoded ones, and implement rate limiting to prevent abuse.

return default_storage.url(stored_name)
return None

def clean_faq_content(self):
Copy link

Choose a reason for hiding this comment

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

issue: Add error handling for HTML parsing

The HTML parsing should be wrapped in try/except to handle malformed HTML gracefully and provide user-friendly error messages.

page_title, page_content = self.get_page(page=kwargs.get("page"))
ctx["page_title"] = str(LazyI18nString(page_title))

attributes = dict(bleach.ALLOWED_ATTRIBUTES)
Copy link

Choose a reason for hiding this comment

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

🚨 suggestion (security): Tighten bleach HTML sanitization configuration

The bleach configuration should be more restrictive. Consider limiting allowed attributes further and adding URL validation for links and images.

        attributes = {
            'a': ['href', 'title', 'rel'],
            'img': ['src', 'alt', 'title'],
            'p': ['style'],
            'span': ['style'],
            'div': ['style']
        }

@mariobehling
Copy link
Member

We do not need an implementation of an FAQ at the moment. We need an implementation of the actual logic of the business processes. Therefore no need to work on this PR at the moment.

@mariobehling
Copy link
Member

Duplicate with #379

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants