mirror of
https://github.com/inventree/InvenTree.git
synced 2025-08-05 03:21:35 +00:00
Merge branch 'master' of https://github.com/inventree/InvenTree into matmair/issue2279
This commit is contained in:
InvenTree
InvenTree
api_tester.pyapps.pyexchange.pyhelpers.pymiddleware.pyready.pyserializers.pysettings.pytasks.pyvalidators.pyversion.py
barcodes
build
common
locale
de
LC_MESSAGES
el
LC_MESSAGES
es
LC_MESSAGES
fr
LC_MESSAGES
he
LC_MESSAGES
id
LC_MESSAGES
it
LC_MESSAGES
ja
LC_MESSAGES
ko
LC_MESSAGES
nl
LC_MESSAGES
no
LC_MESSAGES
pl
LC_MESSAGES
pt
LC_MESSAGES
ru
LC_MESSAGES
sv
LC_MESSAGES
th
LC_MESSAGES
tr
LC_MESSAGES
vi
LC_MESSAGES
zh
LC_MESSAGES
order
part
api.pybom.pyforms.pymodels.pyserializers.py
templates
part
templatetags
test_bom_export.pytest_bom_import.pytest_part.pytest_supplier_part.pyurls.pyviews.pyplugin
stock
templates
users
docker
requirements.txt@@ -177,6 +177,11 @@ class RuleSet(models.Model):
|
||||
'django_q_success',
|
||||
]
|
||||
|
||||
RULESET_CHANGE_INHERIT = [
|
||||
('part', 'partparameter'),
|
||||
('part', 'bomitem'),
|
||||
]
|
||||
|
||||
RULE_OPTIONS = [
|
||||
'can_view',
|
||||
'can_add',
|
||||
@@ -229,6 +234,16 @@ class RuleSet(models.Model):
|
||||
if check_user_role(user, role, permission):
|
||||
return True
|
||||
|
||||
# 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 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)
|
||||
|
||||
@@ -454,6 +469,28 @@ def update_group_roles(group, debug=False):
|
||||
if debug:
|
||||
print(f"Removing permission {perm} from group {group.name}")
|
||||
|
||||
# Enable all action permissions for certain children models
|
||||
# if parent model has 'change' permission
|
||||
for (parent, child) in RuleSet.RULESET_CHANGE_INHERIT:
|
||||
parent_change_perm = f'{parent}.change_{parent}'
|
||||
parent_child_string = f'{parent}_{child}'
|
||||
|
||||
# Check if parent change permission exists
|
||||
if parent_change_perm in group_permissions:
|
||||
# Add child model permissions
|
||||
for action in ['add', 'change', 'delete']:
|
||||
child_perm = f'{parent}.{action}_{child}'
|
||||
|
||||
# Check if child permission not already in group
|
||||
if child_perm not in group_permissions:
|
||||
# Create permission object
|
||||
add_model(parent_child_string, action, ruleset.can_delete)
|
||||
# Add to group
|
||||
permission = get_permission_object(child_perm)
|
||||
if permission:
|
||||
group.permissions.add(permission)
|
||||
print(f"Adding permission {child_perm} to group {group.name}")
|
||||
|
||||
|
||||
@receiver(post_save, sender=Group, dispatch_uid='create_missing_rule_sets')
|
||||
def create_missing_rule_sets(sender, instance, **kwargs):
|
||||
|
Reference in New Issue
Block a user