From aa6061dad7e90ef9761d2d64940cf38eed51c990 Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Wed, 13 Dec 2023 13:10:04 +0100 Subject: Limit allowed scopes to only centers Modify the add/edit users menu to make the 'allowed scopes' field only display centers --- ogcp/views.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'ogcp') diff --git a/ogcp/views.py b/ogcp/views.py index 0d80cc7..b008673 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1678,6 +1678,15 @@ def users(): return render_template('users.html', users=users) +def get_available_centers(): + responses = multi_request('get', '/scopes') + available_centers = list() + for resp in responses: + centers = parse_scopes_from_tree(resp['json'], 'center') + centers = [(center['name'], center['name']) for center in centers] + available_centers.extend(centers) + return available_centers + def get_available_scopes(): responses = multi_request('get', '/scopes') available_scopes = list() @@ -1809,7 +1818,7 @@ def delete_user(username): @login_required def user_add_get(): form = UserForm() - form.scopes.choices = get_available_scopes() + form.scopes.choices = get_available_centers() return render_template('auth/add_user.html', form=form) @@ -1847,7 +1856,7 @@ def user_edit_get(): form.username.render_kw = {'readonly': True} form.admin.data = user.get('ADMIN') form.scopes.data = user.get('SCOPES') - form.scopes.choices = get_available_scopes() + form.scopes.choices = get_available_centers() return render_template('auth/edit_user.html', form=form) -- cgit v1.2.3-18-g5258