mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-16 20:15:44 +00:00
Merge branch 'inventree:master' into webhooks
This commit is contained in:
@ -73,6 +73,9 @@ class RuleSet(models.Model):
|
||||
'socialaccount_socialaccount',
|
||||
'socialaccount_socialapp',
|
||||
'socialaccount_socialtoken',
|
||||
'otp_totp_totpdevice',
|
||||
'otp_static_statictoken',
|
||||
'otp_static_staticdevice',
|
||||
'plugin_pluginconfig'
|
||||
],
|
||||
'part_category': [
|
||||
@ -238,7 +241,7 @@ class RuleSet(models.Model):
|
||||
given the app_model name, and the permission type.
|
||||
"""
|
||||
|
||||
app, model = model.split('_')
|
||||
model, app = split_model(model)
|
||||
|
||||
return "{app}.{perm}_{model}".format(
|
||||
app=app,
|
||||
@ -281,6 +284,30 @@ class RuleSet(models.Model):
|
||||
return self.RULESET_MODELS.get(self.name, [])
|
||||
|
||||
|
||||
def split_model(model):
|
||||
"""get modelname and app from modelstring"""
|
||||
*app, model = model.split('_')
|
||||
|
||||
# handle models that have
|
||||
if len(app) > 1:
|
||||
app = '_'.join(app)
|
||||
else:
|
||||
app = app[0]
|
||||
|
||||
return model, app
|
||||
|
||||
|
||||
def split_permission(app, perm):
|
||||
"""split permission string into permission and model"""
|
||||
permission_name, *model = perm.split('_')
|
||||
# handle models that have underscores
|
||||
if len(model) > 1:
|
||||
app += '_' + '_'.join(model[:-1])
|
||||
perm = permission_name + '_' + model[-1:][0]
|
||||
model = model[-1:][0]
|
||||
return perm, model
|
||||
|
||||
|
||||
def update_group_roles(group, debug=False):
|
||||
"""
|
||||
|
||||
@ -384,7 +411,7 @@ def update_group_roles(group, debug=False):
|
||||
|
||||
(app, perm) = permission_string.split('.')
|
||||
|
||||
(permission_name, model) = perm.split('_')
|
||||
perm, model = split_permission(app, perm)
|
||||
|
||||
try:
|
||||
content_type = ContentType.objects.get(app_label=app, model=model)
|
||||
|
Reference in New Issue
Block a user