Permalink
Browse files

Made more robust permission names.

  • Loading branch information...
mitar committed Jul 22, 2011
1 parent 931b408 commit 5947caeedbdf3f05fc6486dc57692ea6931ade95
Showing with 9 additions and 3 deletions.
  1. +9 −3 componentpermissions/api.py
@@ -19,11 +19,17 @@ class ComponentPermissionsPolicy(Component):
# IPermissionRequestor methods
def _get_permission_name(self, component):
- return 'COMPONENT_%s_VIEW' % (re.sub('[^a-zA-Z]+', '_', component).strip('_').upper(),)
+ name = re.sub('[^a-zA-Z]+', '_', component).strip('_').upper()
+ if name:
+ return 'COMPONENT_%s_VIEW' % (name,)
+ else:
+ return None
def get_permission_actions(self):
for component in model.Component.select(self.env):
- yield self._get_permission_name(component.name)
+ permission = self._get_permission_name(component.name)
+ if permission:
+ yield permission
# IPermissionPolicy methods
@@ -48,5 +54,5 @@ def check_permission(self, action, username, resource, perm):
if should_check_permissions and int(should_check_permissions) and 'component' in ticket.values:
permission = self._get_permission_name(ticket['component'])
- if permission not in perm and 'TICKET_ADMIN' not in perm:
+ if permission and permission not in perm and 'TICKET_ADMIN' not in perm:
return False

0 comments on commit 5947cae

Please sign in to comment.