Skip to content

Commit

Permalink
Merge pull request #35640 from dimagi/mjr/data-forwarding-report
Browse files Browse the repository at this point in the history
Added Data Forwarding Report
  • Loading branch information
mjriley authored Jan 22, 2025
2 parents 902961c + dfc7fbd commit e27fb0e
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions corehq/apps/enterprise/api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
SMSResource,
APIKeysResource,
TwoFactorAuthResource,
DataForwardingResource,
ApplicationVersionComplianceResource,
)

Expand All @@ -27,4 +28,5 @@
v1_api.register(SMSResource())
v1_api.register(APIKeysResource())
v1_api.register(TwoFactorAuthResource())
v1_api.register(DataForwardingResource())
v1_api.register(ApplicationVersionComplianceResource())
19 changes: 19 additions & 0 deletions corehq/apps/enterprise/api/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,25 @@ def get_primary_keys(self):
return ('web_user', 'api_key_name',)


class DataForwardingResource(ODataEnterpriseReportResource):
domain = fields.CharField()
service_name = fields.CharField()
service_type = fields.CharField()
last_modified = fields.DateTimeField()

REPORT_SLUG = EnterpriseReport.DATA_FORWARDING

def dehydrate(self, bundle):
bundle.data['domain'] = bundle.obj[0]
bundle.data['service_name'] = bundle.obj[1]
bundle.data['service_type'] = bundle.obj[2]
bundle.data['last_modified'] = self.convert_datetime(bundle.obj[3])
return bundle

def get_primary_keys(self):
return ('domain', 'service_name', 'service_type')


class ApplicationVersionComplianceResource(ODataEnterpriseReportResource):
mobile_worker = fields.CharField()
domain = fields.CharField()
Expand Down
32 changes: 32 additions & 0 deletions corehq/apps/enterprise/enterprise.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
)
from corehq.apps.users.models import CouchUser, HQApiKey, Invitation, WebUser

from corehq.motech.repeaters.models import Repeater


class EnterpriseReport(ABC):
DOMAINS = 'domains'
Expand All @@ -60,6 +62,7 @@ class EnterpriseReport(ABC):
SMS = 'sms'
API_KEYS = 'api_keys'
TWO_FACTOR_AUTH = '2fa'
DATA_FORWARDING = 'data_forwarding'
APP_VERSION_COMPLIANCE = 'app_version_compliance'

DATE_ROW_FORMAT = '%Y/%m/%d %H:%M:%S'
Expand Down Expand Up @@ -115,6 +118,8 @@ def create(cls, slug, account_id, couch_user, **kwargs):
report = EnterpriseAPIReport(account, couch_user, **kwargs)
elif slug == cls.TWO_FACTOR_AUTH:
report = Enterprise2FAReport(account, couch_user, **kwargs)
elif slug == cls.DATA_FORWARDING:
report = EnterpriseDataForwardingReport(account, couch_user, **kwargs)
elif slug == cls.APP_VERSION_COMPLIANCE:
report = EnterpriseAppVersionComplianceReport(account, couch_user, **kwargs)

Expand Down Expand Up @@ -740,6 +745,33 @@ def rows_for_domain(self, domain_obj):
return [(domain_obj.name,)]


class EnterpriseDataForwardingReport(EnterpriseReport):
title = gettext_lazy('Data Forwarding')
total_description = gettext_lazy('# of Data Forwarders')

@property
def headers(self):
return [_('Project Space'), _('Service Name'), _('Type'), _('Last Modified [UTC]')]

def total_for_domain(self, domain_obj):
return Repeater.objects.filter(domain=domain_obj.name).count()

def rows_for_domain(self, domain_obj):
repeaters = Repeater.objects.filter(domain=domain_obj.name)
rows = []
for repeater in repeaters:
rows.append(
[
domain_obj.name,
repeater.name,
repeater.friendly_name,
self.format_date(repeater.last_modified)
]
)

return rows


class EnterpriseAppVersionComplianceReport(EnterpriseReport):
title = gettext_lazy('Application Version Compliance')
total_description = gettext_lazy('The statistic of this tile is not currently supported')
Expand Down
1 change: 1 addition & 0 deletions corehq/apps/enterprise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def platform_overview(request, domain):
'reports': [EnterpriseReport.create(slug, request.account.id, request.couch_user)
for slug in (EnterpriseReport.ODATA_FEEDS,
EnterpriseReport.DATA_EXPORTS,
EnterpriseReport.DATA_FORWARDING,
EnterpriseReport.CASE_MANAGEMENT,)]},
],
'uses_date_range': [EnterpriseReport.FORM_SUBMISSIONS, EnterpriseReport.SMS],
Expand Down

0 comments on commit e27fb0e

Please sign in to comment.