Skip to content

Commit eeda37d

Browse files
Merge pull request #1418 from IFRCGo/develop
Security update for Django 2.2.27/28
2 parents 9acca47 + 8c325b1 commit eeda37d

File tree

11 files changed

+140
-108
lines changed

11 files changed

+140
-108
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## Unreleased
88

9+
## 1.1.438
10+
## 1.1.437
11+
12+
### Added
13+
- Nginx setup fixing
14+
- /docs/ fixing
15+
- User registration reminder job cleanup
16+
- Lang: page-number
17+
- Tidylib - adding
18+
- Sit_fields_date also to be converted
19+
920
## 1.1.436
1021

1122
### Added
@@ -1959,7 +1970,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
19591970

19601971
## 0.1.20
19611972

1962-
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.436...HEAD
1973+
[Unreleased]: https://github.com/IFRCGo/go-api/compare/1.1.438...HEAD
1974+
[1.1.438]: https://github.com/IFRCGo/go-api/compare/1.1.437...1.1.438
1975+
[1.1.437]: https://github.com/IFRCGo/go-api/compare/1.1.436...1.1.437
19631976
[1.1.436]: https://github.com/IFRCGo/go-api/compare/1.1.435...1.1.436
19641977
[1.1.435]: https://github.com/IFRCGo/go-api/compare/1.1.434...1.1.435
19651978
[1.1.434]: https://github.com/IFRCGo/go-api/compare/1.1.433...1.1.434

api/management/commands/user_registration_reminder.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,16 @@
11
from datetime import datetime, timezone, timedelta
2-
from django.db.models import Q, F, ExpressionWrapper, DurationField, Sum
3-
from django.db.models.query import QuerySet
42
from django.core.management.base import BaseCommand
5-
from django.contrib.auth.models import User
6-
from django.conf import settings
73
from django.template.loader import render_to_string
8-
from elasticsearch.helpers import bulk
9-
from utils.elasticsearch import construct_es_data
10-
from api.esconnection import ES_CLIENT
11-
from api.models import UserRegion, Region, Event, ActionsTaken, CronJob, CronJobStatus, Profile
12-
from api.logger import logger
13-
from notifications.models import RecordType, SubscriptionType, Subscription, SurgeAlert
14-
from notifications.hello import get_hello
15-
from notifications.notification import send_notification
16-
from deployments.models import PersonnelDeployment, ERU, Personnel
17-
from main.frontend import frontend_url
4+
from api.models import UserRegion, Region
185
from registrations.models import Pending
196
from notifications.notification import send_notification
20-
import html
21-
22-
23-
time_3_day = timedelta(days=3)
24-
257

268

279
class Command(BaseCommand):
2810
help = 'Send reminder about the pending registrations'
2911

3012
def diff_3_day(self):
31-
return datetime.utcnow().replace(tzinfo=timezone.utc) - time_3_day
13+
return datetime.utcnow().replace(tzinfo=timezone.utc) - timedelta(days=3)
3214

3315
def handle(self, *args, **options):
3416
region_ids = Region.objects.all().values_list('id', flat=True)

lang/permissions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ def has_permission(self, request, view):
1212
# so we'll always allow GET, HEAD or OPTIONS requests. (`view` is allowed for all)
1313
if request.method in permissions.SAFE_METHODS:
1414
return True
15+
if request.method == 'POST' and \
16+
hasattr(request, '_request') and request.path[:6] == '/docs/' and \
17+
hasattr(view, 'basename') and view.basename == 'language':
18+
return True
1519
return String.has_perm(request.user, view.kwargs['pk'])
1620

1721
def has_object_permission(self, request, view, obj):

main/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
from .celery import app as celery_app
44

55
__all__ = ['celery_app']
6-
__version__ = '1.1.437'
6+
__version__ = '1.1.438'

main/nginx.conf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,5 @@ server {
4343
proxy_pass http://unix:/home/ifrc/django_app.sock;
4444
}
4545
}
46+
47+
# This environment is CHANGE_ME_BEFORE_START.

main/runserver.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@ python manage.py collectstatic --noinput -l
99
python manage.py make_permissions
1010

