3
0
Fork 0

feat: add basic Roles view

can't edit user/role/perm mappings yet, just minimal CRUD
This commit is contained in:
Lance Edgar 2024-08-13 10:52:30 -05:00
parent eac3b81918
commit 7ad6a9d5a0
8 changed files with 178 additions and 5 deletions

View file

@ -152,6 +152,11 @@ class MenuHandler(GenericHandler):
'route': 'users',
'perm': 'users.list',
},
{
'title': "Roles",
'route': 'roles',
'perm': 'roles.list',
},
{'type': 'sep'},
{
'title': "App Info",

View file

@ -16,6 +16,9 @@
<b-field horizontal label="App Title">
<span>${app.get_title()}</span>
</b-field>
<b-field horizontal label="Production Mode">
<span>${config.production()}</span>
</b-field>
</div>
</div>
</nav>

View file

@ -33,6 +33,7 @@ That will in turn include the following modules:
* :mod:`wuttaweb.views.common`
* :mod:`wuttaweb.views.settings`
* :mod:`wuttaweb.views.people`
* :mod:`wuttaweb.views.roles`
* :mod:`wuttaweb.views.users`
"""
@ -44,6 +45,7 @@ def defaults(config, **kwargs):
config.include(mod('wuttaweb.views.common'))
config.include(mod('wuttaweb.views.settings'))
config.include(mod('wuttaweb.views.people'))
config.include(mod('wuttaweb.views.roles'))
config.include(mod('wuttaweb.views.users'))

100
src/wuttaweb/views/roles.py Normal file
View file

@ -0,0 +1,100 @@
# -*- coding: utf-8; -*-
################################################################################
#
# wuttaweb -- Web App for Wutta Framework
# Copyright © 2024 Lance Edgar
#
# This file is part of Wutta Framework.
#
# Wutta Framework is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Wutta Framework is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# Wutta Framework. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Views for roles
"""
from wuttjamaican.db.model import Role
from wuttaweb.views import MasterView
from wuttaweb.db import Session
class RoleView(MasterView):
"""
Master view for roles.
Notable URLs provided by this class:
* ``/roles/``
* ``/roles/new``
* ``/roles/XXX``
* ``/roles/XXX/edit``
* ``/roles/XXX/delete``
"""
model_class = Role
grid_columns = [
'name',
'notes',
]
# TODO: master should handle this, possibly via configure_form()
def get_query(self, session=None):
""" """
model = self.app.model
query = super().get_query(session=session)
return query.order_by(model.Role.name)
def configure_grid(self, g):
""" """
super().configure_grid(g)
# name
g.set_link('name')
def configure_form(self, f):
""" """
super().configure_form(f)
# never show these
f.remove('permission_refs',
'user_refs')
# name
f.set_validator('name', self.unique_name)
def unique_name(self, node, value):
""" """
model = self.app.model
session = Session()
query = session.query(model.Role)\
.filter(model.Role.name == value)
if self.editing:
uuid = self.request.matchdict['uuid']
query = query.filter(model.Role.uuid != uuid)
if query.count():
node.raise_invalid("Name must be unique")
def defaults(config, **kwargs):
base = globals()
RoleView = kwargs.get('RoleView', base['RoleView'])
RoleView.defaults(config)
def includeme(config):
defaults(config)