2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-05 19:41:41 +00:00
Files
.github
InvenTree
InvenTree
barcodes
build
common
company
label
locale
order
part
plugins
report
script
stock
templates
users
fixtures
migrations
__init__.py
admin.py
api.py
apps.py
models.py
serializers.py
test_migrations.py
tests.py
urls.py
config_template.yaml
gunicorn.conf.py
manage.py
ci
deploy
docker
images
.eslintrc.yml
.gitattributes
.gitignore
CONTRIBUTING.md
LICENSE
README.md
RELEASE.md
crowdin.yml
requirements.txt
setup.cfg
tasks.py
InvenTree/InvenTree/users/apps.py
Oliver 5ba7aeaa27 Fixes:
- Use DRF ImageField, not FileField
- Ensure that permissions get updated correctly in 'test' mode
- Allow file upload in the APITester class
2021-06-23 10:28:21 +10:00

57 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db.utils import OperationalError, ProgrammingError
from django.apps import AppConfig
from InvenTree.ready import canAppAccessDatabase
class UsersConfig(AppConfig):
name = 'users'
def ready(self):
if canAppAccessDatabase(allow_test=True):
try:
self.assign_permissions()
except (OperationalError, ProgrammingError):
pass
try:
self.update_owners()
except (OperationalError, ProgrammingError):
pass
def assign_permissions(self):
from django.contrib.auth.models import Group
from users.models import RuleSet, update_group_roles
# First, delete any rule_set objects which have become outdated!
for rule in RuleSet.objects.all():
if rule.name not in RuleSet.RULESET_NAMES:
print("need to delete:", rule.name)
rule.delete()
# Update group permission assignments for all groups
for group in Group.objects.all():
update_group_roles(group)
def update_owners(self):
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from users.models import Owner
# Create group owners
for group in Group.objects.all():
Owner.create(group)
# Create user owners
for user in get_user_model().objects.all():
Owner.create(user)