diff options
author | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-04-26 10:36:25 +0200 |
---|---|---|
committer | Javier Sánchez Parra <jsanchez@soleta.eu> | 2022-04-27 17:24:08 +0200 |
commit | 57da4f4efa0b8b7d96b1238b0127aa83d20007eb (patch) | |
tree | 6d3185e571231b923aa7d020dc5224a3a246c374 | |
parent | c7b0024d2405d29e5c36445b6d28af046b2213f1 (diff) |
Add user role administrator
ogCP now have to types of users, regular and administrator users.
ogCP configuration file defines users roles with the boolean field
"ADMIN".
-rw-r--r-- | ogcp/cfg/ogcp.json | 2 | ||||
-rw-r--r-- | ogcp/models.py | 3 | ||||
-rw-r--r-- | ogcp/views.py | 4 |
3 files changed, 6 insertions, 3 deletions
diff --git a/ogcp/cfg/ogcp.json b/ogcp/cfg/ogcp.json index 7a04890..0cdbb6d 100644 --- a/ogcp/cfg/ogcp.json +++ b/ogcp/cfg/ogcp.json @@ -7,11 +7,13 @@ { "USER": "admin", "PASS": "5b722b307fce6c944905d132691d5e4a2214b7fe92b738920eb3fce3a90420a19511c3010a0e7712b054daef5b57bad59ecbd93b3280f210578f547f4aed4d25", + "ADMIN": true, "SCOPES": [ ] }, { "USER": "user", "PASS": "5b722b307fce6c944905d132691d5e4a2214b7fe92b738920eb3fce3a90420a19511c3010a0e7712b054daef5b57bad59ecbd93b3280f210578f547f4aed4d25", + "ADMIN": false, "SCOPES": [ "Unidad Organizativa (Default)" ] diff --git a/ogcp/models.py b/ogcp/models.py index 4b88a41..d27b869 100644 --- a/ogcp/models.py +++ b/ogcp/models.py @@ -8,6 +8,7 @@ from flask_login import UserMixin class User(UserMixin): - def __init__(self, username, scopes): + def __init__(self, username, scopes, admin): self.id = username self.scopes = scopes + self.admin = admin diff --git a/ogcp/views.py b/ogcp/views.py index 66e9007..d1e4109 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -210,7 +210,7 @@ def load_user(username): if not user_dict: return None - user = User(username, user_dict.get('SCOPES')) + user = User(username, user_dict.get('SCOPES'), user_dict.get('ADMIN')) return user @app.before_request @@ -265,7 +265,7 @@ def login(): user_dict = authenticate_user(form_user, pwd) if not user_dict: return render_template('auth/login.html', form=form) - user = User(form_user, user_dict.get('SCOPES')) + user = User(form_user, user_dict.get('SCOPES'), user_dict.get('ADMIN')) login_user(user) return redirect(url_for('index')) return render_template('auth/login.html', form=LoginForm()) |