3
0
Fork 0

Compare commits

..

No commits in common. "1e3647d27bfaa5d1cec60a02f0c8bd9d4a2e12d7" and "91c87e4d85d9f9222c315733401d65ad12def043" have entirely different histories.

3 changed files with 10 additions and 67 deletions

View file

@ -248,7 +248,12 @@
% else:
<h1 class="title">${index_title}</h1>
% endif
${self.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
% endif
</div>
</div>
@ -344,15 +349,6 @@
</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">

View file

@ -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 Permissions, RoleRef
from wuttaweb.forms.schema import UserRefs, Permissions, RoleRef
class RoleView(MasterView):
@ -123,7 +123,9 @@ class RoleView(MasterView):
# users
if not (self.creating or self.editing):
f.append('users')
f.set_grid('users', self.make_users_grid(role))
f.set_readonly('users')
f.set_node('users', UserRefs(self.request))
f.set_default('users', [u.uuid for u in role.users])
# permissions
f.append('permissions')
@ -132,39 +134,6 @@ 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

View file

@ -7,7 +7,6 @@ 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
@ -94,27 +93,6 @@ 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()