mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
refactor 'all' role
This commit is contained in:
parent
9f922f06ff
commit
a148dbf303
@ -49,32 +49,38 @@ class UserMixin:
|
|||||||
|
|
||||||
self.user.save()
|
self.user.save()
|
||||||
|
|
||||||
for role in self.roles:
|
# Assign all roles if set
|
||||||
self.assignRole(role, self.roles == ['all'])
|
if self.roles == 'all':
|
||||||
|
self.assignRole()
|
||||||
|
# else filter the roles
|
||||||
|
else:
|
||||||
|
for role in self.roles:
|
||||||
|
self.assignRole(role)
|
||||||
|
|
||||||
if self.auto_login:
|
if self.auto_login:
|
||||||
self.client.login(username=self.username, password=self.password)
|
self.client.login(username=self.username, password=self.password)
|
||||||
|
|
||||||
def assignRole(self, role, assign_all: bool = False):
|
def assignRole(self, role = None, assign_all: bool = False):
|
||||||
"""
|
"""
|
||||||
Set the user roles for the registered user
|
Set the user roles for the registered user
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# role is of the format 'rule.permission' e.g. 'part.add'
|
# role is of the format 'rule.permission' e.g. 'part.add'
|
||||||
|
|
||||||
rule, perm = role.split('.')
|
if not assign_all:
|
||||||
|
rule, perm = role.split('.')
|
||||||
|
|
||||||
for ruleset in self.group.rule_sets.all():
|
for ruleset in self.group.rule_sets.all():
|
||||||
|
|
||||||
if ruleset.name == rule or assign_all:
|
if assign_all or ruleset.name == rule:
|
||||||
|
|
||||||
if perm == 'view' or assign_all:
|
if assign_all or perm == 'view':
|
||||||
ruleset.can_view = True
|
ruleset.can_view = True
|
||||||
elif perm == 'change' or assign_all:
|
elif assign_all or perm == 'change':
|
||||||
ruleset.can_change = True
|
ruleset.can_change = True
|
||||||
elif perm == 'delete' or assign_all:
|
elif assign_all or perm == 'delete':
|
||||||
ruleset.can_delete = True
|
ruleset.can_delete = True
|
||||||
elif perm == 'add' or assign_all:
|
elif assign_all or perm == 'add':
|
||||||
ruleset.can_add = True
|
ruleset.can_add = True
|
||||||
|
|
||||||
ruleset.save()
|
ruleset.save()
|
||||||
|
@ -20,7 +20,7 @@ class HTMLAPITests(InvenTreeTestCase):
|
|||||||
which raised an AssertionError when using the HTML API interface,
|
which raised an AssertionError when using the HTML API interface,
|
||||||
while the regular JSON interface continued to work as expected.
|
while the regular JSON interface continued to work as expected.
|
||||||
"""
|
"""
|
||||||
roles = ['all']
|
roles = 'all'
|
||||||
|
|
||||||
def test_part_api(self):
|
def test_part_api(self):
|
||||||
url = reverse('api-part-list')
|
url = reverse('api-part-list')
|
||||||
|
@ -16,9 +16,7 @@ class CompanyViewTestBase(InvenTreeTestCase):
|
|||||||
'supplier_part',
|
'supplier_part',
|
||||||
]
|
]
|
||||||
|
|
||||||
roles = [
|
roles = 'all'
|
||||||
'all',
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
class CompanyViewTest(CompanyViewTestBase):
|
class CompanyViewTest(CompanyViewTestBase):
|
||||||
|
@ -18,7 +18,7 @@ class BomExportTest(InvenTreeTestCase):
|
|||||||
'bom',
|
'bom',
|
||||||
]
|
]
|
||||||
|
|
||||||
roles = ['all']
|
roles = 'all'
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
@ -17,7 +17,7 @@ class PartViewTestCase(TestCase):
|
|||||||
'supplier_part',
|
'supplier_part',
|
||||||
]
|
]
|
||||||
|
|
||||||
roles = ['all']
|
roles = 'all'
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
@ -260,7 +260,7 @@ class PanelMixinTests(TestCase):
|
|||||||
'stock',
|
'stock',
|
||||||
]
|
]
|
||||||
|
|
||||||
roles = ['all']
|
roles = 'all'
|
||||||
|
|
||||||
def test_installed(self):
|
def test_installed(self):
|
||||||
"""Test that the sample panel plugin is installed"""
|
"""Test that the sample panel plugin is installed"""
|
||||||
|
@ -18,7 +18,7 @@ class StockViewTestCase(InvenTreeTestCase):
|
|||||||
'stock',
|
'stock',
|
||||||
]
|
]
|
||||||
|
|
||||||
roles = ['all']
|
roles = 'all'
|
||||||
|
|
||||||
|
|
||||||
class StockListTest(StockViewTestCase):
|
class StockListTest(StockViewTestCase):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user