mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 12:36:45 +00:00
Improved approach to permission check at runtime
This commit is contained in:
parent
fd63fcde43
commit
3b45c1406a
@ -233,15 +233,15 @@ class RuleSet(models.Model):
|
|||||||
if check_user_role(user, role, permission):
|
if check_user_role(user, role, permission):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Check for children models which inherits from parent role
|
# Check for children models which inherits from parent role
|
||||||
for child in cls.RULESET_CHANGE_INHERIT:
|
for (parent, child) in cls.RULESET_CHANGE_INHERIT:
|
||||||
# Get child model name
|
# Get child model name
|
||||||
child_name = f'{child[0]}_{child[1]}'
|
parent_child_string = f'{parent}_{child}'
|
||||||
|
|
||||||
if child_name == table:
|
if parent_child_string == table:
|
||||||
# Check if parent role has change permission
|
# Check if parent role has change permission
|
||||||
if check_user_role(user, role, 'change'):
|
if check_user_role(user, parent, 'change'):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# Print message instead of throwing an error
|
# Print message instead of throwing an error
|
||||||
name = getattr(user, 'name', user.pk)
|
name = getattr(user, 'name', user.pk)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user