Skip to content

Commit

Permalink
Track form update notifications
Browse files Browse the repository at this point in the history
Signed-off-by: Kipchirchir Sigei <arapgodsmack@gmail.com>
  • Loading branch information
KipSigei committed Oct 19, 2022
1 parent 077f0c7 commit 967975a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion onadata/apps/api/viewsets/export_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rest_framework.viewsets import ReadOnlyModelViewSet

from onadata.apps.api.permissions import ExportDjangoObjectPermission
from onadata.apps.messaging.constants import EXPORT, EXPORT_DELETED, XFORM
from onadata.apps.messaging.constants import EXPORT_DELETED, XFORM
from onadata.apps.messaging.serializers import send_message
from onadata.apps.viewer.models.export import Export
from onadata.libs import filters
Expand Down
3 changes: 1 addition & 2 deletions onadata/apps/api/viewsets/project_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
The /projects API endpoint implementation.
"""
from email import message
from django.core.cache import cache
from django.core.mail import send_mail
from django.shortcuts import get_object_or_404
Expand Down Expand Up @@ -92,7 +91,7 @@ def get_queryset(self):
)

return super().get_queryset()

def create(self, request, *args, **kwargs):
"""Creates new project"""
response = super().create(request, *args, **kwargs)
Expand Down
16 changes: 13 additions & 3 deletions onadata/apps/api/viewsets/xform_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
from onadata.apps.logger.models.xform_version import XFormVersion
from onadata.apps.logger.xform_instance_parser import XLSFormError
from onadata.apps.messaging.constants import (
FORM_UPDATED, EXPORT_CREATED, EXPORT_DELETED,
XFORM, FORM_DELETED, FORM_CREATED, PROJECT
FORM_UPDATED, EXPORT_CREATED, XFORM,
FORM_DELETED, FORM_CREATED, PROJECT
)
from onadata.apps.messaging.serializers import send_message
from onadata.apps.viewer.models.export import Export
Expand Down Expand Up @@ -261,7 +261,7 @@ def parse_webform_return_url(return_url, request):
return None


# pylint: disable=too-many-ancestors
# pylint: disable=too-many-ancestors, too-many-lines
class XFormViewSet(
AnonymousUserPublicFormsMixin,
CacheControlMixin,
Expand Down Expand Up @@ -843,6 +843,16 @@ def partial_update(self, request, *args, **kwargs):
return _try_update_xlsform(request, self.object, owner)

try:
# send notification for each form activity
if request.POST.get("title") or request.POST.get("title"):
# send form update notification
send_message(
instance_id=self.object.pk,
target_id=self.object.pk,
target_type=XFORM,
user=request.user or owner,
message_verb=FORM_UPDATED,
)
return super().partial_update(request, *args, **kwargs)
except XLSFormError as e:
raise ParseError(str(e)) from e
Expand Down

0 comments on commit 967975a

Please sign in to comment.