1111
# Add server name(s) to django settings and nginx - later maybe only nginx would be enough, and ALLOWED_HOSTS could be "*"
12-
if [ "$API_FQDN"x = prddsgocdnapi.azureedge.netx ]; then
13-
sed -i 's/\$NGINX_SERVER_NAME/'$API_FQDN' api.go.ifrc.org goadmin.ifrc.org/g' /etc/nginx/sites-available/nginx.conf
12+
if [ "$API_FQDN"x = goadmin.ifrc.orgx ]; then
13+
sed -i 's/\$NGINX_SERVER_NAME/'$API_FQDN' api.go.ifrc.org/g' /etc/nginx/sites-available/nginx.conf
1414
else
1515
sed -i 's/\$NGINX_SERVER_NAME/'$API_FQDN'/g' /etc/nginx/sites-available/nginx.conf
1616
fi
17+
# Just a temporary test:
18+
if [ "$GO_ENVIRONMENT"x = productionx ]; then
19+
sed -i 's/CHANGE_ME_BEFORE_START/prod/' /etc/nginx/sites-available/nginx.conf
20+
else
21+
sed -i 's/CHANGE_ME_BEFORE_START/'$GO_ENVIRONMENT'/' /etc/nginx/sites-available/nginx.conf
22+
fi
1723

1824
# Prepare log files and start outputting logs to stdout
1925
touch $HOME/logs/gunicorn.log

main/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@
193193
url(r'^api/v2/event/(?P<pk>\d+)', api_views.EventViewset.as_view({'get': 'retrieve'})),
194194
url(r'^api/v2/event/(?P<slug>[-\w]+)', api_views.EventViewset.as_view({'get': 'retrieve'}, lookup_field='slug')),
195195
url(r'^api/v2/exportperresults/', per_views.ExportAssessmentToCSVViewset.as_view()),
196-
url(r'^docs/', include_docs_urls(title='IFRC Go API')),
196+
url(r'^docs/', include_docs_urls(title='IFRC Go API', public=False)),
197197
url(r'^tinymce/', include('tinymce.urls')),
198198
url(r'^admin/', RedirectView.as_view(url='/')),
199199
# url(r'^', admin.site.urls),

notifications/drf_views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime, timedelta
1+
from datetime import datetime, timedelta, timezone
22
from django.db.models import Q
33
from django_filters import rest_framework as filters
44
from rest_framework.authentication import TokenAuthentication
@@ -41,7 +41,7 @@ def get_serializer_class(self):
4141
def get_queryset(self):
4242
limit = 14 # days
4343
cond1 = Q(is_stood_down=True)
44-
cond2 = Q(end__lt=datetime.now()-timedelta(days=limit))
44+
cond2 = Q(end__lt=datetime.utcnow().replace(tzinfo=timezone.utc)-timedelta(days=limit))
4545
return SurgeAlert.objects.exclude(cond1 & cond2)
4646

4747

per/drf_views.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ def get_queryset(self):
338338

339339
class GlobalPreparednessViewset(viewsets.ReadOnlyModelViewSet):
340340
"""Global Preparedness Highlights"""
341+
# Probably not used. E.g. no 'code' in Form
341342
queryset = Form.objects.all()
342343
authentication_classes = (TokenAuthentication,)
343344
permission_classes = (IsAuthenticated,)
@@ -351,13 +352,13 @@ def get_queryset(self):
351352
last_duedate = tmz.localize(datetime(2000, 11, 15, 9, 59, 25, 0))
352353
if not next_duedate:
353354
next_duedate = tmz.localize(datetime(2222, 11, 15, 9, 59, 25, 0))
354-
queryset = FormData.objects.filter(form__updated_at__gt=last_duedate, selected_option=7).select_related('form')
355+
queryset = FormData.objects.filter(form__updated_at__gt=last_duedate, selected_answer_id=7).select_related('form')
355356
result = []
356-
for i in queryset:
357-
j = {'id': i.form.id}
358-
j.update({'code': i.form.code})
359-
j.update({'question_id': i.question_id})
360-
result.append(j)
357+
# for i in queryset:
358+
# j = {'id': i.form.id}
359+
# j.update({'code': i.form.code})
360+
# j.update({'question_id': i.question_id})
361+
# result.append(j)
361362
return result
362363

363364

0 commit comments

Comments
 (0)