Skip to content

Commit

Permalink
Merge branch 'master' into sr/connectid
Browse files Browse the repository at this point in the history
  • Loading branch information
sravfeyn committed Dec 12, 2024
2 parents 5b496a5 + 0c6d4b1 commit b7d6dd8
Show file tree
Hide file tree
Showing 74 changed files with 1,252 additions and 2,928 deletions.
25 changes: 15 additions & 10 deletions corehq/apps/app_manager/fixtures/mobile_ucr.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def __call__(self, restore_state):
return []

restore_user = restore_state.restore_user
apps = self._get_apps(restore_state, restore_user)
with restore_state.timing_context('_get_apps'):
apps = self._get_apps(restore_state, restore_user)
report_configs = self._get_report_configs(apps)
if not report_configs:
return []
Expand Down Expand Up @@ -168,6 +169,7 @@ def __init__(self, domain, report_configs):
self.reports = {}
self.domain = domain
self.report_configs = report_configs
self.add_row_index = toggles.ADD_ROW_INDEX_TO_MOBILE_UCRS.enabled(domain)

def get_data(self, key, data_source):
if key not in self.data_cache:
Expand Down Expand Up @@ -234,7 +236,8 @@ def __call__(self, restore_state, restore_user, needed_versions, report_configs)
if needed_versions.intersection({MOBILE_UCR_VERSION_1, MOBILE_UCR_MIGRATING_TO_2}):
yield _get_report_index_fixture(restore_user)
try:
self.report_data_cache.load_reports()
with restore_state.timing_context('V1 load_reports'):
self.report_data_cache.load_reports()
except Exception:
logging.exception("Error fetching reports for domain", extra={
"domain": restore_user.domain,
Expand Down Expand Up @@ -275,13 +278,11 @@ def _v1_fixture(self, restore_user, report_configs, fail_hard=False):
return root

def report_config_to_fixture(self, report_config, restore_user):
row_index_enabled = toggles.ADD_ROW_INDEX_TO_MOBILE_UCRS.enabled(restore_user.domain)

def _row_to_row_elem(
deferred_fields, filter_options_by_field, row, index, is_total_row=False,
):
row_elem = E.row(index=str(index), is_total_row=str(is_total_row))
if row_index_enabled:
if self.report_data_cache.add_row_index:
row_elem.append(E.column(str(index), id='row_index'))
for k in sorted(row.keys()):
value = serialize(row[k])
Expand Down Expand Up @@ -321,15 +322,17 @@ def __call__(self, restore_state, restore_user, needed_versions, report_configs)
yield _get_report_index_fixture(restore_user, oldest_sync_time)

try:
self.report_data_cache.load_reports(synced_fixtures)
with restore_state.timing_context('V2 load_reports'):
self.report_data_cache.load_reports(synced_fixtures)
except Exception:
logging.exception("Error fetching reports for domain", extra={
"domain": restore_user.domain,
"report_config_ids": [config.report_id for config in synced_fixtures]
})
return []

yield from self._v2_fixtures(restore_user, synced_fixtures, restore_state.params.fail_hard)
with restore_state.timing_context('_v2_fixtures'):
yield from self._v2_fixtures(restore_state, synced_fixtures)
for report_uuid in purged_fixture_ids:
yield from self._empty_v2_fixtures(report_uuid)

Expand Down Expand Up @@ -404,10 +407,12 @@ def _empty_v2_fixtures(self, report_uuid):
yield E.fixture(id=self._report_fixture_id(report_uuid))
yield E.fixture(id=self._report_filter_id(report_uuid))

def _v2_fixtures(self, restore_user, report_configs, fail_hard=False):
def _v2_fixtures(self, restore_state, report_configs):
fail_hard = restore_state.params.fail_hard
for report_config in report_configs:
try:
yield from self.report_config_to_fixture(report_config, restore_user)
with restore_state.timing_context(report_config.instance_id):
yield from self.report_config_to_fixture(report_config, restore_state.restore_user)
except ReportConfigurationNotFoundError as err:
logging.exception('Error generating report fixture: {}'.format(err))
if fail_hard:
Expand All @@ -427,7 +432,7 @@ def _v2_fixtures(self, restore_user, report_configs, fail_hard=False):
def report_config_to_fixture(self, report_config, restore_user):
def _row_to_row_elem(deferred_fields, filter_options_by_field, row, index, is_total_row=False):
row_elem = E.row(index=str(index), is_total_row=str(is_total_row))
if toggles.ADD_ROW_INDEX_TO_MOBILE_UCRS.enabled(restore_user.domain):
if self.report_data_cache.add_row_index:
row_elem.append(E('row_index', str(index)))
for k in sorted(row.keys()):
value = serialize(row[k])
Expand Down
19 changes: 19 additions & 0 deletions corehq/apps/hqadmin/static/hqadmin/js/mass_email.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
hqDefine("hqadmin/js/mass_email", [
'jquery',
'commcarehq',
], function (
$
) {
$(function () {
$('#real_email').click(function (e) {
if ($(this).prop('checked')) {
$('#warning_modal').modal('show');
e.preventDefault();
}
});

$('#accept_mass_email').click(function () {
$('#real_email').prop('checked', 'checked');
});
});
});
9 changes: 5 additions & 4 deletions corehq/apps/hqadmin/templates/hqadmin/disable_two_factor.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{% extends "hqadmin/hqadmin_base_report.html" %}
{% extends "hqwebapp/bootstrap3/base_section.html" %}
{% load i18n %}
{% load crispy_forms_tags %}

{% block reportcontent %}
<h1>{% block title %}{% trans "Temporarily Disable Two-factor Authentication" %}{% endblock %}</h1>
{% block title %}{{ current_page.page_name }}{% endblock %}

{% block page_content %}
<p>{% blocktrans %}You are about to temporarily disable two-factor authentication for {{ username }}. This
compromises their account security, are you sure?{% endblocktrans %}</p>
<div class="alert alert-warning">
<p>When temporarily disabling and resetting Two-Factor Auth it is important to verify that the request was made by the owner of the account (and not faked by someone else).</p>
<p>Please follow the <a href="https://confluence.dimagi.com/pages/viewpage.action?pageId=27362739"#Two-StepAuthentication(2FA)-StepsforsupporttoresetCommCareHQaccount\">guidelines on the wiki</a>.</p>
<p>Please follow the <a href="https://confluence.dimagi.com/pages/viewpage.action?pageId=27362739#Two-StepAuthentication(2FA)-StepsforsupporttoresetCommCareHQaccount">guidelines on the wiki</a>.</p>
</div>
{% crispy form %}
{% endblock %}
7 changes: 4 additions & 3 deletions corehq/apps/hqadmin/templates/hqadmin/disable_user.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{% extends "hqadmin/hqadmin_base_report.html" %}
{% extends "hqwebapp/bootstrap3/base_section.html" %}
{% load i18n %}
{% load crispy_forms_tags %}

{% block reportcontent %}
<h1>{% block title %}{{ verb|title }} {% trans "User Account" %}{% endblock %}</h1>
{% block title %}{{ current_page.page_name }}{% endblock %}

{% block page_content %}
<p>{% blocktrans %}You are about to {{ verb }} the user account for "{{ username }}".{% endblocktrans %}</p>
<p>This will prevent them from using CommCare HQ at all and will be enforced immediately.</p>
{% crispy form %}
Expand Down
6 changes: 4 additions & 2 deletions corehq/apps/hqadmin/templates/hqadmin/global_thresholds.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{% extends "hqadmin/hqadmin_base_report.html" %}
{% extends "hqwebapp/bootstrap3/base_section.html" %}
{% load hq_shared_tags %}

{% block reportcontent %}
{% block title %}{{ current_page.page_name }}{% endblock %}

{% block page_content %}

{% include "domain/admin/partials/bootstrap3/project_limits_table.html" %}

Expand Down
61 changes: 0 additions & 61 deletions corehq/apps/hqadmin/templates/hqadmin/hqadmin_base_report.html

This file was deleted.

30 changes: 8 additions & 22 deletions corehq/apps/hqadmin/templates/hqadmin/mass_email.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
{% extends "hqadmin/hqadmin_base_report.html" %}
{% extends "hqwebapp/bootstrap3/base_section.html" %}
{% load hq_shared_tags %}
{% load i18n %}
{% block title %}Mass Email Users{% endblock %}
{% block js-inline %} {{ block.super }}
<script>
$(function () {
$('#real_email').click(function(e) {
if($(this).prop('checked')) {
$('#warning_modal').modal();
e.preventDefault();
}
});

$('#accept_mass_email').click(function() {
$('#real_email').prop('checked', 'checked');
});
});
</script>
{% endblock %}
{% block reportcontent %}
<br><br>
{% block title %}{{ current_page.page_name }}{% endblock %}

{% js_entry_b3 "hqadmin/js/mass_email" %}

{% block page_content %}
{% if form.errors %}
<div class="alert alert-danger">{{ form.errors }}</div>
{% endif %}
Expand All @@ -28,7 +15,7 @@
This is the email mailing list tool. Please exercise caution
when using it.
</p>
</p>
<p>
Leave the <strong>email all users</strong> checkbox unchecked to send a test
email only to yourself. This is useful for verifying that
your formatting is correct before sending a real message.
Expand All @@ -49,8 +36,7 @@
name="email_subject"
type="text"
class="form-control"
placeholder="Enter subject...">
</input>
placeholder="Enter subject..."/>
</div>

<div class="form-group">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% extends "hqadmin/hqadmin_base_report.html" %}
{% extends "hqwebapp/bootstrap3/base_section.html" %}
{% load crispy_forms_tags %}
{% load i18n %}
{% block reportcontent %}
<h2>{% trans "Reprocess Messaging Case Updates" %}</h2>
<div class="row">
{% crispy form %}
</div>

{% block title %}{{ current_page.page_name }}{% endblock %}

{% block page_content %}
{% crispy form %}
{% endblock %}
6 changes: 4 additions & 2 deletions corehq/apps/hqadmin/templates/hqadmin/system_info.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{% extends "hqadmin/hqadmin_base_report.html" %}
{% extends "hqwebapp/bootstrap3/base_section.html" %}
{% load hq_shared_tags %}
{% load i18n %}
{% load humanize %}

{% js_entry_b3 'hqadmin/js/system_info' %}

{% block reportcontent %}
{% block title %}{{ current_page.page_name }}{% endblock %}

{% block page_content %}
{% initial_page_data "celery_update" celery_update %}
{% initial_page_data "couch_update" couch_update %}
{% initial_page_data "is_bigcouch" is_bigcouch %}
Expand Down
1 change: 0 additions & 1 deletion corehq/apps/hqadmin/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,4 @@
from corehq.apps.hqadmin.views.utils import (
BaseAdminSectionView,
default,
get_hqadmin_base_context,
)
15 changes: 7 additions & 8 deletions corehq/apps/hqadmin/views/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from corehq.apps.hqadmin.tasks import send_mass_emails
from corehq.apps.hqadmin.views.utils import (
BaseAdminSectionView,
get_hqadmin_base_context,
get_breadcrumbs,
)
from corehq.form_processor.exceptions import CaseNotFound
from corehq.form_processor.models import CommCareCase
Expand All @@ -40,9 +40,10 @@ def mass_email(request):
else:
form = EmailForm()

context = get_hqadmin_base_context(request)
context['hide_filters'] = True
context['form'] = form
context = {
'form': form,
**get_breadcrumbs('Mass Email Users', 'mass_email'),
}
return render(request, "hqadmin/mass_email.html", context)


Expand Down Expand Up @@ -97,11 +98,9 @@ def form(self):

@property
def page_context(self):
context = get_hqadmin_base_context(self.request)
context.update({
return {
'form': self.form,
})
return context
}

def get_case(self, case_id):
try:
Expand Down
3 changes: 1 addition & 2 deletions corehq/apps/hqadmin/views/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from corehq.apps.hqadmin.utils import get_celery_stats
from corehq.apps.hqadmin.views.utils import (
BaseAdminSectionView,
get_hqadmin_base_context,
)
from corehq.apps.hqwebapp.decorators import use_datatables, use_jquery_ui
from corehq.apps.receiverwrapper.rate_limiter import (
Expand All @@ -56,7 +55,7 @@ def dispatch(self, request, *args, **kwargs):
def page_context(self):
environment = settings.SERVER_ENVIRONMENT

context = get_hqadmin_base_context(self.request)
context = {}
context['couch_update'] = self.request.GET.get('couch_update', 5000)
context['celery_update'] = self.request.GET.get('celery_update', 10000)
context['db_update'] = self.request.GET.get('db_update', 30000)
Expand Down
8 changes: 4 additions & 4 deletions corehq/apps/hqadmin/views/users.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import csv
import itertools
import settings
import os
import urllib.parse
import uuid
from collections import Counter
from datetime import datetime, timedelta
from io import StringIO
Expand Down Expand Up @@ -56,7 +54,7 @@
SuperuserManagementForm,
OffboardingUserListForm,
)
from corehq.apps.hqadmin.views.utils import BaseAdminSectionView
from corehq.apps.hqadmin.views.utils import BaseAdminSectionView, get_breadcrumbs
from corehq.apps.hqmedia.tasks import create_files_for_ccz
from corehq.apps.ota.views import get_restore_params, get_restore_response
from corehq.apps.users.audit.change_messages import UserChangeMessage
Expand Down Expand Up @@ -457,7 +455,8 @@ def get(self, request, *args, **kwargs):

def get_context_data(self, **kwargs):
context = super(DisableUserView, self).get_context_data(**kwargs)
context['verb'] = 'disable' if self.user.is_active else 'enable'
verb = 'Disable' if self.user.is_active else 'Enable'
context.update(get_breadcrumbs(f'{verb} User Account', 'disable_user'))
context['username'] = self.username
return context

Expand Down Expand Up @@ -539,6 +538,7 @@ def get_initial(self):

def render_to_response(self, context, **response_kwargs):
context.update({
**get_breadcrumbs('Temporarily Disable Two-factor Authentication', self.urlname),
'username': self.request.GET.get("q"),
})
return super().render_to_response(context, **response_kwargs)
Expand Down
Loading

0 comments on commit b7d6dd8

Please sign in to comment.