Compare commits
2 commits
91c87e4d85
...
1e3647d27b
Author | SHA1 | Date | |
---|---|---|---|
|
1e3647d27b | ||
|
194d798c0c |
|
@ -248,12 +248,7 @@
|
|||
% else:
|
||||
<h1 class="title">${index_title}</h1>
|
||||
% endif
|
||||
% if master and master.creatable and not master.creating and master.has_perm('create'):
|
||||
<wutta-button once type="is-primary"
|
||||
tag="a" href="${url(f'{route_prefix}.create')}"
|
||||
icon-left="plus"
|
||||
label="Create New" />
|
||||
% endif
|
||||
${self.index_title_controls()}
|
||||
% endif
|
||||
</div>
|
||||
</div>
|
||||
|
@ -349,6 +344,15 @@
|
|||
</footer>
|
||||
</%def>
|
||||
|
||||
<%def name="index_title_controls()">
|
||||
% if master and master.creatable and not master.creating and master.has_perm('create'):
|
||||
<wutta-button once type="is-primary"
|
||||
tag="a" href="${url(f'{route_prefix}.create')}"
|
||||
icon-left="plus"
|
||||
label="Create New" />
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<%def name="render_vue_template_whole_page()">
|
||||
<script type="text/x-template" id="whole-page-template">
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ from wuttjamaican.db.model import Role, Permission
|
|||
from wuttaweb.views import MasterView
|
||||
from wuttaweb.db import Session
|
||||
from wuttaweb.forms import widgets
|
||||
from wuttaweb.forms.schema import UserRefs, Permissions, RoleRef
|
||||
from wuttaweb.forms.schema import Permissions, RoleRef
|
||||
|
||||
|
||||
class RoleView(MasterView):
|
||||
|
@ -123,9 +123,7 @@ class RoleView(MasterView):
|
|||
# users
|
||||
if not (self.creating or self.editing):
|
||||
f.append('users')
|
||||
f.set_readonly('users')
|
||||
f.set_node('users', UserRefs(self.request))
|
||||
f.set_default('users', [u.uuid for u in role.users])
|
||||
f.set_grid('users', self.make_users_grid(role))
|
||||
|
||||
# permissions
|
||||
f.append('permissions')
|
||||
|
@ -134,6 +132,39 @@ class RoleView(MasterView):
|
|||
if not self.creating:
|
||||
f.set_default('permissions', list(role.permissions))
|
||||
|
||||
def make_users_grid(self, role):
|
||||
"""
|
||||
Make and return the grid for the Users field.
|
||||
|
||||
This grid is shown for the Users field when viewing a Role.
|
||||
|
||||
:returns: Fully configured :class:`~wuttaweb.grids.base.Grid`
|
||||
instance.
|
||||
"""
|
||||
model = self.app.model
|
||||
route_prefix = self.get_route_prefix()
|
||||
|
||||
grid = self.make_grid(key=f'{route_prefix}.view.users',
|
||||
model_class=model.User,
|
||||
data=role.users,
|
||||
columns=[
|
||||
'username',
|
||||
'person',
|
||||
'active',
|
||||
])
|
||||
|
||||
if self.request.has_perm('users.view'):
|
||||
url = lambda user, i: self.request.route_url('users.view', uuid=user.uuid)
|
||||
grid.add_action('view', icon='eye', url=url)
|
||||
grid.set_link('person')
|
||||
grid.set_link('username')
|
||||
|
||||
if self.request.has_perm('users.edit'):
|
||||
url = lambda user, i: self.request.route_url('users.edit', uuid=user.uuid)
|
||||
grid.add_action('edit', url=url)
|
||||
|
||||
return grid
|
||||
|
||||
def unique_name(self, node, value):
|
||||
""" """
|
||||
model = self.app.model
|
||||
|
|
|
@ -7,6 +7,7 @@ from sqlalchemy import orm
|
|||
import colander
|
||||
|
||||
from wuttaweb.views import roles as mod
|
||||
from wuttaweb.grids import Grid
|
||||
from wuttaweb.forms.schema import RoleRef
|
||||
from wuttaweb.testing import WebTestCase
|
||||
|
||||
|
@ -93,6 +94,27 @@ class TestRoleView(WebTestCase):
|
|||
view.configure_form(form)
|
||||
self.assertIsNotNone(form.validators['name'])
|
||||
|
||||
def test_make_users_grid(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
role = model.Role(name="Manager")
|
||||
|
||||
# basic
|
||||
grid = view.make_users_grid(role)
|
||||
self.assertIsInstance(grid, Grid)
|
||||
self.assertFalse(grid.linked_columns)
|
||||
self.assertFalse(grid.actions)
|
||||
|
||||
# view + edit actions
|
||||
with patch.object(self.request, 'is_root', new=True):
|
||||
grid = view.make_users_grid(role)
|
||||
self.assertIsInstance(grid, Grid)
|
||||
self.assertIn('person', grid.linked_columns)
|
||||
self.assertIn('username', grid.linked_columns)
|
||||
self.assertEqual(len(grid.actions), 2)
|
||||
self.assertEqual(grid.actions[0].key, 'view')
|
||||
self.assertEqual(grid.actions[1].key, 'edit')
|
||||
|
||||
def test_unique_name(self):
|
||||
model = self.app.model
|
||||
view = self.make_view()
|
||||
|
|
Loading…
Reference in a new issue