fix guest bug in role perms editing

This commit is contained in:
Lance Edgar 2012-11-12 22:52:37 -08:00
parent 9b2589ca12
commit c79d6de56d
2 changed files with 5 additions and 4 deletions

View file

@ -105,7 +105,7 @@ def grant_permission(role, permission, session=None):
role.permissions.append(permission) role.permissions.append(permission)
def has_permission(obj, perm, session=None): def has_permission(obj, perm, include_guest=True, session=None):
""" """
Checks the given ``obj`` (which may be either a :class:`edbob.User`` or Checks the given ``obj`` (which may be either a :class:`edbob.User`` or
:class:`edbob.Role` instance), and returns a boolean indicating whether or :class:`edbob.Role` instance), and returns a boolean indicating whether or
@ -124,8 +124,9 @@ def has_permission(obj, perm, session=None):
if not session: if not session:
session = object_session(obj) session = object_session(obj)
assert session assert session
if include_guest:
roles.append(guest_role(session))
admin = administrator_role(session) admin = administrator_role(session)
roles.append(guest_role(session))
for role in roles: for role in roles:
if role is admin: if role is admin:
return True return True

View file

@ -139,12 +139,12 @@ def PermissionsFieldRenderer(permissions, *args, **kwargs):
for group, perms in self.permissions: for group, perms in self.permissions:
inner = HTML.tag('p', c=group) inner = HTML.tag('p', c=group)
for perm, title in perms: for perm, title in perms:
checked = auth.has_permission(role, perm, Session()) checked = auth.has_permission(
role, perm, include_guest=False, session=Session())
if readonly: if readonly:
span = HTML.tag('span', c="[X]" if checked else "[ ]") span = HTML.tag('span', c="[X]" if checked else "[ ]")
inner += HTML.tag('p', class_='perm', c=span + ' ' + title) inner += HTML.tag('p', class_='perm', c=span + ' ' + title)
else: else:
checked = auth.has_permission(role, perm, Session())
inner += tags.checkbox(self.name + '-' + perm, inner += tags.checkbox(self.name + '-' + perm,
checked=checked, label=title) checked=checked, label=title)
html += HTML.tag('div', class_='group', c=inner) html += HTML.tag('div', class_='group', c=inner)