mirror of
https://github.com/inventree/InvenTree.git
synced 2026-09-02 10:18:42 +00:00
Run nh3 cleaner over backend notes
This commit is contained in:
@@ -30,7 +30,7 @@ from stdimage.models import StdImageField, StdImageFieldFile
|
|||||||
|
|
||||||
from common.currency import currency_code_default
|
from common.currency import currency_code_default
|
||||||
from InvenTree.sanitizer import (
|
from InvenTree.sanitizer import (
|
||||||
DEAFAULT_ATTRS,
|
DEFAULT_ATTRS,
|
||||||
DEFAULT_CSS,
|
DEFAULT_CSS,
|
||||||
DEFAULT_PROTOCOLS,
|
DEFAULT_PROTOCOLS,
|
||||||
DEFAULT_TAGS,
|
DEFAULT_TAGS,
|
||||||
@@ -963,7 +963,7 @@ def clean_markdown(value: str) -> str:
|
|||||||
|
|
||||||
# nh3 sanitizer settings
|
# nh3 sanitizer settings
|
||||||
whitelist_tags = markdownify_settings.get('WHITELIST_TAGS', DEFAULT_TAGS)
|
whitelist_tags = markdownify_settings.get('WHITELIST_TAGS', DEFAULT_TAGS)
|
||||||
whitelist_attrs = markdownify_settings.get('WHITELIST_ATTRS', DEAFAULT_ATTRS)
|
whitelist_attrs = markdownify_settings.get('WHITELIST_ATTRS', DEFAULT_ATTRS)
|
||||||
whitelist_styles = markdownify_settings.get('WHITELIST_STYLES', DEFAULT_CSS)
|
whitelist_styles = markdownify_settings.get('WHITELIST_STYLES', DEFAULT_CSS)
|
||||||
whitelist_protocols = markdownify_settings.get(
|
whitelist_protocols = markdownify_settings.get(
|
||||||
'WHITELIST_PROTOCOLS', DEFAULT_PROTOCOLS
|
'WHITELIST_PROTOCOLS', DEFAULT_PROTOCOLS
|
||||||
|
|||||||
@@ -244,7 +244,7 @@ ALLOWED_ATTRIBUTES_SVG = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
# Default allowlists (matching bleach's original defaults)
|
# Default allowlists (matching bleach's original defaults)
|
||||||
# TODO: I do not see us needing a bunch of these but I do not want to introduce a breaking change; we might want to narroy this down with the next breaking change
|
# TODO: I do not see us needing a bunch of these but I do not want to introduce a breaking change; we might want to narrow this down with the next breaking change
|
||||||
DEFAULT_TAGS = frozenset([
|
DEFAULT_TAGS = frozenset([
|
||||||
'a',
|
'a',
|
||||||
'abbr',
|
'abbr',
|
||||||
@@ -259,7 +259,7 @@ DEFAULT_TAGS = frozenset([
|
|||||||
'strong',
|
'strong',
|
||||||
'ul',
|
'ul',
|
||||||
])
|
])
|
||||||
DEAFAULT_ATTRS = {'a': {'href', 'title'}, 'abbr': {'title'}, 'acronym': {'title'}}
|
DEFAULT_ATTRS = {'a': {'href', 'title'}, 'abbr': {'title'}, 'acronym': {'title'}}
|
||||||
DEFAULT_CSS = frozenset([
|
DEFAULT_CSS = frozenset([
|
||||||
'azimuth',
|
'azimuth',
|
||||||
'background-color',
|
'background-color',
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ from django.urls import reverse
|
|||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
import nh3
|
||||||
import structlog
|
import structlog
|
||||||
from anymail.signals import inbound, tracking
|
from anymail.signals import inbound, tracking
|
||||||
from django_q.signals import post_spawn
|
from django_q.signals import post_spawn
|
||||||
@@ -3045,6 +3046,8 @@ class Note(
|
|||||||
if not others.exists():
|
if not others.exists():
|
||||||
self.primary = True
|
self.primary = True
|
||||||
|
|
||||||
|
self.clean()
|
||||||
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
# Once this note is saved, mark other notes as non-primary
|
# Once this note is saved, mark other notes as non-primary
|
||||||
@@ -3060,7 +3063,9 @@ class Note(
|
|||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
"""Clean / validate the note before saving to the database."""
|
"""Clean / validate the note before saving to the database."""
|
||||||
# TODO: Implement this
|
if self.content:
|
||||||
|
self.content = self.content.strip()
|
||||||
|
self.content = nh3.clean(self.content)
|
||||||
|
|
||||||
def check_save(self):
|
def check_save(self):
|
||||||
"""Check if this note can be saved."""
|
"""Check if this note can be saved."""
|
||||||
|
|||||||
Reference in New Issue
Block a user