modified: app.py

modified:   templates/manage_namespace.html.j2
This commit is contained in:
Russell Ballestrini 2025-01-12 14:30:37 -05:00
parent 5a5bd57bc3
commit d58a8c6638
2 changed files with 26 additions and 9 deletions

26
app.py
View file

@ -198,6 +198,22 @@ def get_current_user(request):
return None
def get_user_namespace_role(request):
user = request.user
namespace = request.namespace
if not user or not namespace:
return None
s = request.dbsession
association = s.query(NamespaceUserAssociation).filter(
NamespaceUserAssociation.user_id == user.id,
NamespaceUserAssociation.namespace_id == namespace.id
).first()
if association:
return association.role
else:
return None
def uuid_to_short_id(u):
"""Encode UUID to a URL-safe base64 string without padding."""
return base64.urlsafe_b64encode(u.bytes).decode("ascii").rstrip("=")
@ -793,9 +809,6 @@ def manage_namespace_view(request):
.all()
)
# Determine if the current user is an owner
request.user_is_owner = True # Since owner_required decorator is used
return {
"request": request,
"namespace": namespace,
@ -1255,17 +1268,16 @@ def main(global_config=None, **settings):
# Register with zope.sqlalchemy
register(DBSession)
# Add user to all requests
config.add_request_method(callable=get_current_user, name="user", reify=True)
# Provide dbsession to requests
def dbsession(request):
return DBSession
config.add_request_method(dbsession, "dbsession", reify=True)
# Add namespace to requests
# Add user, namespace, user_namespace_role to requests
config.add_request_method(get_current_user, "user", reify=True)
config.add_request_method(get_namespace, "namespace", reify=True)
config.add_request_method(get_user_namespace_role, 'user_namespace_role', reify=True)
# Add namespace_dbsession to requests if namespace is set
config.add_request_method(

View file

@ -14,12 +14,15 @@
<button type="submit">Update Namespace</button>
</form>
<!-- Only owners can see the user management section -->
{% if request.user_namespace_role == 'owner' %}
<h2>Users in Namespace</h2>
{% for member in users %}
<div>
<span>
{{ member.user.username }}
{% if request.user.id != member.user.id and request.user_is_owner %}
{% if request.user.id != member.user.id %}
<!-- Form to remove user -->
<form action="{{ request.route_url('remove_user', namespace_short_id=namespace.short_id) }}" method="post" class="inline-form">
<input type="hidden" name="csrf_token" value="{{ request.session.get_csrf_token() }}">
@ -29,7 +32,7 @@
{% endif %}
</span>
<span>
{% if request.user.id != member.user.id and request.user_is_owner %}
{% if request.user.id != member.user.id %}
<!-- Form to change role -->
<form action="{{ request.route_url('change_member_role', namespace_short_id=namespace.short_id) }}" method="post" class="inline-form">
<input type="hidden" name="csrf_token" value="{{ request.session.get_csrf_token() }}">
@ -64,6 +67,8 @@
<button type="submit">Invite User</button>
</form>
{% endif %}
<!-- Only owners can see the user management section -->
<h2>Agents</h2>
{% if agents %}