MozillaFoundation / foundation.mozilla.org

Mozilla Foundation website
https://foundation.mozilla.org
Mozilla Public License 2.0
387 stars 153 forks source link

[Main Nav] Restrict image icon choosers to SVG #12232

Closed data-sync-user closed 4 months ago

data-sync-user commented 5 months ago

Image choosers on featured icons and topic icons currently offer no restrictions on image formats that can be used/added to a dropdown. However, the backend/templates assume that they will be SVGs. We need to provide proper validation for this. We can use ImageChooser(validators=[MySVGValidator]) and write up the proper validator, such as with this Wagtail example.

A potential implementation:

from django.core.validators import FileExtensionValidator

def SVGImageFormatValidator(value):
    return FileExtensionValidator(allowed_extensions=["svg"])(value)

However, this gets tricky with the relationships for featured topics, as we only have access to an integer that is the image’s FK.

Maybe removing the SVG assumptions on the backend and trusting the editors could also be a way forward… (although I don’t like this as much)

┆Issue is synchronized with this Jira Story

data-sync-user commented 4 months ago

➤ Daniel Miranda commented:

The PR for this ticket has been merged into the new navigation bar feature branch 👍