feat(core): add to migration signal system user and use for inventory objects
ref: #948 closes #949
This commit is contained in:
@ -1,4 +1,6 @@
|
|||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
|
from django.conf import settings
|
||||||
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from django.db.models.signals import (
|
from django.db.models.signals import (
|
||||||
post_migrate,
|
post_migrate,
|
||||||
)
|
)
|
||||||
@ -14,6 +16,31 @@ def centurion_model_migrate(sender, **kwargs):
|
|||||||
if sender.label != 'core':
|
if sender.label != 'core':
|
||||||
return
|
return
|
||||||
|
|
||||||
|
try:
|
||||||
|
|
||||||
|
print('\n\nFetching System User.\n')
|
||||||
|
|
||||||
|
user = apps.get_model(settings.AUTH_USER_MODEL).objects.get(
|
||||||
|
username = 'system'
|
||||||
|
)
|
||||||
|
|
||||||
|
if user.is_active:
|
||||||
|
print(' System user is set as "Active", disabling.\n')
|
||||||
|
user.is_active = False
|
||||||
|
|
||||||
|
user.save()
|
||||||
|
|
||||||
|
except ObjectDoesNotExist:
|
||||||
|
|
||||||
|
print(' System user not found, creating.\n')
|
||||||
|
|
||||||
|
user = apps.get_model(settings.AUTH_USER_MODEL).objects.create(
|
||||||
|
username = 'system',
|
||||||
|
first_name = 'System',
|
||||||
|
last_name = 'User',
|
||||||
|
is_active = False,
|
||||||
|
)
|
||||||
|
|
||||||
print('\n\nCenturion Model Migration Signal.....\n')
|
print('\n\nCenturion Model Migration Signal.....\n')
|
||||||
|
|
||||||
models: list[ dict ] = [
|
models: list[ dict ] = [
|
||||||
@ -261,7 +288,7 @@ def centurion_model_migrate(sender, **kwargs):
|
|||||||
model_name = model.get_history_model_name( model )
|
model_name = model.get_history_model_name( model )
|
||||||
)
|
)
|
||||||
|
|
||||||
history = original_history.objects.filter().exclude( user = None )
|
history = original_history.objects.filter()
|
||||||
|
|
||||||
print(f' Found {len(history)} history entries to migrate.')
|
print(f' Found {len(history)} history entries to migrate.')
|
||||||
|
|
||||||
@ -269,18 +296,28 @@ def centurion_model_migrate(sender, **kwargs):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
after = {}
|
||||||
|
if entry.after:
|
||||||
|
after = entry.after
|
||||||
|
|
||||||
entry_model = entry.model
|
entry_model = entry.model
|
||||||
if hasattr(entry, 'child_model'):
|
if hasattr(entry, 'child_model'):
|
||||||
entry_model = entry.child_model
|
entry_model = entry.child_model
|
||||||
|
|
||||||
|
entry_user = entry.user
|
||||||
|
|
||||||
|
if not entry_user:
|
||||||
|
|
||||||
|
entry_user = user
|
||||||
|
|
||||||
migrated_history = audit_history.objects.create(
|
migrated_history = audit_history.objects.create(
|
||||||
organization = entry.organization,
|
organization = entry.organization,
|
||||||
content_type = entry.content_type,
|
content_type = entry.content_type,
|
||||||
model = entry_model,
|
model = entry_model,
|
||||||
before = entry.before,
|
before = entry.before,
|
||||||
after = entry.after,
|
after = after,
|
||||||
action = entry.action,
|
action = entry.action,
|
||||||
user = entry.user,
|
user = entry_user,
|
||||||
created = entry.created
|
created = entry.created
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ The device can also have configuration defined. this configuration is intended t
|
|||||||
|
|
||||||
It's possible for a machine to be inventoried and have the report passed to the [inventory endpoint](../api.md#inventory-reports). This report will update the device within the interface and provides the option to use scheduled inventory gathering to keep the device up to date.
|
It's possible for a machine to be inventoried and have the report passed to the [inventory endpoint](../api.md#inventory-reports). This report will update the device within the interface and provides the option to use scheduled inventory gathering to keep the device up to date.
|
||||||
|
|
||||||
Inventory processing is conducted by a background worker. As soon as the inventory is uploaded, the inventory processing is added to the background worker queue. Further information about the background worker can be found within its [documentation](../core/index.md#background-worker)
|
Inventory processing is conducted by a background worker. As soon as the inventory is uploaded, the inventory processing is added to the background worker queue. Further information about the background worker can be found within its [documentation](../core/index.md#background-worker). All inventory objects history entries will be added by a user called `System User` regardless of the user that was used to authenticated to upload the inventory.
|
||||||
|
|
||||||
!!! tip
|
!!! tip
|
||||||
Inventory not uploading? review the task logs by navigating to `Settings -> Application -> Task Logs`
|
Inventory not uploading? review the task logs by navigating to `Settings -> Application -> Task Logs`
|
||||||
|
Reference in New Issue
Block a user