From 3b45c1406a0c231ed1f4f7b78763c0dde7143f48 Mon Sep 17 00:00:00 2001 From: eeintech Date: Mon, 7 Feb 2022 15:42:39 -0500 Subject: [PATCH] Improved approach to permission check at runtime --- InvenTree/users/models.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/InvenTree/users/models.py b/InvenTree/users/models.py index eecfd2f4d9..f2b72e5efa 100644 --- a/InvenTree/users/models.py +++ b/InvenTree/users/models.py @@ -233,15 +233,15 @@ class RuleSet(models.Model): if check_user_role(user, role, permission): return True - # Check for children models which inherits from parent role - for child in cls.RULESET_CHANGE_INHERIT: - # Get child model name - child_name = f'{child[0]}_{child[1]}' + # Check for children models which inherits from parent role + for (parent, child) in cls.RULESET_CHANGE_INHERIT: + # Get child model name + parent_child_string = f'{parent}_{child}' - if child_name == table: - # Check if parent role has change permission - if check_user_role(user, role, 'change'): - return True + if parent_child_string == table: + # Check if parent role has change permission + if check_user_role(user, parent, 'change'): + return True # Print message instead of throwing an error name = getattr(user, 'name', user.pk)