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

Add resource's description size limit #2586

Merged
merged 3 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Add resource's description and title size limit [#2586](https://github.com/opendatateam/udata/pull/2586)

## 2.5.1 (2020-12-31)

Expand Down
12 changes: 7 additions & 5 deletions udata/core/dataset/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .models import (
Dataset, Resource, License, Checksum, CommunityResource,
UPDATE_FREQUENCIES, DEFAULT_FREQUENCY, RESOURCE_FILETYPES, CHECKSUM_TYPES,
LEGACY_FREQUENCIES, RESOURCE_TYPES,
LEGACY_FREQUENCIES, RESOURCE_TYPES, TITLE_SIZE_LIMIT, DESCRIPTION_SIZE_LIMIT,
ResourceSchema,
)

Expand Down Expand Up @@ -43,8 +43,10 @@ def enforce_allowed_schemas(form, field):


class BaseResourceForm(ModelForm):
title = fields.StringField(_('Title'), [validators.DataRequired()])
description = fields.MarkdownField(_('Description'))
title = fields.StringField(
_('Title'), [validators.DataRequired(), validators.Length(max=TITLE_SIZE_LIMIT)])
description = fields.MarkdownField(
_('Description'), [validators.Length(max=DESCRIPTION_SIZE_LIMIT)])
filetype = fields.RadioField(
_('File type'), [validators.DataRequired()],
choices=list(RESOURCE_FILETYPES.items()), default='file',
Expand Down Expand Up @@ -103,11 +105,11 @@ class DatasetForm(ModelForm):
model_class = Dataset

title = fields.StringField(
_('Title'), [validators.DataRequired(), validators.Length(max=350)])
_('Title'), [validators.DataRequired(), validators.Length(max=TITLE_SIZE_LIMIT)])
acronym = fields.StringField(_('Acronym'),
description=_('An optional acronym'))
description = fields.MarkdownField(
_('Description'), [validators.DataRequired(), validators.Length(max=100000)],
_('Description'), [validators.DataRequired(), validators.Length(max=DESCRIPTION_SIZE_LIMIT)],
description=_('The details about the dataset '
'(collection process, specifics...).'))
license = fields.ModelSelectField(
Expand Down
3 changes: 3 additions & 0 deletions udata/core/dataset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@

SCHEMA_CACHE_DURATION = 60 * 5 # In seconds

TITLE_SIZE_LIMIT = 350
DESCRIPTION_SIZE_LIMIT = 100000


def get_json_ld_extra(key, value):
'''Serialize an extras key, value pair into JSON-LD'''
Expand Down
6 changes: 3 additions & 3 deletions udata/core/discussions/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from udata.forms import ModelForm, Form, fields, validators
from udata.i18n import lazy_gettext as _

from .models import Discussion
from .models import Discussion, COMMENT_SIZE_LIMIT

__all__ = ('DiscussionCreateForm', 'DiscussionCommentForm')

Expand All @@ -11,12 +11,12 @@ class DiscussionCreateForm(ModelForm):

title = fields.StringField(_('Title'), [validators.DataRequired()])
comment = fields.StringField(
_('Comment'), [validators.DataRequired(), validators.Length(max=50000)])
_('Comment'), [validators.DataRequired(), validators.Length(max=COMMENT_SIZE_LIMIT)])
subject = fields.ModelField(_('Subject'), [validators.DataRequired()])
extras = fields.ExtrasField()


class DiscussionCommentForm(Form):
comment = fields.StringField(
_('Comment'), [validators.DataRequired(), validators.Length(max=50000)])
_('Comment'), [validators.DataRequired(), validators.Length(max=COMMENT_SIZE_LIMIT)])
close = fields.BooleanField(default=False)
3 changes: 3 additions & 0 deletions udata/core/discussions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
log = logging.getLogger(__name__)


COMMENT_SIZE_LIMIT = 50000


class Message(db.EmbeddedDocument):
content = db.StringField(required=True)
posted_on = db.DateTimeField(default=datetime.now, required=True)
Expand Down
7 changes: 4 additions & 3 deletions udata/core/organization/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from udata.i18n import lazy_gettext as _

from .models import (
Organization, MembershipRequest, Member, LOGO_SIZES, ORG_ROLES
Organization, MembershipRequest, Member, LOGO_SIZES, ORG_ROLES,
TITLE_SIZE_LIMIT, DESCRIPTION_SIZE_LIMIT
)

__all__ = (
Expand All @@ -17,11 +18,11 @@
class OrganizationForm(ModelForm):
model_class = Organization

name = fields.StringField(_('Name'), [validators.DataRequired(), validators.Length(max=350)])
name = fields.StringField(_('Name'), [validators.DataRequired(), validators.Length(max=TITLE_SIZE_LIMIT)])
acronym = fields.StringField(
_('Acronym'), description=_('Shorter organization name'))
description = fields.MarkdownField(
_('Description'), [validators.DataRequired(), validators.Length(max=20000)],
_('Description'), [validators.DataRequired(), validators.Length(max=DESCRIPTION_SIZE_LIMIT)],
description=_('The details about your organization'))
url = fields.URLField(
_('Website'), description=_('The organization website URL'))
Expand Down
3 changes: 3 additions & 0 deletions udata/core/organization/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
PUBLIC_SERVICE = 'public-service'
CERTIFIED = 'certified'

TITLE_SIZE_LIMIT = 350
DESCRIPTION_SIZE_LIMIT = 100000


class Team(db.EmbeddedDocument):
name = db.StringField(required=True)
Expand Down
6 changes: 3 additions & 3 deletions udata/core/reuse/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from udata.i18n import lazy_gettext as _
from udata.models import Reuse, REUSE_TYPES

from .models import IMAGE_SIZES
from .models import IMAGE_SIZES, TITLE_SIZE_LIMIT, DESCRIPTION_SIZE_LIMIT

__all__ = ('ReuseForm', )

Expand All @@ -16,9 +16,9 @@ def check_url_does_not_exists(form, field):
class ReuseForm(ModelForm):
model_class = Reuse

title = fields.StringField(_('Title'), [validators.DataRequired(), validators.Length(max=350)])
title = fields.StringField(_('Title'), [validators.DataRequired(), validators.Length(max=TITLE_SIZE_LIMIT)])
description = fields.MarkdownField(
_('Description'), [validators.DataRequired(), validators.Length(max=20000)],
_('Description'), [validators.DataRequired(), validators.Length(max=DESCRIPTION_SIZE_LIMIT)],
description=_('The details about the reuse (build process, specifics, '
'self-critics...).'))
type = fields.SelectField(_('Type'), choices=list(REUSE_TYPES.items()))
Expand Down
3 changes: 3 additions & 0 deletions udata/core/reuse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
IMAGE_SIZES = [100, 50, 25]
IMAGE_MAX_SIZE = 800

TITLE_SIZE_LIMIT = 350
DESCRIPTION_SIZE_LIMIT = 100000


class ReuseQuerySet(db.OwnedQuerySet):
def visible(self):
Expand Down