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')
)
diff --git a/ogcp/models.py b/ogcp/models.py
index d27b869..ef050ed 100644
--- a/ogcp/models.py
+++ b/ogcp/models.py
@@ -8,7 +8,18 @@
from flask_login import UserMixin
class User(UserMixin):
- def __init__(self, username, scopes, admin):
+ def __init__(self, username, scopes, admin, permissions):
self.id = username
self.scopes = scopes
self.admin = admin
+ self.permissions = permissions
+
+ def get_permission(self, target, action):
+ if self.admin or not target in self.permissions:
+ return True
+ return self.permissions[target].get(action, True)
+
+ def target_is_disabled(self, target):
+ if self.admin or not target in self.permissions or not self.permissions[target]:
+ return False
+ return all(value == False for value in self.permissions[target].values())
diff --git a/ogcp/templates/auth/add_user.html b/ogcp/templates/auth/add_user.html
index cc5ed09..4661236 100644
--- a/ogcp/templates/auth/add_user.html
+++ b/ogcp/templates/auth/add_user.html
@@ -1,53 +1,5 @@
-{% extends 'users.html' %}
-{% import "bootstrap/wtf.html" as wtf %}
+{% extends 'auth/user_form.html' %}
-{% set sidebar_state = 'disabled' %}
-{% set btn_back = true %}
+{% block subhead_heading %}{{_('Add user')}}{% endblock %}
-{% block nav_user_add %}active{% endblock %}
-{% block content %}
-
-
{{_('Add a user')}}
-
-
-
-{% endblock %}
+{% block form_action %}{{ url_for('user_add_post') }}{% endblock %}
diff --git a/ogcp/templates/auth/edit_user.html b/ogcp/templates/auth/edit_user.html
index 3b10508..42ba5aa 100644
--- a/ogcp/templates/auth/edit_user.html
+++ b/ogcp/templates/auth/edit_user.html
@@ -1,53 +1,9 @@
-{% extends 'users.html' %}
-{% import "bootstrap/wtf.html" as wtf %}
+{% extends 'auth/user_form.html' %}
-{% set sidebar_state = 'disabled' %}
-{% set btn_back = true %}
+{% block subhead_heading %}{{_('Edit user {}').format(form.username.data)}}{% endblock %}
-{% block nav_user_edit %}active{% endblock %}
-{% block content %}
+{% block form_action %}{{ url_for('user_edit_post') }}{% endblock %}
-{{_('Edit user {}').format(form.username.data)}}
+{% block pwd_field %}{% endblock %}
-
-
-{% endblock %}
+{% block pwd_confirm_field %}{% endblock %}
diff --git a/ogcp/templates/auth/user_form.html b/ogcp/templates/auth/user_form.html
new file mode 100644
index 0000000..7b6b338
--- /dev/null
+++ b/ogcp/templates/auth/user_form.html
@@ -0,0 +1,126 @@
+{% extends 'users.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% set sidebar_state = 'disabled' %}
+{% set btn_back = true %}
+
+{% block nav_user_add %}active{% endblock %}
+{% block content %}
+
+{% block subhead_heading %}{% endblock %}
+
+
+
+{% endblock %}
diff --git a/ogcp/templates/base.html b/ogcp/templates/base.html
index 9839029..2af9873 100644
--- a/ogcp/templates/base.html
+++ b/ogcp/templates/base.html
@@ -36,10 +36,10 @@
{{ _('Scopes management') }}
- {% if current_user.admin %}
{{ _('Repos') }}
+ {% if current_user.admin %}
{{ _('Users') }}
diff --git a/ogcp/templates/commands.html b/ogcp/templates/commands.html
index 7a63c38..9bb0176 100644
--- a/ogcp/templates/commands.html
+++ b/ogcp/templates/commands.html
@@ -16,7 +16,7 @@
{% endblock %}
{% block commands %}
-
+{% if current_user.is_authenticated %}
@@ -109,7 +113,7 @@
form="scopesForm" formaction="{{ url_for('action_legacy_rt_log') }}" formmethod="get" formtarget="_blank">
-
+{% endif %}
{% if btn_back %}