Files
Tanmoy SarkarandGitHub f9d9a5a530 feat: webhook feature implementation (#2162)
* feat: created required doctypes

* feat: webhook dispatch function added

* fix: typo

* feat: webhook queue processor implemented

* feat: webhook retry and logging support added

* feat: webhook endpoint pre-validation added

* chore: rename callback_url to endpoint in webhook

* chore: check webhook status

* feat: webhook list and webhook add dialog added

* feat: endpoint validation added

* feat: delete webhook support added

* feat: use client.list instead of new api

* feat: webhook activation flow completed

* feat: delete webhook log at the time of deleting webhook

* feat: webhook disable support added

* feat: webhook config edit support added

* fix: permission and dashboard api whitelisting of Press Webhook Log

* feat: webhook log page and dialog added

* chore: refactor ui
- move webhook logs page to modal
- move webhook details modal to integrated page in logs
- code quality fixed

* chore: webhook list in dialog revamped

* chore: add notice for webhook log retention of 24hr

* feat: job added to purge 24hrs old logs

* chore: handle failure

* chore: use deduplicate

* chore: better error message

* feat: configure webhook events

* feat: export fixtures of press webhook event

* fix: lint issues

* fix: lint issues

* fix: format files using ruff

* chore: remove bench status update from list

* feat: auto disable high failure webhooks and alert team

* chore: remove debug statement

* feat: mark in-process webhook calls to status queued to reduce duplicate entry

* chore: lint

* chore: lint

* feat: disallow use of query params

* fix(ruff-lint): reduce complexity in is_setup_wizard_complete

* fix(ruff-lint): reduce complexity in get_current_team method
2024-09-23 17:25:39 +05:30

136 lines
3.1 KiB
Vue

<template>
<Dialog
:options="{
title: 'Activate Webhook'
}"
>
<template #body-content>
<div class="space-y-4">
<FormControl label="Endpoint" v-model="webhook.endpoint" disabled />
<div v-if="request">
<p class="text-xs text-gray-600">Request</p>
<pre
class="mt-2 whitespace-pre-wrap rounded bg-gray-50 px-2 py-1.5 text-sm text-gray-600"
>{{ request }}</pre
>
</div>
<FormControl
v-if="response_status_code"
label="Response Status Code"
v-model="response_status_code"
disabled
/>
<div v-if="response">
<p class="text-xs text-gray-600">Response</p>
<pre
class="mt-2 max-h-52 overflow-y-auto whitespace-pre-wrap rounded bg-gray-50 px-2 py-1.5 text-sm text-gray-600"
>{{ response }}</pre
>
</div>
<div class="flex items-center" v-if="validated">
<ILucideCheck class="h-4 text-green-600" />
<div class="ml-2 text-sm font-medium text-gray-700">
Endpoint has been validated
</div>
</div>
<ErrorMessage :message="errorMessage" />
</div>
</template>
<template v-slot:actions>
<Button
class="w-full"
theme="gray"
variant="solid"
@click="$resources.validateEndpoint.submit()"
:loading="$resources.validateEndpoint.loading"
loadingText="Validating Webhook"
v-if="!validated"
>Validate Webhook</Button
>
<Button
class="w-full"
theme="gray"
variant="solid"
@click="$resources.activateWebhook.submit()"
:loading="$resources.activateWebhook.loading"
loadingText="Activating Webhook"
v-if="validated"
>Activate Webhook</Button
>
</template>
</Dialog>
</template>
<script>
import { toast } from 'vue-sonner';
export default {
emits: ['success'],
props: ['webhook'],
data() {
return {
errorMessage: '',
validated: false,
request: null,
response: null,
response_status_code: null
};
},
resources: {
validateEndpoint() {
return {
url: 'press.api.client.run_doc_method',
makeParams() {
return {
dt: 'Press Webhook',
dn: this.webhook.name,
method: 'validate_endpoint'
};
},
onSuccess: result => {
const data = result.message;
this.request = data.request;
this.response = data.response;
this.response_status_code = data.response_status_code;
if (data.success) {
this.errorMessage = '';
this.validated = true;
} else {
this.validated = false;
this.errorMessage =
'Endpoint should return a status between 200 and 300\nPlease check the endpoint and try again';
}
},
onError: e => {
console.error(e);
this.errorMessage = e.message;
}
};
},
activateWebhook() {
return {
url: 'press.api.client.run_doc_method',
makeParams() {
return {
dt: 'Press Webhook',
dn: this.webhook.name,
method: 'activate'
};
},
onSuccess(e) {
toast.success('Webhook activated successfully');
this.$emit('success');
},
onError(e) {
console.error(e);
this.errorMessage = e.message;
}
};
}
}
};
</script>