Skip to content

Commit

Permalink
Merge pull request #35400 from dimagi/mjr/security_watchtower
Browse files Browse the repository at this point in the history
Added security watchtower page
  • Loading branch information
mjriley authored Dec 3, 2024
2 parents 140d56c + 63d6b28 commit 23682ba
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 84 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
hqDefine("enterprise/js/enterprise_dashboard", [
hqDefine("enterprise/js/project_dashboard", [
'jquery',
'knockout',
'underscore',
Expand Down Expand Up @@ -192,30 +192,35 @@ hqDefine("enterprise/js/enterprise_dashboard", [
}

$(function () {
const datePicker = tempusDominus.createDefaultDateRangePicker(
document.getElementById("id_date_range"),
moment().subtract(30, "days"),
moment()
);

const formSubmissionsDisplay = MobileFormSubmissionsTile(datePicker);
const maxDateRangeDays = initialPageData.get("max_date_range_days");
const dateRangeModal = DateRangeModal(datePicker, dateRangePresetOptions, maxDateRangeDays, formSubmissionsDisplay);

$("#dateRangeDisplay").koApplyBindings(formSubmissionsDisplay);
$("#enterpriseFormsDaterange").koApplyBindings(
dateRangeModal
);

kissmetrics.track.event("[Enterprise Dashboard] Visited page");
const metricType = initialPageData.get('metric_type');
const $dateRangeDisplay = $("#dateRangeDisplay");
let dateRangeModal = null;
if ($dateRangeDisplay.length) {
const datePicker = tempusDominus.createDefaultDateRangePicker(
document.getElementById("id_date_range"),
moment().subtract(30, "days"),
moment()
);

const formSubmissionsDisplay = MobileFormSubmissionsTile(datePicker);
const maxDateRangeDays = initialPageData.get("max_date_range_days");
dateRangeModal = DateRangeModal(datePicker, dateRangePresetOptions, maxDateRangeDays, formSubmissionsDisplay);

$dateRangeDisplay.koApplyBindings(formSubmissionsDisplay);
$("#enterpriseFormsDaterange").koApplyBindings(
dateRangeModal
);
}

kissmetrics.track.event(`[${metricType}] Visited page`);
$(".report-panel").each(function () {
var $element = $(this),
slug = $element.data("slug");

updateDisplayTotal($element);

$element.find(".btn-primary").click(function () {
kissmetrics.track.event("[Enterprise Dashboard] Clicked Email Report for " + slug);
kissmetrics.track.event(`[${metricType}] Clicked Email Report for ` + slug);
var $button = $(this);
$button.disableButton();
const requestParams = {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{% load i18n %}

<div class="col-md-6 col-lg-6 col-xl-3">
<div class="card text-center report-panel mb-3" data-slug="{{ report.slug }}" id="{{ report.slug }}">
<div class="card-header">
<div class="fs-4">{{ report.title }}</div>
{% if report.title == "Mobile Form Submissions" %}
<button id="dateRangeDisplay" type="button" data-bind="text: presetText" data-bs-toggle="modal" data-bs-target="#enterpriseFormsDaterange" class="btn btn-link fs-6">&nbsp;</button>
{% else %}
<div class="form-control-plaintext fs-6">{{ report.subtitle|default:"&nbsp;" }}</div>
{% endif %}
</div>
<div class="card-body">
<h1 class="card-text total">
<i class="fa fa-spin fa-spinner"></i>
</h1>
<br>
<button class="btn btn-primary btn-lg">
<i class="fa fa-envelope"></i>
{% trans "Email Report" %}
</button>
</div>
</div>
</div>
23 changes: 23 additions & 0 deletions corehq/apps/enterprise/templates/enterprise/project_dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "hqwebapp/bootstrap5/base_section.html" %}
{% load hq_shared_tags %}
{% load i18n %}

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

{% js_entry 'enterprise/js/project_dashboard' %}

{% block page_content %}
{% registerurl "enterprise_dashboard_email" domain "---" %}
{% registerurl "enterprise_dashboard_total" domain "---" %}

{% initial_page_data 'max_date_range_days' max_date_range_days %}
{% initial_page_data 'metric_type' metric_type %}

<div class="row">
{% for report in reports %}
{% include 'enterprise/partials/project_tile.html' with report=report %}
{% endfor %}
</div>

{% include 'enterprise/partials/date_range_modal.html' %}
{% endblock %}
6 changes: 4 additions & 2 deletions corehq/apps/enterprise/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
add_enterprise_permissions_domain,
disable_enterprise_permissions,
edit_enterprise_settings,
enterprise_dashboard,
platform_overview,
enterprise_dashboard_download,
enterprise_dashboard_email,
enterprise_dashboard_total,
enterprise_permissions,
enterprise_settings,
remove_enterprise_permissions_domain,
security_center,
update_enterprise_permissions_source_domain,
ManageEnterpriseMobileWorkersView,
)
Expand All @@ -28,7 +29,7 @@
]

domain_specific = [
url(r'^dashboard/$', enterprise_dashboard, name='enterprise_dashboard'),
url(r'^dashboard/$', platform_overview, name='platform_overview'),
url(r'^dashboard/(?P<slug>[^/]*)/download/(?P<export_hash>[\w\-]+)/$', enterprise_dashboard_download,
name='enterprise_dashboard_download'),
url(r'^dashboard/(?P<slug>[^/]*)/email/$', enterprise_dashboard_email,
Expand All @@ -43,6 +44,7 @@
name='remove_enterprise_permissions_domain'),
url(r'^permissions/source/$', update_enterprise_permissions_source_domain,
name='update_enterprise_permissions_source_domain'),
url(r'^security_center/$', security_center, name='security_center'),
url(r'^settings/$', enterprise_settings, name='enterprise_settings'),
url(r'^settings/edit/$', edit_enterprise_settings, name='edit_enterprise_settings'),
url(r'^billing_statements/$', EnterpriseBillingStatementsView.as_view(),
Expand Down
60 changes: 49 additions & 11 deletions corehq/apps/enterprise/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,36 @@

from corehq.apps.export.utils import get_default_export_settings_if_available

from corehq.apps.hqwebapp.context import get_page_context, Section
from corehq.apps.hqwebapp.decorators import use_bootstrap5, use_tempusdominus
from corehq.apps.hqwebapp.views import CRUDPaginatedViewMixin
from corehq.apps.users.decorators import require_can_edit_or_view_web_users

from corehq.const import USER_DATE_FORMAT
from corehq import toggles


@use_tempusdominus
@use_bootstrap5
@always_allow_project_access
@require_enterprise_admin
@login_and_domain_required
def enterprise_dashboard(request, domain):
def platform_overview(request, domain):
if not has_privilege(request, privileges.PROJECT_ACCESS):
return HttpResponseRedirect(reverse(EnterpriseBillingStatementsView.urlname, args=(domain,)))

context = {
'account': request.account,
'domain': domain,
context = get_page_context(
page_url=reverse('platform_overview', args=(domain,)),
page_title=_('Platform Overview for {}').format(request.account.name),
page_name=_('Platform Overview'),
domain=domain,
section=Section(
_('Enterprise Console'),
reverse('platform_overview', args=(domain,)),
),
)

context.update({
'max_date_range_days': EnterpriseFormReport.MAX_DATE_RANGE_DAYS,
'reports': [EnterpriseReport.create(slug, request.account.id, request.couch_user) for slug in (
EnterpriseReport.DOMAINS,
Expand All @@ -81,12 +92,39 @@ def enterprise_dashboard(request, domain):
EnterpriseReport.FORM_SUBMISSIONS,
EnterpriseReport.ODATA_FEEDS,
)],
'current_page': {
'page_name': _('Enterprise Dashboard'),
'title': _('Enterprise Dashboard'),
}
}
return render(request, "enterprise/enterprise_dashboard.html", context)
'metric_type': 'Platform Overview',
})

return render(request, "enterprise/project_dashboard.html", context)


@use_tempusdominus
@use_bootstrap5
@always_allow_project_access
@require_enterprise_admin
@login_and_domain_required
@toggles.ENTERPRISE_DASHBOARD_IMPROVEMENTS.required_decorator()
def security_center(request, domain):
if not has_privilege(request, privileges.PROJECT_ACCESS):
return HttpResponseRedirect(reverse(EnterpriseBillingStatementsView.urlname, args=(domain,)))

context = get_page_context(
page_url=reverse('security_center', args=(domain,)),
page_title=_('Security Center for {}').format(request.account.name),
page_name=_('Security Center'),
domain=domain,
section=Section(
_('Enterprise Console'),
reverse('platform_overview', args=(domain,)),
),
)

context.update({
'reports': [],
'metric_type': 'Security Center',
})

return render(request, "enterprise/project_dashboard.html", context)


@require_enterprise_admin
Expand Down Expand Up @@ -220,7 +258,7 @@ class BaseEnterpriseAdminView(BaseDomainView):

@property
def section_url(self):
return reverse('enterprise_dashboard', args=(self.domain,))
return reverse('platform_overview', args=(self.domain,))

@property
def page_url(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<li class="nav-divider divider"></li>
<li class="dropdown-header nav-header">{% trans 'Manage Enterprise' %}</li>
<li>
<a href="{% url "enterprise_dashboard" domain %}">
<a href="{% url "platform_overview" domain %}">
<i class="fa fa-cogs icon-cogs dropdown-icon"></i> {% trans "Enterprise Console" %}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<li><hr class="dropdown-divider"></li>
<li class="dropdown-header nav-header">{% trans 'Manage Enterprise' %}</li>
<li>
<a href="{% url "enterprise_dashboard" domain %}" class="dropdown-item">
<a href="{% url "platform_overview" domain %}" class="dropdown-item">
<i class="fa fa-cogs icon-cogs dropdown-icon"></i> {% trans "Enterprise Console" %}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
- <li class="nav-divider divider"></li>
- <li class="dropdown-header nav-header">{% trans 'Manage Enterprise' %}</li>
- <li>
- <a href="{% url "enterprise_dashboard" domain %}">
- <a href="{% url "platform_overview" domain %}">
- <i class="fa fa-cogs icon-cogs dropdown-icon"></i> {% trans "Enterprise Console" %}
- </a>
- </li>
Expand Down Expand Up @@ -86,7 +86,7 @@
+ <li><hr class="dropdown-divider"></li>
+ <li class="dropdown-header nav-header">{% trans 'Manage Enterprise' %}</li>
+ <li>
+ <a href="{% url "enterprise_dashboard" domain %}" class="dropdown-item">
+ <a href="{% url "platform_overview" domain %}" class="dropdown-item">
+ <i class="fa fa-cogs icon-cogs dropdown-icon"></i> {% trans "Enterprise Console" %}
</a>
- </li>
Expand Down
21 changes: 15 additions & 6 deletions corehq/tabs/tabclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -1812,16 +1812,25 @@ def sidebar_items(self):
enterprise_user_management_views = []

if has_privilege(self._request, privileges.PROJECT_ACCESS):
enterprise_views.extend([
enterprise_views.append(
{
'title': _('Enterprise Dashboard'),
'url': reverse('enterprise_dashboard', args=[self.domain]),
},
'title': _('Platform Overview'),
'url': reverse('platform_overview', args=[self.domain]),
}
)
if toggles.ENTERPRISE_DASHBOARD_IMPROVEMENTS.enabled_for_request(self._request):
enterprise_views.append(
{
'title': _('Security Center'),
'url': reverse('security_center', args=[self.domain]),
}
)
enterprise_views.append(
{
'title': _('Enterprise Settings'),
'url': reverse('enterprise_settings', args=[self.domain]),
},
])
}
)
enterprise_views.append({
'title': _('Billing Statements'),
'url': reverse('enterprise_billing_statements',
Expand Down

0 comments on commit 23682ba

Please sign in to comment.