mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-17 04:58:16 -06:00
14438 update migration for event rules
This commit is contained in:
parent
84b4085a1f
commit
0100857e92
@ -522,7 +522,7 @@ class ScriptSerializer(ValidatedModelSerializer):
|
||||
class Meta:
|
||||
model = Script
|
||||
fields = [
|
||||
'id', 'url', 'module', 'name', 'description', 'vars', 'result', 'display',
|
||||
'id', 'url', 'module', 'name', 'description', 'vars', 'result', 'display', 'is_valid',
|
||||
]
|
||||
|
||||
@extend_schema_field(serializers.JSONField(allow_null=True))
|
||||
|
@ -1,5 +1,6 @@
|
||||
# Generated by Django 4.2.9 on 2024-02-05 21:37
|
||||
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
@ -8,7 +9,7 @@ def update_scripts(apps, schema_editor):
|
||||
from extras.models import ScriptModule
|
||||
ScriptModuleNew = apps.get_model('extras', 'ScriptModule')
|
||||
Script = apps.get_model('extras', 'Script')
|
||||
ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
# ContentType = apps.get_model('contenttypes', 'ContentType')
|
||||
ct = ContentType.objects.filter(app_label='extras', model='script').first()
|
||||
|
||||
for module in ScriptModule.objects.all():
|
||||
@ -19,8 +20,18 @@ def update_scripts(apps, schema_editor):
|
||||
)
|
||||
|
||||
# update all jobs associated with this module/name to point to the new script obj
|
||||
if ct:
|
||||
module.jobs.filter(name=script).update(object_type=ct, object_id=obj.id)
|
||||
module.jobs.filter(name=script).update(object_type=ct, object_id=obj.id)
|
||||
|
||||
EventRule = apps.get_model('extras', 'EventRule')
|
||||
ct_script_module = ContentType.objects.filter(app_label='extras', model='scriptmodule').first()
|
||||
for rule in EventRule.objects.filter(action_object_type=ct_script_module):
|
||||
name = rule.action_parameters.get('script_name')
|
||||
if name:
|
||||
obj = Script.objects.filter(module=rule.action_object, name=name).first()
|
||||
if obj:
|
||||
rule.action_paramter = obj
|
||||
rule.action_parameters.pop(name, None)
|
||||
rule.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
Loading…
Reference in New Issue
Block a user