From 4938fb262a87b23a3c31313f420c98e17d376e44 Mon Sep 17 00:00:00 2001 From: KRAIEM Taha Yassine Date: Thu, 20 May 2021 22:41:28 +0200 Subject: [PATCH] Changes: - return full integration body on add slack --- api/chalicelib/blueprints/bp_core_dynamic.py | 6 +++--- api/chalicelib/core/collaboration_slack.py | 11 +++++------ api/chalicelib/core/webhook.py | 8 ++++---- ee/api/chalicelib/blueprints/bp_core_dynamic.py | 6 +++--- ee/api/chalicelib/core/collaboration_slack.py | 11 +++++------ ee/api/chalicelib/ee/webhook.py | 10 +++++----- 6 files changed, 25 insertions(+), 27 deletions(-) diff --git a/api/chalicelib/blueprints/bp_core_dynamic.py b/api/chalicelib/blueprints/bp_core_dynamic.py index 462954cb4..1768896f9 100644 --- a/api/chalicelib/blueprints/bp_core_dynamic.py +++ b/api/chalicelib/blueprints/bp_core_dynamic.py @@ -158,12 +158,12 @@ def add_slack_client(context): data = app.current_request.json_body if "url" not in data or "name" not in data: return {"errors": ["please provide a url and a name"]} - if Slack.add_channel(tenant_id=context["tenantId"], url=data["url"], name=data["name"]): - return {"data": {"status": "success"}} - else: + n = Slack.add_channel(tenant_id=context["tenantId"], url=data["url"], name=data["name"]) + if n is None: return { "errors": ["We couldn't send you a test message on your Slack channel. Please verify your webhook url."] } + return {"data": n} @app.route('/integrations/slack/{integrationId}', methods=['POST', 'PUT']) diff --git a/api/chalicelib/core/collaboration_slack.py b/api/chalicelib/core/collaboration_slack.py index c7df5c5a6..b3da03a37 100644 --- a/api/chalicelib/core/collaboration_slack.py +++ b/api/chalicelib/core/collaboration_slack.py @@ -10,12 +10,11 @@ class Slack: url = args["url"] name = args["name"] if cls.say_hello(url): - webhook.add(tenant_id=tenant_id, - endpoint=url, - webhook_type="slack", - name=name) - return True - return False + return webhook.add(tenant_id=tenant_id, + endpoint=url, + webhook_type="slack", + name=name) + return None @classmethod def say_hello(cls, url): diff --git a/api/chalicelib/core/webhook.py b/api/chalicelib/core/webhook.py index e622c2231..fff2d4e7e 100644 --- a/api/chalicelib/core/webhook.py +++ b/api/chalicelib/core/webhook.py @@ -24,7 +24,7 @@ def get(tenant_id, webhook_id): cur.execute( cur.mogrify("""\ SELECT - w.* + webhook_id AS integration_id, webhook_id AS id, w.* FROM public.webhooks AS w where w.webhook_id =%(webhook_id)s AND deleted_at ISNULL;""", {"webhook_id": webhook_id}) @@ -55,7 +55,7 @@ def get_by_tenant(tenant_id, replace_none=False): with pg_client.PostgresClient() as cur: cur.execute("""\ SELECT - w.* + webhook_id AS integration_id, webhook_id AS id, w.* FROM public.webhooks AS w WHERE deleted_at ISNULL;""" ) @@ -81,7 +81,7 @@ def update(tenant_id, webhook_id, changes, replace_none=False): UPDATE public.webhooks SET {','.join(sub_query)} WHERE webhook_id =%(id)s AND deleted_at ISNULL - RETURNING *;""", + RETURNING webhook_id AS integration_id, webhook_id AS id,*;""", {"id": webhook_id, **changes}) ) w = helper.dict_to_camel_case(cur.fetchone()) @@ -98,7 +98,7 @@ def add(tenant_id, endpoint, auth_header=None, webhook_type='webhook', name="", query = cur.mogrify("""\ INSERT INTO public.webhooks(endpoint,auth_header,type,name) VALUES (%(endpoint)s, %(auth_header)s, %(type)s,%(name)s) - RETURNING *;""", + RETURNING webhook_id AS integration_id, webhook_id AS id,*;""", {"endpoint": endpoint, "auth_header": auth_header, "type": webhook_type, "name": name}) cur.execute( diff --git a/ee/api/chalicelib/blueprints/bp_core_dynamic.py b/ee/api/chalicelib/blueprints/bp_core_dynamic.py index 67d29bf04..6e45627df 100644 --- a/ee/api/chalicelib/blueprints/bp_core_dynamic.py +++ b/ee/api/chalicelib/blueprints/bp_core_dynamic.py @@ -159,12 +159,12 @@ def add_slack_client(context): data = app.current_request.json_body if "url" not in data or "name" not in data: return {"errors": ["please provide a url and a name"]} - if Slack.add_channel(tenant_id=context["tenantId"], url=data["url"], name=data["name"]): - return {"data": {"status": "success"}} - else: + n = Slack.add_channel(tenant_id=context["tenantId"], url=data["url"], name=data["name"]) + if n is None: return { "errors": ["We couldn't send you a test message on your Slack channel. Please verify your webhook url."] } + return {"data": n} @app.route('/integrations/slack/{integrationId}', methods=['POST', 'PUT']) diff --git a/ee/api/chalicelib/core/collaboration_slack.py b/ee/api/chalicelib/core/collaboration_slack.py index c7df5c5a6..b3da03a37 100644 --- a/ee/api/chalicelib/core/collaboration_slack.py +++ b/ee/api/chalicelib/core/collaboration_slack.py @@ -10,12 +10,11 @@ class Slack: url = args["url"] name = args["name"] if cls.say_hello(url): - webhook.add(tenant_id=tenant_id, - endpoint=url, - webhook_type="slack", - name=name) - return True - return False + return webhook.add(tenant_id=tenant_id, + endpoint=url, + webhook_type="slack", + name=name) + return None @classmethod def say_hello(cls, url): diff --git a/ee/api/chalicelib/ee/webhook.py b/ee/api/chalicelib/ee/webhook.py index 73641b77d..20e873f5c 100644 --- a/ee/api/chalicelib/ee/webhook.py +++ b/ee/api/chalicelib/ee/webhook.py @@ -8,7 +8,7 @@ def get_by_id(webhook_id): cur.execute( cur.mogrify("""\ SELECT - w.* + webhook_id AS integration_id, webhook_id AS id, w.* FROM public.webhooks AS w where w.webhook_id =%(webhook_id)s AND deleted_at ISNULL;""", {"webhook_id": webhook_id}) @@ -24,7 +24,7 @@ def get(tenant_id, webhook_id): cur.execute( cur.mogrify("""\ SELECT - w.* + webhook_id AS integration_id, webhook_id AS id, w.* FROM public.webhooks AS w where w.webhook_id =%(webhook_id)s AND w.tenant_id =%(tenant_id)s AND deleted_at ISNULL;""", {"webhook_id": webhook_id, "tenant_id": tenant_id}) @@ -59,7 +59,7 @@ def get_by_tenant(tenant_id, replace_none=False): cur.execute( cur.mogrify("""\ SELECT - w.* + webhook_id AS integration_id, webhook_id AS id,w.* FROM public.webhooks AS w where w.tenant_id =%(tenant_id)s @@ -88,7 +88,7 @@ def update(tenant_id, webhook_id, changes, replace_none=False): UPDATE public.webhooks SET {','.join(sub_query)} WHERE tenant_id =%(tenant_id)s AND webhook_id =%(id)s AND deleted_at ISNULL - RETURNING *;""", + RETURNING webhook_id AS integration_id, webhook_id AS id,*;""", {"tenant_id": tenant_id, "id": webhook_id, **changes}) ) w = helper.dict_to_camel_case(cur.fetchone()) @@ -105,7 +105,7 @@ def add(tenant_id, endpoint, auth_header=None, webhook_type='webhook', name="", query = cur.mogrify("""\ INSERT INTO public.webhooks(tenant_id, endpoint,auth_header,type,name) VALUES (%(tenant_id)s, %(endpoint)s, %(auth_header)s, %(type)s,%(name)s) - RETURNING *;""", + RETURNING webhook_id AS integration_id, webhook_id AS id,*;""", {"tenant_id": tenant_id, "endpoint": endpoint, "auth_header": auth_header, "type": webhook_type, "name": name}) cur.execute(