From 977b457d5ce7661e8b4680d5543ad4d31063dcf1 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 25 Jun 2024 17:29:02 +0200 Subject: ogcp: add user permission mechanism Add a new user permission system to control the allowed operations accessible from each account. Add a permission matrix editable through the user/add and user/edit views. The permission matrix has client, center, room, folder, image and repository as permission targets and add, update and delete as permission types. Restrict each view based on the user permissions, hide all actions from not autheticated users. permissions defined in the class UserForm. Serialize each user permissions into ogcp.json as: { ... "USERS" [ { "USER": "admin" ... "PERMISSIONS": { "CLIENT": { "ADD": true, "UPDATE": true, "DELETE": true, }, ... <- same structure for "CENTER", "ROOM", "FOLDER", "IMAGE" and "REPOSITORY" } }, ... ], ... } Grant all the permissions to old user configuration to not disrupt their workflow. The administrator will need to assign the permissions for each user. Ignore scope and permission restrictions for admin users. Save permissions and scopes even if the user is admin to account for the case of a temporal admin promotion without losing the previous configuration. Use template inheritance for add_user.html and edit_user.html to prevent big code duplication with the new HTML code to render the permission matrix. Make user administration an admin only feature. Define methods get_permission and target_is_disabled to improve readability in template conditionals that disable features based on user permissions. --- ogcp/forms/auth.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'ogcp/forms') diff --git a/ogcp/forms/auth.py b/ogcp/forms/auth.py index d85931b..a76ec7c 100644 --- a/ogcp/forms/auth.py +++ b/ogcp/forms/auth.py @@ -7,7 +7,8 @@ from wtforms import ( Form, SubmitField, HiddenField, SelectField, BooleanField, IntegerField, - StringField, RadioField, PasswordField, SelectMultipleField, widgets + StringField, RadioField, PasswordField, SelectMultipleField, FormField, + widgets ) from wtforms.validators import InputRequired, Optional from flask_wtf import FlaskForm @@ -28,6 +29,12 @@ class LoginForm(FlaskForm): ) +class PermissionForm(FlaskForm): + add = BooleanField(_l('Add'), default=True) + update = BooleanField(_l('Update'), default=True) + delete = BooleanField(_l('Delete'), default=True) + + class UserForm(FlaskForm): username = StringField( label=_l('Username'), @@ -50,6 +57,12 @@ class UserForm(FlaskForm): option_widget=widgets.CheckboxInput(), widget=widgets.ListWidget(prefix_label=False) ) + client_permissions = FormField(PermissionForm, label=_l('Client Permissions')) + center_permissions = FormField(PermissionForm, label=_l('Center Permissions')) + room_permissions = FormField(PermissionForm, label=_l('Room Permissions')) + folder_permissions = FormField(PermissionForm, label=_l('Folder Permissions')) + image_permissions = FormField(PermissionForm, label=_l('Image Permissions')) + repository_permissions = FormField(PermissionForm, label=_l('Repository Permissions')) submit_btn = SubmitField( label=_l('Submit') ) -- cgit v1.2.3-18-g5258