Skip to content

Commit 44428c6

Browse files
authoredJul 19, 2024
templates: hide Treestatus editing capabilities from unprivileged users (Bug 1901484) (#205)
Add a new `is_treestatus_user` template helper which checks for membership in the Treestatus Mozillians groups. Switch to using this new function to determine if Treestatus editing elements of the UI should be shown.
1 parent 80abbcb commit 44428c6

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed
 

‎landoui/template_helpers.py

+20-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
from typing import Optional
1313

14-
from flask import Blueprint, current_app, escape
14+
from flask import Blueprint, current_app, escape, session
1515
from landoui.forms import (
1616
ReasonCategory,
1717
TreeCategory,
@@ -32,6 +32,25 @@ def is_user_authenticated() -> bool:
3232
return helpers.is_user_authenticated()
3333

3434

35+
TREESTATUS_USER_GROUPS = {
36+
"mozilliansorg_treestatus_admins",
37+
"mozilliansorg_treestatus_users",
38+
}
39+
40+
41+
@template_helpers.app_template_global()
42+
def is_treestatus_user() -> bool:
43+
if not is_user_authenticated():
44+
return False
45+
46+
try:
47+
groups = session["userinfo"]["https://sso.mozilla.com/claim/groups"]
48+
except KeyError:
49+
return False
50+
51+
return not TREESTATUS_USER_GROUPS.isdisjoint(groups)
52+
53+
3554
@template_helpers.app_template_global()
3655
def user_has_phabricator_token() -> bool:
3756
return helpers.get_phabricator_api_token() is not None

‎landoui/templates/treestatus/trees.html

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
<h1>Treestatus</h1>
1313
<p>Current status of Mozilla's version-control repositories.</p>
1414

15+
{% if is_treestatus_user() %}
1516
{% include "treestatus/recent_changes.html" %}
17+
{% endif %}
1618

1719
<h1>Trees</h1>
1820
{#
@@ -22,7 +24,7 @@ <h1>Trees</h1>
2224
<form method="post">
2325
{{ treestatus_update_trees_form.csrf_token }}
2426

25-
{% if is_user_authenticated() %}
27+
{% if is_treestatus_user() %}
2628
<div class="block">
2729
<a href="{{ url_for("treestatus.new_tree") }}">
2830
<button class="button" title="New Tree" type="button">New Tree</button>
@@ -47,7 +49,7 @@ <h4 class="subtitle is-4 tree-category-header">{{ ns.current_category | tree_cat
4749

4850
<div class="select-trees-box box">
4951
<div class="columns">
50-
{% if is_user_authenticated() %}
52+
{% if is_treestatus_user() %}
5153
<div class="column is-1">
5254
<input class="tree-select-checkbox" type="checkbox" name="{{ tree_option.id }}" value="{{ tree_option.data }}">
5355
</div>

0 commit comments

Comments
 (0)
Failed to load comments.