Skip to content

Commit

Permalink
remove admin access display item
Browse files Browse the repository at this point in the history
  • Loading branch information
FuHsinyu committed Jun 13, 2024
1 parent 671c0b0 commit 646d188
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 28 deletions.
24 changes: 15 additions & 9 deletions admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
__copyright__ = "Copyright (c) 2024, Utrecht University"
__license__ = "GPLv3, see LICENSE"

from flask import Blueprint, g, render_template, Response
from flask import abort, Blueprint, render_template, Response

import api

Expand All @@ -18,11 +18,17 @@

@admin_bp.route("/")
def index() -> Response:
# Call api to check is user is admin
is_admin = api.call("admin_is_user_admin", {})
if (
is_admin
): # TODO redirect to the access-dinied html (available) for non-admin user
print("Test api_group_user_is_admin success, from Portal")

return render_template("admin.html")
"""
Route to the admin page. It checks if the current user has admin
privileges and directs them accordingly.
Returns:
Rendered template or aborts the request (403) if access is denied.
"""
has_admin_access = api.call("admin_has_access", data={})["data"]
print(f"Admin access check from Portal: {has_admin_access}")

if has_admin_access:
return render_template("admin.html")
else:
return abort(403)
41 changes: 22 additions & 19 deletions general/templates/general/user.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
{% if g.user %}
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" id="userDropdown" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" id="userDropdown" data-bs-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
{{ g.user }} {% if g.notifications %}<i class="fa-solid fa-bell" aria-hidden="true"></i>{% endif %}
</button>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
<a class="dropdown-item" href="{{ url_for('user_bp.notifications') }}">
Notifications {% if g.notifications %}<span class="badge bg-primary">{{ g.notifications }}</span>{% endif %}
</a>
<a class="dropdown-item" href="{{ url_for('user_bp.settings') }}">Settings</a>
{% if config.get('TOKENS_ENABLED') %}
<a class="dropdown-item" href="{{ url_for('user_bp.data_access') }}">Data Access Password</a>
{% endif %}
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ url_for('admin_bp.index') }}">Administration</a>
<a class="dropdown-item" href="{{ url_for('group_manager_bp.index') }}">Group Manager</a>
<a class="dropdown-item" href="{{ url_for('stats_bp.index') }}">Statistics</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ url_for('user_bp.logout') }}">Log out</a>
</div>
</button>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="userDropdown">
<a class="dropdown-item" href="{{ url_for('user_bp.notifications') }}">
Notifications {% if g.notifications %}<span class="badge bg-primary">{{ g.notifications }}</span>{% endif %}
</a>
<a class="dropdown-item" href="{{ url_for('user_bp.settings') }}">Settings</a>
{% if config.get('TOKENS_ENABLED') %}
<a class="dropdown-item" href="{{ url_for('user_bp.data_access') }}">Data Access Password</a>
{% endif %}
<div class="dropdown-divider"></div>
{% if g.administration %}
<a class="dropdown-item" href="{{ url_for('admin_bp.index') }}">Administration</a>
{% endif %}
<a class="dropdown-item" href="{{ url_for('group_manager_bp.index') }}">Group Manager</a>
<a class="dropdown-item" href="{{ url_for('stats_bp.index') }}">Statistics</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="{{ url_for('user_bp.logout') }}">Log out</a>
</div>
</div>
{% else %}
<a class="btn btn-primary" href="{{ url_for('user_bp.gate') }}" title="Go to sign in page">Sign in</a>
<a class="btn btn-primary" href="{{ url_for('user_bp.gate') }}" title="Go to sign in page">Sign in</a>
{% endif %}

0 comments on commit 646d188

Please sign in to comment.