-
Notifications
You must be signed in to change notification settings - Fork 2.9k
14438 database representation of scripts #15061
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
1034ee7
14438 script model
arthanson 4cb3b63
14438 script model
arthanson fc890e3
14438 script model
arthanson 6930e44
14438 script job mapping
arthanson 5981fc9
14438 script job mapping
arthanson 9543169
14438 script job run
arthanson d162d44
14438 fix migration
arthanson 0bd15c3
14438 merge feature
arthanson 0c214d3
14438 fix merge
arthanson 41c792a
14438 fix merge
arthanson 172d1b0
14438 check valid script for views
arthanson c0a5de0
14438 check valid script for views
arthanson f7e55a0
14438 view fixes cleanup
arthanson d382350
14438 view fixes cleanup
arthanson 079dc00
14438 view fixes cleanup
arthanson 8c17d73
14438 fix delete
arthanson 6846ec7
14438 temp fix
arthanson 2f8a7b9
Merge branch 'feature' into 14438-script-model
arthanson 5290c86
14438 fix serializer and api view
arthanson b4c9f93
14438 fix api post
arthanson d9afaf9
14438 fix tests
arthanson 84b4085
14438 fix tests
arthanson 0100857
14438 update migration for event rules
arthanson 1a6099f
14438 update migration for event rules
arthanson 8c2fbce
14438 update EventRule code / form
arthanson 4fdce65
14438 fix migration
arthanson 63d3ce6
14438 fix migration
arthanson bc59634
14438 add generic relation so delete will show event rule
arthanson ee88c2f
14438 optimize migration
arthanson 6cb176a
Merge branch 'feature' into 14438-script-model
arthanson 38d2cbb
14438 review changes
arthanson c4ffafa
14438 review changes
arthanson ecd2712
14438 temp
arthanson e9f28dc
14438 update migration
arthanson 613f9f2
14438 update migration
arthanson ba8329e
14438 review comments retain old urls
arthanson 638c303
Update references to is_executable
jeremystretch 6422049
Replace legacy URLs with redirects
jeremystretch 1ea0b6d
Restore missing edit button for script modules
jeremystretch af2c642
14438 review changes
arthanson 3182977
Merge branch 'feature' into 14438-script-model
arthanson 8b54ff7
14438 update init_script_choice in form
arthanson cb2bf2b
14438 soft delete
arthanson 1c14c35
14438 get_module_scripts -> module_scripts
arthanson 1ccbe94
14438 post_save sync handler
arthanson 34d3c12
14438 result on script model and serializer update
arthanson f9608f7
14438 init_vars_or_redirect
arthanson 49b90ca
14438 fixes
arthanson 785ff34
14438 update api doc string
arthanson 4733376
14438 docstring
arthanson 1060ff8
14438 add permissions
arthanson f7be815
14438 add schema
arthanson a2b2a1d
Merge branch 'feature' into 14438-script-model
jeremystretch 2d206fb
Misc cleanup
jeremystretch 274bbfa
Fix support for object-based permissions
jeremystretch 890c94b
Clean up migrations
jeremystretch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,9 +44,6 @@ | |
| 'ImageAttachmentSerializer', | ||
| 'JournalEntrySerializer', | ||
| 'ObjectChangeSerializer', | ||
| 'ReportDetailSerializer', | ||
| 'ReportSerializer', | ||
| 'ReportInputSerializer', | ||
| 'SavedFilterSerializer', | ||
| 'ScriptDetailSerializer', | ||
| 'ScriptInputSerializer', | ||
|
|
@@ -85,9 +82,9 @@ def get_action_object(self, instance): | |
| context = {'request': self.context['request']} | ||
| # We need to manually instantiate the serializer for scripts | ||
| if instance.action_type == EventRuleActionChoices.SCRIPT: | ||
| script_name = instance.action_parameters['script_name'] | ||
| script = instance.action_object.scripts[script_name]() | ||
| return NestedScriptSerializer(script, context=context).data | ||
| script = instance.action_object | ||
| instance = script.python_class() if script.python_class else None | ||
| return NestedScriptSerializer(instance, context=context).data | ||
| else: | ||
| serializer = get_serializer_for_model( | ||
| model=instance.action_object_type.model_class(), | ||
|
|
@@ -512,79 +509,54 @@ class Meta: | |
| ] | ||
|
|
||
|
|
||
| # | ||
| # Reports | ||
| # | ||
|
|
||
| class ReportSerializer(serializers.Serializer): | ||
| url = serializers.HyperlinkedIdentityField( | ||
| view_name='extras-api:report-detail', | ||
| lookup_field='full_name', | ||
| lookup_url_kwarg='pk' | ||
| ) | ||
| id = serializers.CharField(read_only=True, source="full_name") | ||
| module = serializers.CharField(max_length=255) | ||
| name = serializers.CharField(max_length=255) | ||
| description = serializers.CharField(max_length=255, required=False) | ||
| test_methods = serializers.ListField(child=serializers.CharField(max_length=255), read_only=True) | ||
| result = NestedJobSerializer() | ||
| display = serializers.SerializerMethodField(read_only=True) | ||
|
|
||
| @extend_schema_field(serializers.CharField()) | ||
| def get_display(self, obj): | ||
| return f'{obj.name} ({obj.module})' | ||
|
|
||
|
|
||
| class ReportDetailSerializer(ReportSerializer): | ||
| result = JobSerializer() | ||
|
|
||
|
|
||
| class ReportInputSerializer(serializers.Serializer): | ||
| schedule_at = serializers.DateTimeField(required=False, allow_null=True) | ||
| interval = serializers.IntegerField(required=False, allow_null=True) | ||
|
|
||
| def validate_schedule_at(self, value): | ||
| if value and not self.context['report'].scheduling_enabled: | ||
| raise serializers.ValidationError(_("Scheduling is not enabled for this report.")) | ||
| return value | ||
|
|
||
| def validate_interval(self, value): | ||
| if value and not self.context['report'].scheduling_enabled: | ||
| raise serializers.ValidationError(_("Scheduling is not enabled for this report.")) | ||
| return value | ||
|
|
||
|
|
||
| # | ||
| # Scripts | ||
| # | ||
|
|
||
| class ScriptSerializer(serializers.Serializer): | ||
| url = serializers.HyperlinkedIdentityField( | ||
| view_name='extras-api:script-detail', | ||
| lookup_field='full_name', | ||
| lookup_url_kwarg='pk' | ||
| ) | ||
| id = serializers.CharField(read_only=True, source="full_name") | ||
| module = serializers.CharField(max_length=255) | ||
| name = serializers.CharField(read_only=True) | ||
| description = serializers.CharField(read_only=True) | ||
| class ScriptSerializer(ValidatedModelSerializer): | ||
| url = serializers.HyperlinkedIdentityField(view_name='extras-api:script-detail') | ||
| description = serializers.SerializerMethodField(read_only=True) | ||
| vars = serializers.SerializerMethodField(read_only=True) | ||
| result = NestedJobSerializer() | ||
| display = serializers.SerializerMethodField(read_only=True) | ||
| result = NestedJobSerializer(read_only=True) | ||
|
|
||
| class Meta: | ||
| model = Script | ||
| fields = [ | ||
| 'id', 'url', 'module', 'name', 'description', 'vars', 'result', 'display', 'is_executable', | ||
| ] | ||
|
|
||
| @extend_schema_field(serializers.JSONField(allow_null=True)) | ||
| def get_vars(self, instance): | ||
| return { | ||
| k: v.__class__.__name__ for k, v in instance._get_vars().items() | ||
| } | ||
| def get_vars(self, obj): | ||
| if obj.python_class: | ||
| return { | ||
| k: v.__class__.__name__ for k, v in obj.python_class()._get_vars().items() | ||
| } | ||
| else: | ||
| return {} | ||
|
|
||
| @extend_schema_field(serializers.CharField()) | ||
| def get_display(self, obj): | ||
arthanson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return f'{obj.name} ({obj.module})' | ||
|
|
||
| @extend_schema_field(serializers.CharField()) | ||
| def get_description(self, obj): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason not to save |
||
| if obj.python_class: | ||
| return obj.python_class().description | ||
| else: | ||
| return None | ||
|
|
||
|
|
||
| class ScriptDetailSerializer(ScriptSerializer): | ||
| result = JobSerializer() | ||
| result = serializers.SerializerMethodField(read_only=True) | ||
|
|
||
| @extend_schema_field(JobSerializer()) | ||
| def get_result(self, obj): | ||
| job = obj.jobs.all().order_by('-created').first() | ||
| context = { | ||
| 'request': self.context['request'] | ||
| } | ||
| data = JobSerializer(job, context=context).data | ||
| return data | ||
|
|
||
|
|
||
| class ScriptInputSerializer(serializers.Serializer): | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.