This is an automated email from the ASF dual-hosted git repository. sbp pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tooling-atr-experiments.git
The following commit(s) were added to refs/heads/main by this push: new 39cfea1 Use proper admin detection in the sidebar 39cfea1 is described below commit 39cfea1ac85bc2184589277c6aa7490fdcf8f9c4 Author: Sean B. Palmer <s...@miscoranda.com> AuthorDate: Tue Feb 18 14:28:22 2025 +0200 Use proper admin detection in the sidebar --- atr/server.py | 7 ++++++- atr/static/css/atr.css | 42 ++++++++++++++++++++----------------- atr/templates/includes/sidebar.html | 15 ++++++------- atr/util.py | 7 +++++++ 4 files changed, 44 insertions(+), 27 deletions(-) diff --git a/atr/server.py b/atr/server.py index 8b4cb8f..51ce772 100644 --- a/atr/server.py +++ b/atr/server.py @@ -97,7 +97,12 @@ def create_app(app_config: type[AppConfig]) -> QuartApp: @app.context_processor async def app_wide(): - return {"current_user": await asfquart.session.read()} + from atr.util import is_admin + + return { + "current_user": await asfquart.session.read(), + "is_admin": is_admin, + } @app.after_serving async def shutdown() -> None: diff --git a/atr/static/css/atr.css b/atr/static/css/atr.css index 45d220f..da9eff1 100644 --- a/atr/static/css/atr.css +++ b/atr/static/css/atr.css @@ -72,16 +72,6 @@ label { font-weight: 500; border-bottom: 1px dashed #d1d2d3; padding-bottom: 0.5 form.striking { background-color: #ffe; border: 1px solid #ddb; padding: 1rem; border-radius: 0.5rem; } -.hex { - font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; - font-size: 0.9em; - background: #fff; - padding: 0.25rem 0.5rem; - border-radius: 2px; - border: 1px solid #e0e0e0; - word-break: break-all; -} - footer { padding: 2rem; background: #eee; @@ -104,23 +94,37 @@ button { border-radius: 4px; cursor: pointer; font-weight: 500; - } +} - button:hover { +button:hover { background: #047; - } - +} - input, - textarea { +input, +textarea { font-family: monospace; padding: 0.5rem; - } +} - textarea { +textarea { width: 100%; min-height: 200px; - } +} + +span.warning { + color: #c00; + font-weight: 550; +} + +.hex { + font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; + font-size: 0.9em; + background: #fff; + padding: 0.25rem 0.5rem; + border-radius: 2px; + border: 1px solid #e0e0e0; + word-break: break-all; +} .wrapper { min-height: 100vh; diff --git a/atr/templates/includes/sidebar.html b/atr/templates/includes/sidebar.html index f197a4b..68b342b 100644 --- a/atr/templates/includes/sidebar.html +++ b/atr/templates/includes/sidebar.html @@ -38,7 +38,7 @@ </li> <li> <a href="{{ url_for('root_pmc_directory') }}" - {% if request.endpoint == 'root_pmc_directory' %}class="active"{% endif %}>PMC Directory</a> + {% if request.endpoint == 'root_pmc_directory' %}class="active"{% endif %}>PMCs</a> </li> </ul> @@ -47,11 +47,11 @@ <ul> <li> <a href="{{ url_for('root_add_release_candidate') }}" - {% if request.endpoint == 'root_add_release_candidate' %}class="active"{% endif %}>Add Release Candidate</a> + {% if request.endpoint == 'root_add_release_candidate' %}class="active"{% endif %}>Add release candidate</a> </li> <li> <a href="{{ url_for('root_user_uploads') }}" - {% if request.endpoint == 'root_user_uploads' %}class="active"{% endif %}>Your Uploads</a> + {% if request.endpoint == 'root_user_uploads' %}class="active"{% endif %}>Your uploads</a> </li> </ul> @@ -59,20 +59,21 @@ <ul> <li> <a href="{{ url_for('root_user_keys_add') }}" - {% if request.endpoint == 'root_user_keys_add' %}class="active"{% endif %}>Add Signing Key</a> + {% if request.endpoint == 'root_user_keys_add' %}class="active"{% endif %}>Add signing key</a> </li> <li> <a href="{{ url_for('root_user_keys_delete') }}" - {% if request.endpoint == 'root_user_keys_delete' %}class="active"{% endif %}>Delete Keys</a> + {% if request.endpoint == 'root_user_keys_delete' %}class="active"{% endif %}>Delete keys</a> + <span class="warning">(!)</span> </li> </ul> - {% if current_user.uid in ['cwells', 'fluxo', 'gmcdonald', 'humbedooh', 'sbp', 'tn', 'wave'] %} + {% if is_admin(current_user.uid) %} <h3>Administration</h3> <ul> <li> <a href="{{ url_for('secret_blueprint.secret_data') }}" - {% if request.endpoint == 'secret_blueprint.secret_data' %}class="active"{% endif %}>Browse Database</a> + {% if request.endpoint == 'secret_blueprint.secret_data' %}class="active"{% endif %}>Browse database</a> </li> <li> <a href="{{ url_for('secret_blueprint.secret_pmcs_update') }}" diff --git a/atr/util.py b/atr/util.py index b3b5faf..fd40943 100644 --- a/atr/util.py +++ b/atr/util.py @@ -27,6 +27,13 @@ def get_admin_users() -> set[str]: return set(current_app.config["ADMIN_USERS"]) +def is_admin(user_id: str | None) -> bool: + """Check if a user is an admin.""" + if user_id is None: + return False + return user_id in get_admin_users() + + def get_release_storage_dir() -> str: return str(current_app.config["RELEASE_STORAGE_DIR"]) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tooling.apache.org For additional commands, e-mail: dev-h...@tooling.apache.org