simplify yml definitions to use wildcard syntax
This commit is contained in:
parent
cce4370d41
commit
aa0d2a6e01
@ -7,19 +7,15 @@
|
||||
# writers:
|
||||
# users:
|
||||
# - writer
|
||||
## specify explicit permission codenames or codename filter functions and filters to match on
|
||||
## specify explicit permission codenames or include wildcard to match multiple permissions
|
||||
# permissions:
|
||||
# - delete_device
|
||||
# - delete_virtualmachine
|
||||
# - codename__startswith:
|
||||
# - add_
|
||||
# - change_
|
||||
# - add_*
|
||||
# - change_*
|
||||
# vm_managers:
|
||||
# - codename__endswith:
|
||||
# - _virtualmachine
|
||||
# - *_virtualmachine
|
||||
# device_managers:
|
||||
# - codename__contains:
|
||||
# - device
|
||||
# - *device*
|
||||
# creators:
|
||||
# - codename__startswith:
|
||||
# - add_
|
||||
# - add_*
|
||||
|
@ -4,10 +4,9 @@
|
||||
# password: reader
|
||||
# writer:
|
||||
# password: writer
|
||||
## specify explicit permission codenames or codename filter functions and filters to match on
|
||||
## specify explicit permission codenames or include wildcard to match multiple permissions
|
||||
# permissions:
|
||||
# - delete_device
|
||||
# - delete_virtualmachine
|
||||
# - codename__startswith:
|
||||
# - add_
|
||||
# - change_
|
||||
# - add_*
|
||||
# - change_*
|
||||
|
@ -30,16 +30,13 @@ with file.open('r') as stream:
|
||||
if yaml_permissions:
|
||||
permission_object.permissions.clear()
|
||||
for yaml_permission in yaml_permissions:
|
||||
if isinstance(yaml_permission,dict):
|
||||
# assume this is the specific codename filter function instead of an exact codename
|
||||
permission_codename_function = list(yaml_permission.keys())[0]
|
||||
permission_codenames = yaml_permission[permission_codename_function]
|
||||
if '*' in yaml_permission:
|
||||
permission_codename_function = 'codename__iregex'
|
||||
permission_codename = '^' + yaml_permission.replace('*','.*') + '$'
|
||||
else:
|
||||
permission_codename_function = 'codename'
|
||||
permission_codenames = list({yaml_permission})
|
||||
permission_codename = yaml_permission
|
||||
|
||||
# supports either one codename from the permissions list, or multiple codenames in a codename_function dict
|
||||
for permission_codename in permission_codenames:
|
||||
# supports non-unique permission codenames
|
||||
for permission in eval('Permission.objects.filter(' + permission_codename_function + '=permission_codename)'):
|
||||
permission_object.permissions.add(permission)
|
||||
|
@ -29,16 +29,13 @@ with file.open('r') as stream:
|
||||
if yaml_permissions:
|
||||
permission_object.permissions.clear()
|
||||
for yaml_permission in yaml_permissions:
|
||||
if isinstance(yaml_permission,dict):
|
||||
# assume this is the specific codename filter function instead of an exact codename
|
||||
permission_codename_function = list(yaml_permission.keys())[0]
|
||||
permission_codenames = yaml_permission[permission_codename_function]
|
||||
if '*' in yaml_permission:
|
||||
permission_codename_function = 'codename__iregex'
|
||||
permission_codename = '^' + yaml_permission.replace('*','.*') + '$'
|
||||
else:
|
||||
permission_codename_function = 'codename'
|
||||
permission_codenames = list({yaml_permission})
|
||||
permission_codename = yaml_permission
|
||||
|
||||
# supports either one codename from the permissions list, or multiple codenames in a codename_function dict
|
||||
for permission_codename in permission_codenames:
|
||||
# supports non-unique permission codenames
|
||||
for permission in eval('Permission.objects.filter(' + permission_codename_function + '=permission_codename)'):
|
||||
permission_object.permissions.add(permission)
|
||||
|
Loading…
Reference in New Issue
Block a user