fix permission parsing if underscores in perm

This commit is contained in:
Matthias 2021-11-01 17:06:13 +01:00
parent bba478dc1c
commit 6dead88028
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -393,7 +393,13 @@ def update_group_roles(group, debug=False):
(app, perm) = permission_string.split('.')
(model, permission_name) = split_model(perm)
# split up the permissions -> handle models with underscores
permission_name, *model = perm.split('_')
# handle models that have
if len(model) > 1:
app += '_' + '_'.join(model[:-1])
perm = permission_name + '_' + model[-1:][0]
model = model[-1:][0]
try:
content_type = ContentType.objects.get(app_label=app, model=model)
@ -401,6 +407,8 @@ def update_group_roles(group, debug=False):
except ContentType.DoesNotExist:
logger.warning(f"Error: Could not find permission matching '{permission_string}'")
permission = None
except Exception as _e:
print(_e)
return permission