Skip to content

Commit

Permalink
Merge branch 'master' into jt/cbc-password-read-write-pt2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jtang-1 committed Jan 23, 2025
2 parents e05499d + fe7bec3 commit a5b0498
Show file tree
Hide file tree
Showing 170 changed files with 6,666 additions and 4,627 deletions.
32 changes: 22 additions & 10 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
language: en-US
early_access: true
reviews:
high_level_summary: false
review_status: false
poem: false
collapse_walkthrough: true
changed_files_summary: false
abort_on_close: true
auto_review:
enabled: false
auto_incremental_review: false
drafts: true
high_level_summary: false
review_status: false
poem: false
changed_files_summary: false
abort_on_close: true
instructions: >-
- Consider the [code review](https://github.com/dimagi/open-source/blob/master/docs/code_review.md) and [contributing](https://github.com/dimagi/commcare-hq/blob/master/CONTRIBUTING.rst)
guides when doing a review.
- Also follow the [project standards and best practices](https://github.com/dimagi/commcare-hq/blob/master/STANDARDS.rst) guide.
path_instructions:
- path: "**/*.js"
instructions: >-
- Review the JavaScript code against the [Google JavaScript style guide](https://google.github.io/styleguide/jsguide.html) and point out any mismatches
- Also follow [this guide](https://github.com/dimagi/commcare-hq/blob/master/docs/js-guide/code-review.rst)
- path: "**/*.py"
instructions: >-
- Review the code following best practises and standards
path_filters: ["**/*.js", "**/*.py", "**/*.md", "**/*.rst", "**/*.html"]
auto_review:
enabled: false
auto_incremental_review: false
drafts: false
4 changes: 4 additions & 0 deletions corehq/apps/accounting/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ class InvoiceInterfaceBase(GenericTabularReport):
dispatcher = AccountingAdminInterfaceDispatcher
exportable = True
export_format_override = Format.CSV
is_admin_report = True

def filter_by_subscription(self, subscription):
self.subscription = subscription
Expand Down Expand Up @@ -1212,6 +1213,7 @@ class PaymentRecordInterface(GenericTabularReport):
base_template = 'accounting/report_filter_actions.html'
asynchronous = True
exportable = True
is_admin_report = True

fields = [
'corehq.apps.accounting.interface.DateCreatedFilter',
Expand Down Expand Up @@ -1303,6 +1305,7 @@ class SubscriptionAdjustmentInterface(GenericTabularReport):
base_template = 'accounting/report_filter_actions.html'
asynchronous = True
exportable = True
is_admin_report = True

fields = [
'corehq.apps.accounting.interface.DomainFilter',
Expand Down Expand Up @@ -1373,6 +1376,7 @@ class CreditAdjustmentInterface(GenericTabularReport):
base_template = 'accounting/report_filter_actions.html'
asynchronous = True
exportable = True
is_admin_report = True

fields = [
'corehq.apps.accounting.interface.NameFilter',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import "reports/js/bootstrap3/base";
import "accounting/js/widgets";
import "commcarehq";
8 changes: 0 additions & 8 deletions corehq/apps/accounting/templates/accounting/invoice_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
{% load compress %}
{% load hq_shared_tags %}

{% block js %}
{{ block.super }}
{% compress js %}
<script src="{% static 'hqwebapp/js/utils/email.js' %}"></script>
<script src="{% static 'accounting/js/widgets.js' %}"></script>
{% endcompress %}
{% endblock %}

{% block page_content %}
{% for adjust_balance_form in adjust_balance_forms %}
{% include 'accounting/partials/adjust_balance.html' %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% extends "reports/bootstrap3/base_template.html" %}
{% load hq_shared_tags %}
{% load i18n %}

{% js_entry_b3 "accounting/js/report_filter_actions" %}

{% block report_filter_actions %}
<div id="savedReports" class="{{ report_filter_form_action_css_class }}">
<button id="apply-filters" type="submit"
Expand Down
45 changes: 44 additions & 1 deletion corehq/apps/analytics/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from corehq.apps.users.dbaccessors import get_all_user_rows
from corehq.apps.users.models import WebUser
from corehq.toggles import deterministic_random
from corehq.util.dates import unix_time
from corehq.util.dates import unix_time, unix_time_in_micros
from corehq.util.decorators import analytics_task
from corehq.util.metrics import metrics_counter, metrics_gauge
from corehq.util.metrics.const import MPM_LIVESUM, MPM_MAX
Expand Down Expand Up @@ -873,3 +873,46 @@ def generate_partner_reports():
task_time.seconds,
multiprocess_mode=MPM_LIVESUM
)


def record_event(event_name, couch_user, event_properties=None):
"""
Record an event in Google Analytics.
"""
if not couch_user.analytics_enabled:
return

event_properties = event_properties or {}

timestamp = unix_time_in_micros(datetime.utcnow()) # Dimagi KISSmetrics account uses UTC

event_body = {
'client_id': couch_user._id,
'timestamp_micros': timestamp,
'events': [{
'name': event_name,
'params': event_properties,
}]
}

_record_event_task.delay(json.dumps(event_body))


@analytics_task()
def _record_event_task(event_json):
ga_secret = settings.ANALYTICS_IDS.get('GOOGLE_ANALYTICS_SECRET', None)
ga_measurement_id = settings.ANALYTICS_IDS.get('GOOGLE_ANALYTICS_MEASUREMENT_ID', None)

if not (ga_secret and ga_measurement_id):
return

res = requests.post(
'https://www.google-analytics.com/mp/collect',
headers={'Content-Type': 'application/json'},
params={
'api_secret': ga_secret,
'measurement_id': ga_measurement_id,
},
data=event_json
)
res.raise_for_status()
21 changes: 2 additions & 19 deletions corehq/apps/api/domain_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,12 @@ def dehydrate_billing_properties(self, bundle):
}

def dehydrate_calculated_properties(self, bundle):
from corehq.toggles import CALCULATED_PROPERTIES_FROM_DOMAIN_METRICS, NAMESPACE_DOMAIN
calc_prop_prefix = 'cp_'
domain_obj = _get_domain(bundle)
try:
if CALCULATED_PROPERTIES_FROM_DOMAIN_METRICS.enabled(domain_obj.name, namespace=NAMESPACE_DOMAIN):
base_properties = self._get_base_properties_from_domain_metrics(domain_obj.name)
else:
base_properties = self._get_base_properties_from_elasticsearch(domain_obj.name, calc_prop_prefix)
base_properties = self._get_base_properties_from_domain_metrics(domain_obj.name)
properties = self._add_extra_calculated_properties(base_properties, domain_obj.name, calc_prop_prefix)
except (DomainMetrics.DoesNotExist, IndexError):
except (DomainMetrics.DoesNotExist):
logging.exception('Problem getting calculated properties for {}'.format(domain_obj.name))
return {}
return properties
Expand All @@ -74,19 +70,6 @@ def _get_base_properties_from_domain_metrics(domain):
domain_metrics = DomainMetrics.objects.get(domain=domain)
return domain_metrics.to_calculated_properties()

@staticmethod
def _get_base_properties_from_elasticsearch(domain, calc_prop_prefix):
es_data = (DomainES()
.in_domains([domain])
.size(1)
.run()
.hits[0])
return {
prop_name: es_data[prop_name]
for prop_name in es_data
if prop_name.startswith(calc_prop_prefix)
}

@staticmethod
def _add_extra_calculated_properties(properties, domain, calc_prop_prefix):
try:
Expand Down
Loading

0 comments on commit a5b0498

Please sign in to comment.