Add unique check for "name" when creating new Role
This commit is contained in:
parent
84db66a60c
commit
c5fef6b954
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2017 Lance Edgar
|
# Copyright © 2010-2018 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -65,10 +65,22 @@ class RolesView(PrincipalMasterView):
|
||||||
g.set_sort_defaults('name')
|
g.set_sort_defaults('name')
|
||||||
g.set_link('name')
|
g.set_link('name')
|
||||||
|
|
||||||
|
def unique_name(self, node, value):
|
||||||
|
query = self.Session.query(model.Role)\
|
||||||
|
.filter(model.Role.name == value)
|
||||||
|
if self.editing:
|
||||||
|
role = self.get_instance()
|
||||||
|
query = query.filter(model.Role.uuid != role.uuid)
|
||||||
|
if query.count():
|
||||||
|
raise colander.Invalid(node, "Name must be unique")
|
||||||
|
|
||||||
def configure_form(self, f):
|
def configure_form(self, f):
|
||||||
super(RolesView, self).configure_form(f)
|
super(RolesView, self).configure_form(f)
|
||||||
role = f.model_instance
|
role = f.model_instance
|
||||||
|
|
||||||
|
# name
|
||||||
|
f.set_validator('name', self.unique_name)
|
||||||
|
|
||||||
# permissions
|
# permissions
|
||||||
self.tailbone_permissions = self.request.registry.settings.get('tailbone_permissions', {})
|
self.tailbone_permissions = self.request.registry.settings.get('tailbone_permissions', {})
|
||||||
f.set_renderer('permissions', PermissionsRenderer(permissions=self.tailbone_permissions))
|
f.set_renderer('permissions', PermissionsRenderer(permissions=self.tailbone_permissions))
|
||||||
|
|
Loading…
Reference in a new issue