Skip to content

Commit a49615a

Browse files
committed
Limiting locales for each concept to max 500
1 parent bef2fa2 commit a49615a

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

core/concepts/constants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
OPENMRS_CONCEPT_CLASS = 'Invalid concept class'
2626
BASIC_DESCRIPTION_CANNOT_BE_EMPTY = 'Concept description cannot be empty'
2727
BASIC_NAMES_CANNOT_BE_EMPTY = 'A concept must have at least one name'
28+
MAX_LOCALES_LIMIT = 500
29+
MAX_NAMES_LIMIT = 'max limit {} of names exceeded'.format(MAX_LOCALES_LIMIT)
30+
MAX_DESCRIPTIONS_LIMIT = 'max limit {} of descriptions exceeded'.format(MAX_LOCALES_LIMIT)
2831
CONCEPT_WAS_RETIRED = 'Concept was retired'
2932
CONCEPT_WAS_UNRETIRED = 'Concept was un-retired'
3033
CONCEPT_IS_ALREADY_RETIRED = 'Concept is already retired'

core/concepts/models.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
encode_string, decode_string
1515
from core.concepts.constants import CONCEPT_TYPE, LOCALES_FULLY_SPECIFIED, LOCALES_SHORT, LOCALES_SEARCH_INDEX_TERM, \
1616
CONCEPT_WAS_RETIRED, CONCEPT_IS_ALREADY_RETIRED, CONCEPT_IS_ALREADY_NOT_RETIRED, CONCEPT_WAS_UNRETIRED, \
17-
PERSIST_CLONE_ERROR, PERSIST_CLONE_SPECIFY_USER_ERROR, ALREADY_EXISTS, CONCEPT_REGEX
17+
PERSIST_CLONE_ERROR, PERSIST_CLONE_SPECIFY_USER_ERROR, ALREADY_EXISTS, CONCEPT_REGEX, MAX_LOCALES_LIMIT, \
18+
MAX_NAMES_LIMIT, MAX_DESCRIPTIONS_LIMIT
1819
from core.concepts.mixins import ConceptValidationMixin
1920

2021

@@ -548,6 +549,7 @@ def persist_new(cls, data, user=None, create_initial_version=True, create_parent
548549
return concept
549550

550551
try:
552+
concept.validate_locales_limit(names, descriptions)
551553
concept.cloned_names = names
552554
concept.cloned_descriptions = descriptions
553555
concept.full_clean()
@@ -615,6 +617,8 @@ def persist_clone(
615617
prev_latest_version = versioned_object.versions.exclude(id=obj.id).filter(is_latest_version=True).first()
616618
try:
617619
with transaction.atomic():
620+
cls.validate_locales_limit(obj.cloned_names, obj.cloned_descriptions)
621+
618622
cls.pause_indexing()
619623

620624
obj.is_latest_version = True
@@ -666,6 +670,13 @@ def index_all():
666670

667671
return errors
668672

673+
@staticmethod
674+
def validate_locales_limit(names, descriptions):
675+
if len(names) > MAX_LOCALES_LIMIT:
676+
raise ValidationError({'names': [MAX_NAMES_LIMIT]})
677+
if len(descriptions) > MAX_LOCALES_LIMIT:
678+
raise ValidationError({'descriptions': [MAX_DESCRIPTIONS_LIMIT]})
679+
669680
def get_unidirectional_mappings_for_collection(self, collection_url, collection_version=HEAD):
670681
from core.mappings.models import Mapping
671682
return Mapping.objects.filter(

0 commit comments

Comments
 (0)