feat(chalice): fixed update slack
feat(chalice): changed get /integrations response
This commit is contained in:
parent
b911981c69
commit
3d287cfc58
9 changed files with 28 additions and 17 deletions
|
|
@ -41,5 +41,5 @@ class BaseCollaboration(ABC):
|
|||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def __get(cls, tenant_id, integration_id=None):
|
||||
def get_integration(cls, tenant_id, integration_id=None):
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ class MSTeams(BaseCollaboration):
|
|||
|
||||
@classmethod
|
||||
def send_raw(cls, tenant_id, webhook_id, body):
|
||||
integration = cls.__get(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
integration = cls.get_integration(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
if integration is None:
|
||||
return {"errors": ["msteams integration not found"]}
|
||||
try:
|
||||
|
|
@ -61,7 +61,7 @@ class MSTeams(BaseCollaboration):
|
|||
|
||||
@classmethod
|
||||
def send_batch(cls, tenant_id, webhook_id, attachments):
|
||||
integration = cls.__get(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
integration = cls.get_integration(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
if integration is None:
|
||||
return {"errors": ["msteams integration not found"]}
|
||||
print(f"====> sending msteams batch notification: {len(attachments)}")
|
||||
|
|
@ -95,7 +95,7 @@ class MSTeams(BaseCollaboration):
|
|||
|
||||
@classmethod
|
||||
def __share(cls, tenant_id, integration_id, attachement):
|
||||
integration = cls.__get(tenant_id=tenant_id, integration_id=integration_id)
|
||||
integration = cls.get_integration(tenant_id=tenant_id, integration_id=integration_id)
|
||||
if integration is None:
|
||||
return {"errors": ["Microsoft Teams integration not found"]}
|
||||
r = requests.post(
|
||||
|
|
@ -179,7 +179,7 @@ class MSTeams(BaseCollaboration):
|
|||
return {"data": data}
|
||||
|
||||
@classmethod
|
||||
def __get(cls, tenant_id, integration_id=None):
|
||||
def get_integration(cls, tenant_id, integration_id=None):
|
||||
if integration_id is not None:
|
||||
return webhook.get_webhook(tenant_id=tenant_id, webhook_id=integration_id,
|
||||
webhook_type=schemas.WebhookType.msteams)
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class Slack(BaseCollaboration):
|
|||
|
||||
@classmethod
|
||||
def send_raw(cls, tenant_id, webhook_id, body):
|
||||
integration = cls.__get(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
integration = cls.get_integration(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
if integration is None:
|
||||
return {"errors": ["slack integration not found"]}
|
||||
try:
|
||||
|
|
@ -60,7 +60,7 @@ class Slack(BaseCollaboration):
|
|||
|
||||
@classmethod
|
||||
def send_batch(cls, tenant_id, webhook_id, attachments):
|
||||
integration = cls.__get(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
integration = cls.get_integration(tenant_id=tenant_id, integration_id=webhook_id)
|
||||
if integration is None:
|
||||
return {"errors": ["slack integration not found"]}
|
||||
print(f"====> sending slack batch notification: {len(attachments)}")
|
||||
|
|
@ -76,7 +76,7 @@ class Slack(BaseCollaboration):
|
|||
|
||||
@classmethod
|
||||
def __share(cls, tenant_id, integration_id, attachement):
|
||||
integration = cls.__get(tenant_id=tenant_id, integration_id=integration_id)
|
||||
integration = cls.get_integration(tenant_id=tenant_id, integration_id=integration_id)
|
||||
if integration is None:
|
||||
return {"errors": ["slack integration not found"]}
|
||||
attachement["ts"] = datetime.now().timestamp()
|
||||
|
|
@ -108,7 +108,7 @@ class Slack(BaseCollaboration):
|
|||
return {"data": data}
|
||||
|
||||
@classmethod
|
||||
def __get(cls, tenant_id, integration_id=None):
|
||||
def get_integration(cls, tenant_id, integration_id=None):
|
||||
if integration_id is not None:
|
||||
return webhook.get_webhook(tenant_id=tenant_id, webhook_id=integration_id,
|
||||
webhook_type=schemas.WebhookType.slack)
|
||||
|
|
|
|||
|
|
@ -51,7 +51,10 @@ def get_global_integrations_status(tenant_id, user_id, project_id):
|
|||
AND provider='elasticsearch')) AS {schemas.IntegrationType.elasticsearch.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='slack')) AS {schemas.IntegrationType.slack.value};""",
|
||||
WHERE type='slack')) AS {schemas.IntegrationType.slack.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='msteams')) AS {schemas.IntegrationType.ms_teams.value};""",
|
||||
{"user_id": user_id, "tenant_id": tenant_id, "project_id": project_id})
|
||||
)
|
||||
current_integrations = cur.fetchone()
|
||||
|
|
|
|||
|
|
@ -768,8 +768,7 @@ def get_slack_channels(context: schemas.CurrentContext = Depends(OR_context)):
|
|||
|
||||
@app.get('/integrations/slack/{webhookId}', tags=["integrations"])
|
||||
def get_slack_webhook(webhookId: int, context: schemas.CurrentContext = Depends(OR_context)):
|
||||
return {"data": webhook.get_webhook(tenant_id=context.tenant_id, webhook_id=webhookId,
|
||||
webhook_type=schemas.WebhookType.slack)}
|
||||
return {"data": Slack.get_integration(tenant_id=context.tenant_id, integration_id=webhookId)}
|
||||
|
||||
|
||||
@app.delete('/integrations/slack/{webhookId}', tags=["integrations"])
|
||||
|
|
@ -879,8 +878,9 @@ def add_msteams_integration(data: schemas.AddCollaborationSchema,
|
|||
def edit_msteams_integration(webhookId: int, data: schemas.EditCollaborationSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
if len(data.url) > 0:
|
||||
old = webhook.get_webhook(tenant_id=context.tenant_id, webhook_id=webhookId,
|
||||
webhook_type=schemas.WebhookType.msteams)
|
||||
old = MSTeams.get_integration(tenant_id=context.tenant_id, integration_id=webhookId)
|
||||
if not old:
|
||||
return {"errors": ["MsTeams integration not found."]}
|
||||
if old["endpoint"] != data.url:
|
||||
if not MSTeams.say_hello(data.url):
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -75,7 +75,9 @@ def add_slack_integration(data: schemas.AddCollaborationSchema, context: schemas
|
|||
def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
if len(data.url) > 0:
|
||||
old = webhook.get_webhook(tenant_id=context.tenant_id, webhook_id=integrationId)
|
||||
old = Slack.get_integration(tenant_id=context.tenant_id, integration_id=integrationId)
|
||||
if not old:
|
||||
return {"errors": ["Slack integration not found."]}
|
||||
if old["endpoint"] != data.url:
|
||||
if not Slack.say_hello(data.url):
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -1219,6 +1219,7 @@ class IntegrationType(str, Enum):
|
|||
github = "GITHUB"
|
||||
jira = "JIRA"
|
||||
slack = "SLACK"
|
||||
ms_teams = "MSTEAMS"
|
||||
sentry = "SENTRY"
|
||||
bugsnag = "BUGSNAG"
|
||||
rollbar = "ROLLBAR"
|
||||
|
|
|
|||
|
|
@ -51,7 +51,10 @@ def get_global_integrations_status(tenant_id, user_id, project_id):
|
|||
AND provider='elasticsearch')) AS {schemas.IntegrationType.elasticsearch.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='slack' AND tenant_id=%(tenant_id)s)) AS {schemas.IntegrationType.slack.value};""",
|
||||
WHERE type='slack' AND tenant_id=%(tenant_id)s)) AS {schemas.IntegrationType.slack.value},
|
||||
EXISTS((SELECT 1
|
||||
FROM public.webhooks
|
||||
WHERE type='msteams' AND tenant_id=%(tenant_id)s)) AS {schemas.IntegrationType.ms_teams.value};""",
|
||||
{"user_id": user_id, "tenant_id": tenant_id, "project_id": project_id})
|
||||
)
|
||||
current_integrations = cur.fetchone()
|
||||
|
|
|
|||
|
|
@ -79,7 +79,9 @@ def add_slack_client(data: schemas.AddCollaborationSchema, context: schemas.Curr
|
|||
def edit_slack_integration(integrationId: int, data: schemas.EditCollaborationSchema = Body(...),
|
||||
context: schemas.CurrentContext = Depends(OR_context)):
|
||||
if len(data.url) > 0:
|
||||
old = webhook.get_webhook(tenant_id=context.tenant_id, webhook_id=integrationId)
|
||||
old = Slack.get_integration(tenant_id=context.tenant_id, integration_id=integrationId)
|
||||
if not old:
|
||||
return {"errors": ["Slack integration not found."]}
|
||||
if old["endpoint"] != data.url:
|
||||
if not Slack.say_hello(data.url):
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue