Skip to content

Commit

Permalink
stats: Open "tb 330" and "tb 346" to all "CD"
Browse files Browse the repository at this point in the history
  • Loading branch information
rsebille committed Sep 12, 2024
1 parent e123886 commit fbdbb13
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 90 deletions.
17 changes: 0 additions & 17 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,23 +436,6 @@
# Kept as a setting to not let User pks or Company asp_ids in clear in the code.
STATS_SIAE_USER_PK_WHITELIST = json.loads(os.getenv("STATS_SIAE_USER_PK_WHITELIST", "[]"))
STATS_SIAE_PK_WHITELIST = json.loads(os.getenv("STATS_SIAE_PK_WHITELIST", "[]"))
STATS_CD_DEPARTMENT_WHITELIST = [
"02",
"13",
"16",
"18",
"31",
"37",
"38",
"41",
"45",
"48",
"49",
"55",
"63",
"93",
"94",
]
STATS_ACI_DEPARTMENT_WHITELIST = ["31", "84"]

# Slack notifications sent by Metabase cronjobs.
Expand Down
2 changes: 0 additions & 2 deletions itou/templates/dashboard/includes/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
</a>
{% include "dashboard/includes/stats_new_badge.html" %}
</li>
{% endif %}
{% if can_view_stats_cd_whitelist %}
<li class="d-flex justify-content-between align-items-center mb-3">
<a href="{% url 'stats:stats_cd_hiring' %}" class="btn-link btn-ico">
<i class="ri-bar-chart-line ri-lg font-weight-normal align-self-start"></i>
Expand Down
1 change: 0 additions & 1 deletion itou/www/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def dashboard(request, template_name="dashboard/dashboard.html"):
"can_view_stats_siae_etp": stats_utils.can_view_stats_siae_etp(request),
"can_view_stats_siae_orga_etp": stats_utils.can_view_stats_siae_orga_etp(request),
"can_view_stats_cd": stats_utils.can_view_stats_cd(request),
"can_view_stats_cd_whitelist": stats_utils.can_view_stats_cd_whitelist(request),
"can_view_stats_cd_aci": stats_utils.can_view_stats_cd_aci(request),
"can_view_stats_ft": stats_utils.can_view_stats_ft(request),
"can_view_stats_ph": stats_utils.can_view_stats_ph(request),
Expand Down
7 changes: 0 additions & 7 deletions itou/www/stats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@ def can_view_stats_cd(request):
)


def can_view_stats_cd_whitelist(request):
return (
can_view_stats_cd(request)
and request.current_organization.department in settings.STATS_CD_DEPARTMENT_WHITELIST
)


def can_view_stats_cd_aci(request):
return (
can_view_stats_cd(request)
Expand Down
4 changes: 0 additions & 4 deletions itou/www/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ def stats_cd_iae(request):

@login_required
def stats_cd_hiring(request):
if not utils.can_view_stats_cd_whitelist(request):
raise PermissionDenied
context = {
"pilotage_webinar_banners": [
{
Expand All @@ -357,8 +355,6 @@ def stats_cd_hiring(request):

@login_required
def stats_cd_brsa(request):
if not utils.can_view_stats_cd_whitelist(request):
raise PermissionDenied
context = {
"pilotage_webinar_banners": [
{
Expand Down
59 changes: 1 addition & 58 deletions tests/www/stats/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest
from django.contrib.messages.middleware import MessageMiddleware
from django.contrib.sessions.middleware import SessionMiddleware
from django.test import RequestFactory, override_settings
from django.test import RequestFactory

from itou.common_apps.address.departments import DEPARTMENTS, REGIONS
from itou.companies.enums import CompanyKind
Expand Down Expand Up @@ -61,63 +61,6 @@ def test_can_view_stats_siae_aci():
assert utils.can_view_stats_dashboard_widget(request)


@override_settings(STATS_CD_DEPARTMENT_WHITELIST=["93"])
def test_can_view_stats_cd_whitelist():
"""
CD as in "Conseil Départemental".
"""
# Department outside of the whitelist cannot access.
org = PrescriberOrganizationWithMembershipFactory(
authorized=True, kind=PrescriberOrganizationKind.DEPT, department="01"
)
request = get_request(org.members.get())
assert not utils.can_view_stats_cd_whitelist(request)
assert utils.can_view_stats_dashboard_widget(request)

# Admin prescriber of authorized CD can access.
org = PrescriberOrganizationWithMembershipFactory(
authorized=True, kind=PrescriberOrganizationKind.DEPT, department="93"
)
request = get_request(org.members.get())
assert utils.can_view_stats_cd_whitelist(request)
assert utils.can_view_stats_dashboard_widget(request)

# Non admin prescriber can access as well.
org = PrescriberOrganizationWithMembershipFactory(
authorized=True,
kind=PrescriberOrganizationKind.DEPT,
membership__is_admin=False,
department="93",
)
request = get_request(org.members.get())
assert utils.can_view_stats_cd_whitelist(request)
assert utils.can_view_stats_dashboard_widget(request)

# Non authorized organization does not give access.
org = PrescriberOrganizationWithMembershipFactory(
kind=PrescriberOrganizationKind.DEPT,
department="93",
)
request = get_request(org.members.get())
assert not utils.can_view_stats_cd_whitelist(request)
assert utils.can_view_stats_dashboard_widget(request)

# Non CD organization does not give access.
org = PrescriberOrganizationWithMembershipFactory(
authorized=True,
kind=PrescriberOrganizationKind.CHRS,
department="93",
)
request = get_request(org.members.get())
assert not utils.can_view_stats_cd_whitelist(request)
assert utils.can_view_stats_dashboard_widget(request)

# Prescriber without organization cannot access.
request = get_request(PrescriberFactory())
assert not utils.can_view_stats_cd_whitelist(request)
assert utils.can_view_stats_dashboard_widget(request)


def test_can_view_stats_cd_aci(settings):
"""
CD as in "Conseil Départemental".
Expand Down
1 change: 0 additions & 1 deletion tests/www/stats/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ def test_stats_cd_log_visit(client, settings, view_name):
prescriber_org = PrescriberOrganizationWithMembershipFactory(kind="DEPT", authorized=True)
user = prescriber_org.members.get()

settings.STATS_CD_DEPARTMENT_WHITELIST = [prescriber_org.department]
settings.STATS_ACI_DEPARTMENT_WHITELIST = [prescriber_org.department]

client.force_login(user)
Expand Down

0 comments on commit fbdbb13

Please sign in to comment.