mirror of
https://github.com/ansible/awx.git
synced 2026-05-14 21:07:39 -02:30
Add the webhook-specific fields to JobTemplate and WorkflowJobTemplate
This commit is contained in:
44
awx/main/migrations/0092_v360_webhook_mixin.py
Normal file
44
awx/main/migrations/0092_v360_webhook_mixin.py
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
# Generated by Django 2.2.4 on 2019-09-12 14:49
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0091_v360_approval_node_notifications'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='jobtemplate',
|
||||||
|
name='webhook_credential',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='jobtemplates', to='main.Credential'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='jobtemplate',
|
||||||
|
name='webhook_key',
|
||||||
|
field=models.CharField(blank=True, max_length=64),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='jobtemplate',
|
||||||
|
name='webhook_service',
|
||||||
|
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab'), ('bitbucket', 'Bitbucket')], max_length=16),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='workflowjobtemplate',
|
||||||
|
name='webhook_credential',
|
||||||
|
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='workflowjobtemplates', to='main.Credential'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='workflowjobtemplate',
|
||||||
|
name='webhook_key',
|
||||||
|
field=models.CharField(blank=True, max_length=64),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='workflowjobtemplate',
|
||||||
|
name='webhook_service',
|
||||||
|
field=models.CharField(blank=True, choices=[('github', 'Github'), ('gitlab', 'Gitlab'), ('bitbucket', 'Bitbucket')], max_length=16),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -48,6 +48,7 @@ from awx.main.models.mixins import (
|
|||||||
TaskManagerJobMixin,
|
TaskManagerJobMixin,
|
||||||
CustomVirtualEnvMixin,
|
CustomVirtualEnvMixin,
|
||||||
RelatedJobsMixin,
|
RelatedJobsMixin,
|
||||||
|
WebhookMixin,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -187,7 +188,7 @@ class JobOptions(BaseModel):
|
|||||||
return needed
|
return needed
|
||||||
|
|
||||||
|
|
||||||
class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin):
|
class JobTemplate(UnifiedJobTemplate, JobOptions, SurveyJobTemplateMixin, ResourceMixin, CustomVirtualEnvMixin, RelatedJobsMixin, WebhookMixin):
|
||||||
'''
|
'''
|
||||||
A job template is a reusable job definition for applying a project (with
|
A job template is a reusable job definition for applying a project (with
|
||||||
playbook) to an inventory source with a given credential.
|
playbook) to an inventory source with a given credential.
|
||||||
|
|||||||
@@ -7,12 +7,12 @@ from copy import copy, deepcopy
|
|||||||
# Django
|
# Django
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from django.contrib.auth.models import User # noqa
|
from django.contrib.auth.models import User # noqa
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
|
from django.db import models
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
# AWX
|
# AWX
|
||||||
from awx.main.models.base import prevent_search
|
from awx.main.models.base import prevent_search
|
||||||
@@ -483,3 +483,31 @@ class RelatedJobsMixin(object):
|
|||||||
raise RuntimeError("Programmer error. Expected _get_active_jobs() to return a QuerySet.")
|
raise RuntimeError("Programmer error. Expected _get_active_jobs() to return a QuerySet.")
|
||||||
|
|
||||||
return [dict(id=t[0], type=mapping[t[1]]) for t in jobs.values_list('id', 'polymorphic_ctype_id')]
|
return [dict(id=t[0], type=mapping[t[1]]) for t in jobs.values_list('id', 'polymorphic_ctype_id')]
|
||||||
|
|
||||||
|
|
||||||
|
class WebhookMixin(models.Model):
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
SERVICES = [
|
||||||
|
('github', "Github"),
|
||||||
|
('gitlab', "Gitlab"),
|
||||||
|
('bitbucket', "Bitbucket"),
|
||||||
|
]
|
||||||
|
|
||||||
|
webhook_service = models.CharField(
|
||||||
|
max_length=16,
|
||||||
|
choices=SERVICES,
|
||||||
|
blank=True
|
||||||
|
)
|
||||||
|
webhook_key = prevent_search(models.CharField(
|
||||||
|
max_length=64,
|
||||||
|
blank=True
|
||||||
|
))
|
||||||
|
webhook_credential = models.ForeignKey(
|
||||||
|
'Credential',
|
||||||
|
blank=True,
|
||||||
|
null=True,
|
||||||
|
on_delete=models.SET_NULL,
|
||||||
|
related_name='%(class)ss'
|
||||||
|
)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ from awx.main.models.mixins import (
|
|||||||
SurveyJobTemplateMixin,
|
SurveyJobTemplateMixin,
|
||||||
SurveyJobMixin,
|
SurveyJobMixin,
|
||||||
RelatedJobsMixin,
|
RelatedJobsMixin,
|
||||||
|
WebhookMixin,
|
||||||
)
|
)
|
||||||
from awx.main.models.jobs import LaunchTimeConfigBase, LaunchTimeConfig, JobTemplate
|
from awx.main.models.jobs import LaunchTimeConfigBase, LaunchTimeConfig, JobTemplate
|
||||||
from awx.main.models.credential import Credential
|
from awx.main.models.credential import Credential
|
||||||
@@ -358,7 +359,7 @@ class WorkflowJobOptions(LaunchTimeConfigBase):
|
|||||||
return new_workflow_job
|
return new_workflow_job
|
||||||
|
|
||||||
|
|
||||||
class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTemplateMixin, ResourceMixin, RelatedJobsMixin):
|
class WorkflowJobTemplate(UnifiedJobTemplate, WorkflowJobOptions, SurveyJobTemplateMixin, ResourceMixin, RelatedJobsMixin, WebhookMixin):
|
||||||
|
|
||||||
SOFT_UNIQUE_TOGETHER = [('polymorphic_ctype', 'name', 'organization')]
|
SOFT_UNIQUE_TOGETHER = [('polymorphic_ctype', 'name', 'organization')]
|
||||||
FIELDS_TO_PRESERVE_AT_COPY = [
|
FIELDS_TO_PRESERVE_AT_COPY = [
|
||||||
|
|||||||
Reference in New Issue
Block a user