Skip to content

Commit b3aff25

Browse files
authored
Merge pull request #2544 from IFRCGo/feat/add-file-size-limit
Add file size limit on bulk upload
2 parents 87197e1 + 3cb1ef2 commit b3aff25

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

deploy/helm/ifrcgo-helm/values.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,8 @@ cronjobs:
272272
schedule: '0 0 * * 0'
273273
- command: 'ingest_icrc'
274274
schedule: '0 3 * * 0'
275-
# NOTE: Disabling local unit email notification for now
276-
# - command: 'notify_validators'
277-
# schedule: '0 0 * * *'
275+
- command: 'notify_validators'
276+
schedule: '0 0 * * *'
278277
# https://github.com/jazzband/django-oauth-toolkit/blob/master/docs/management_commands.rst#cleartokens
279278
- command: 'oauth_cleartokens'
280279
schedule: '0 1 * * *'

local_units/management/commands/notify_validators.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import timedelta
22

3+
from django.conf import settings
34
from django.core.management.base import BaseCommand
45
from django.template.loader import render_to_string
56
from django.utils import timezone
@@ -21,21 +22,28 @@ class Command(BaseCommand):
2122
@monitor(monitor_slug=SentryMonitor.NOTIFY_VALIDATORS)
2223
def handle(self, *args, **options):
2324
self.stdout.write(self.style.NOTICE("Notifying the validators..."))
24-
25+
# NOTE: In production use standard email notification time(7days/14days),shorter delays(1day/2days) elsewhere for testing
26+
production = settings.GO_ENVIRONMENT == "production"
27+
if production:
28+
regional_email_notification_days = 7
29+
global_email_notification_days = 14
30+
else:
31+
regional_email_notification_days = 1
32+
global_email_notification_days = 2
2533
# Regional Validators: 14 days
2634
queryset_for_regional_validators = LocalUnit.objects.filter(
2735
status__in=[LocalUnit.Status.UNVALIDATED, LocalUnit.Status.PENDING_EDIT_VALIDATION],
2836
is_deprecated=False,
2937
last_sent_validator_type=Validator.LOCAL,
30-
created_at__lte=timezone.now() - timedelta(days=7),
38+
created_at__lte=timezone.now() - timedelta(days=regional_email_notification_days),
3139
)
3240

3341
# Global Validators: 28 days
3442
queryset_for_global_validators = LocalUnit.objects.filter(
3543
status__in=[LocalUnit.Status.UNVALIDATED, LocalUnit.Status.PENDING_EDIT_VALIDATION],
3644
is_deprecated=False,
3745
last_sent_validator_type=Validator.REGIONAL,
38-
created_at__lte=timezone.now() - timedelta(days=14),
46+
created_at__lte=timezone.now() - timedelta(days=global_email_notification_days),
3947
)
4048

4149
for local_unit in queryset_for_regional_validators:

local_units/serializers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,8 @@ class Meta:
699699
def validate_file(self, file):
700700
if not file.name.endswith(".csv"):
701701
raise serializers.ValidationError(gettext("File must be a CSV file."))
702+
if file.size > 10 * 1024 * 1024:
703+
raise serializers.ValidationError(gettext("File must be less than 10 MB."))
702704
return file
703705

704706
def get_file_name(self, obj):

local_units/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ class ExternallyManagedLocalUnitViewSet(
401401
class LocalUnitBulkUploadViewSet(
402402
mixins.CreateModelMixin,
403403
mixins.ListModelMixin,
404+
mixins.RetrieveModelMixin,
404405
viewsets.GenericViewSet,
405406
):
406407
queryset = LocalUnitBulkUpload.objects.select_related("country", "local_unit_type", "triggered_by").order_by("-triggered_at")

main/sentry.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ class SentryMonitor(models.TextChoices):
128128
INGEST_NS_DOCUMENT = "ingest_ns_document", "0 0 * * 0"
129129
INGEST_NS_INITIATIVES = "ingest_ns_initiatives", "0 0 * * 0"
130130
INGEST_ICRC = "ingest_icrc", "0 3 * * 0"
131-
# NOTE: Disabling local unit email notification for now
132-
# NOTIFY_VALIDATORS = "notify_validators", "0 0 * * *"
131+
NOTIFY_VALIDATORS = "notify_validators", "0 0 * * *"
133132
OAUTH_CLEARTOKENS = "oauth_cleartokens", "0 1 * * *"
134133

135134
@staticmethod

notifications/templates/email/local_units/local_unit.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h3>Dear {{full_name}}</h3>
1616

1717
{% if update_local_unit %}
1818
<td align="center" class="pb-30">
19-
The local unit "{{local_branch_name}}" in {{country}} has been updated. Reason:"{{update_reason_overview}}" and is awaiting your validation. Kindly review the information and validate or delete as necessary.
19+
The local unit "{{local_branch_name}}" in {{country}} has been updated. Reason: {{update_reason_overview}} and is awaiting your validation. Kindly review the information and validate or delete as necessary.
2020
You can view the updated local unit <a href="{{ frontend_url }}/countries/{{country_id}}/ns-overview/context-and-structure" target="_blank" class="link" style="font-family: 'Lato', Arial, sans-serif;text-decoration: underline;color: #000;">here.</a>
2121
</td>
2222
{% endif %}

0 commit comments

Comments
 (0)