- return full integration body on add slack
This commit is contained in:
KRAIEM Taha Yassine 2021-05-20 22:41:28 +02:00
parent 09d3dfab6e
commit 4938fb262a
6 changed files with 25 additions and 27 deletions

View file

@ -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'])

View file

@ -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):

View file

@ -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(

View file

@ -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'])

View file

@ -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):

View file

@ -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(