Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add name to the webhook classes

Maciej Korycinski95a495785a84
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 21fe9f5932..5943339f8e 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -4259,6 +4259,7 @@ type VoucherUpdate {
}
type Webhook implements Node {
+ name: String
serviceAccount: ServiceAccount!
targetUrl: String!
isActive: Boolean!
@@ -4285,6 +4286,7 @@ type WebhookCreate {
}
input WebhookCreateInput {
+ name: String
targetUrl: String
events: [WebhookEventTypeEnum]
serviceAccount: ID
@@ -4333,6 +4335,7 @@ type WebhookUpdate {
}
input WebhookUpdateInput {
+ name: String
targetUrl: String
events: [WebhookEventTypeEnum]
serviceAccount: ID
diff --git a/saleor/graphql/webhook/mutations.py b/saleor/graphql/webhook/mutations.py
index 208b67979b..50a27ad63d 100644
--- a/saleor/graphql/webhook/mutations.py
+++ b/saleor/graphql/webhook/mutations.py
@@ -10,6 +10,7 @@ from .types import Webhook
class WebhookCreateInput(graphene.InputObjectType):
+ name = graphene.String(description="The name of the webhook.", required=False)
target_url = graphene.String(description="The url to receive the payload.")
events = graphene.List(
WebhookEventTypeEnum, description="The events that webhook wants to subscribe."
@@ -93,6 +94,7 @@ class WebhookCreate(ModelMutation):
class WebhookUpdateInput(graphene.InputObjectType):
+ name = graphene.String(description="The new name of the webhook.", required=False)
target_url = graphene.String(
description="The url to receive the payload.", required=False
)
diff --git a/saleor/graphql/webhook/types.py b/saleor/graphql/webhook/types.py
index 42670e7747..23eb0f8f25 100644
--- a/saleor/graphql/webhook/types.py
+++ b/saleor/graphql/webhook/types.py
@@ -22,7 +22,13 @@ class Webhook(CountableDjangoObjectType):
description = "Webhook"
model = models.Webhook
interfaces = [graphene.relay.Node]
- only_fields = ["service_account", "target_url", "is_active", "secret_key"]
+ only_fields = [
+ "service_account",
+ "target_url",
+ "is_active",
+ "secret_key",
+ "name",
+ ]
@staticmethod
@gql_optimizer.resolver_hints(prefetch_related=("events",))
diff --git a/saleor/webhook/migrations/0002_webhook_name.py b/saleor/webhook/migrations/0002_webhook_name.py
new file mode 100644
index 0000000000..285df87f4e
--- /dev/null
+++ b/saleor/webhook/migrations/0002_webhook_name.py
@@ -0,0 +1,16 @@
+# Generated by Django 2.2.4 on 2019-10-02 06:52
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("webhook", "0001_initial")]
+
+ operations = [
+ migrations.AddField(
+ model_name="webhook",
+ name="name",
+ field=models.CharField(blank=True, max_length=255, null=True),
+ )
+ ]
diff --git a/saleor/webhook/models.py b/saleor/webhook/models.py
index 2ddefa821b..b389740143 100644
--- a/saleor/webhook/models.py
+++ b/saleor/webhook/models.py
@@ -5,6 +5,7 @@ from ..account.models import ServiceAccount
class Webhook(models.Model):
+ name = models.CharField(max_length=255, null=True, blank=True)
service_account = models.ForeignKey(
ServiceAccount, related_name="webhooks", on_delete=models.CASCADE
)
diff --git a/tests/api/test_webhook.py b/tests/api/test_webhook.py
index 6a3733a7d9..7bb2b9f10c 100644
--- a/tests/api/test_webhook.py
+++ b/tests/api/test_webhook.py
@@ -7,8 +7,9 @@ from saleor.webhook.models import Webhook
from .utils import assert_no_permission, get_graphql_content
WEBHOOK_CREATE_BY_SERVICE_ACCOUNT = """
- mutation webhookCreate($target_url: String, $events: [WebhookEventTypeEnum]){
- webhookCreate(input:{targetUrl:$target_url, events:$events}){
+ mutation webhookCreate($name: String, $target_url: String,
+ $events: [WebhookEventTypeEnum]){
+ webhookCreate(input:{name: $name, targetUrl:$target_url, events:$events}){
errors{
field
message
@@ -27,12 +28,14 @@ def test_webhook_create_by_service_account(
service_account.permissions.add(permission_manage_orders)
query = WEBHOOK_CREATE_BY_SERVICE_ACCOUNT
variables = {
+ "name": "New integration",
"target_url": "https://www.example.com",
"events": [WebhookEventTypeEnum.ORDER_CREATED.name],
}
response = service_account_api_client.post_graphql(query, variables=variables)
get_graphql_content(response)
new_webhook = Webhook.objects.get()
+ assert new_webhook.name == "New integration"
assert new_webhook.target_url == "https://www.example.com"
events = new_webhook.events.all()
assert len(events) == 1
@@ -49,6 +52,7 @@ def test_webhook_create_inactive_service_account(
variables = {
"target_url": "https://www.example.com",
"events": [WebhookEventTypeEnum.ORDER_CREATED.name],
+ "name": "",
}
response = service_account_api_client.post_graphql(query, variables=variables)
@@ -64,6 +68,7 @@ def test_webhook_create_without_service_account(
variables = {
"target_url": "https://www.example.com",
"events": [WebhookEventTypeEnum.ORDER_CREATED.name],
+ "name": "",
}
response = service_account_api_client.post_graphql(query, variables=variables)
assert_no_permission(response)
@@ -78,6 +83,7 @@ def test_webhook_create_service_account_doesnt_exist(
variables = {
"target_url": "https://www.example.com",
"events": [WebhookEventTypeEnum.ORDER_CREATED.name],
+ "name": "",
}
response = service_account_api_client.post_graphql(query, variables=variables)
assert_no_permission(response)