Skip to content

Commit

Permalink
siae_whitelist
Browse files Browse the repository at this point in the history
publishing the TB

fix

fix test

fix stats.html

fix
  • Loading branch information
YannickPassa committed Jul 16, 2024
1 parent aefd13c commit e1882e6
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
# Specific experimental stats are progressively being deployed to more and more users and/or companies.
# 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_SIAE_HIRING_REPORT_REGION_WHITELIST = ["Occitanie"]
STATS_CD_DEPARTMENT_WHITELIST = ["13", "16", "18", "31", "37", "38", "41", "45", "48", "49", "55", "63", "93"]
STATS_ACI_DEPARTMENT_WHITELIST = ["31", "84"]
Expand Down
8 changes: 8 additions & 0 deletions itou/templates/dashboard/includes/stats.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
<i class="ri-bar-chart-line ri-lg font-weight-normal align-self-start"></i>
<span>Suivre les effectifs annuels et mensuels en ETP</span>
</a>
</li>
{% endif %}
{% if can_view_stats_siae_orga_etp %}
<li class="d-flex justify-content-between align-items-center mb-3">
<a href="{% url 'stats:stats_siae_orga_etp' %}" class="btn-link btn-ico">
<i class="ri-bar-chart-line ri-lg font-weight-normal align-self-start"></i>
<span>Suivre les effectifs annuels et mensuels en ETP de ma structure</span>
</a>
{% include "dashboard/includes/stats_new_badge.html" %}
</li>
{% endif %}
Expand Down
3 changes: 3 additions & 0 deletions itou/utils/apis/metabase.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"dashboard_id": 327,
},
"stats_siae_etp": {
"dashboard_id": 465,
},
"stats_siae_orga_etp": {
"dashboard_id": 440,
},
"stats_siae_hiring": {
Expand Down
1 change: 1 addition & 0 deletions itou/www/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def dashboard(request, template_name="dashboard/dashboard.html"):
"can_view_stats_siae": stats_utils.can_view_stats_siae(request),
"can_view_stats_siae_aci": stats_utils.can_view_stats_siae_aci(request),
"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_siae_hiring_report": stats_utils.can_view_stats_siae_hiring_report(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),
Expand Down
1 change: 1 addition & 0 deletions itou/www/stats/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# Employer stats.
path("siae/aci", views.stats_siae_aci, name="stats_siae_aci"),
path("siae/etp", views.stats_siae_etp, name="stats_siae_etp"),
path("siae/orga_etp", views.stats_siae_orga_etp, name="stats_siae_orga_etp"),
path("siae/hiring", views.stats_siae_hiring, name="stats_siae_hiring"),
path("siae/auto_prescription", views.stats_siae_auto_prescription, name="stats_siae_auto_prescription"),
path(
Expand Down
7 changes: 7 additions & 0 deletions itou/www/stats/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ def can_view_stats_siae_etp(request):
)


def can_view_stats_siae_orga_etp(request):
"""
Non official stats with very specific access rights.
"""
return can_view_stats_siae(request) and request.current_organization.pk in settings.STATS_SIAE_PK_WHITELIST


def can_view_stats_siae_hiring_report(request):
return (
can_view_stats_siae(request)
Expand Down
24 changes: 24 additions & 0 deletions itou/www/stats/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,30 @@ def stats_siae_etp(request):
)


@login_required
def stats_siae_orga_etp(request):
"""
SIAE stats shown to their own members.
They can only view data for their own SIAE.
These stats are about ETP data from the ASP.
"""
current_org = get_stats_siae_current_org(request)
if not utils.can_view_stats_siae_orga_etp(request):
raise PermissionDenied
context = {
"page_title": "Suivi des effectifs annuels et mensuels en ETP",
"department": current_org.department,
"matomo_custom_url_suffix": format_region_and_department_for_matomo(current_org.department),
}
return render_stats(
request=request,
context=context,
params={
mb.ASP_SIAE_FILTER_KEY_FLAVOR3: [str(current_org.convention.asp_id)],
},
)


def render_stats_siae(request, page_title):
"""
SIAE stats shown only to their own members.
Expand Down
1 change: 1 addition & 0 deletions tests/www/stats/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ def test_stats_siae_log_visit(client, settings, view_name):
user = company.members.get()

settings.STATS_SIAE_USER_PK_WHITELIST = [user.pk]
settings.STATS_SIAE_PK_WHITELIST = [company.pk]
settings.STATS_SIAE_HIRING_REPORT_REGION_WHITELIST = [company.region]
settings.STATS_ACI_DEPARTMENT_WHITELIST = [company.department]

Expand Down

0 comments on commit e1882e6

Please sign in to comment.