FEATURE: granular webhooks (#23070)

Before this change, webhooks could be only configured for specific groups like for example, all topic events.

We would like to have more granular control like for example topic_created or topic_destroyed.

Test are failing because plugins changed has to be merged as well:
discourse/discourse-assign#498
discourse/discourse-solved#248
discourse/discourse-topic-voting#159
This commit is contained in:
Krzysztof Kotlarek
2023-10-09 14:35:31 +11:00
committed by GitHub
parent 1d3b2d6bd4
commit c468110929
23 changed files with 705 additions and 198 deletions

View File

@@ -1,7 +1,4 @@
<label class="hook-event">
<Input @type="checkbox" @checked={{this.enabled}} name="event-choice" />
{{this.name}}
<p>{{this.details}}</p>
{{this.details}}
</label>

View File

@@ -2,12 +2,10 @@ import Component from "@glimmer/component";
import I18n from "I18n";
export default class WebhookEventChooser extends Component {
get name() {
return I18n.t(`admin.web_hooks.${this.args.type.name}_event.name`);
}
get details() {
return I18n.t(`admin.web_hooks.${this.args.type.name}_event.details`);
return I18n.t(
`admin.web_hooks.${this.args.group}_event.${this.args.type.name}`
);
}
get eventTypeExists() {

View File

@@ -14,7 +14,7 @@ export default class AdminWebHooksEditController extends Controller {
@controller adminWebHooks;
@alias("adminWebHooks.eventTypes") eventTypes;
@alias("adminWebHooks.groupedEventTypes") groupedEventTypes;
@alias("adminWebHooks.defaultEventTypes") defaultEventTypes;
@alias("adminWebHooks.contentTypes") contentTypes;

View File

@@ -8,7 +8,7 @@ export default class AdminWebHooksRoute extends Route {
setupController(controller, model) {
controller.setProperties({
model,
eventTypes: model.extras.event_types,
groupedEventTypes: model.extras.grouped_event_types,
defaultEventTypes: model.extras.default_event_types,
contentTypes: model.extras.content_types,
deliveryStatuses: model.extras.delivery_statuses,

View File

@@ -43,8 +43,9 @@
<label class="subscription-choice">
<RadioButton
@name="subscription-choice"
@value="individual"
@selection={{this.model.webhookType}}
@onChange={{action (mut this.model.wildcard_web_hook) false}}
@value={{false}}
@selection={{this.model.wildcard_web_hook}}
/>
{{i18n "admin.web_hooks.individual_event"}}
<InputTip @validation={{this.eventTypeValidation}} />
@@ -52,20 +53,27 @@
{{#unless this.model.wildcard_web_hook}}
<div class="event-selector">
{{#each this.eventTypes as |type|}}
<WebhookEventChooser
@type={{type}}
@eventTypes={{this.model.web_hook_event_types}}
/>
{{/each}}
{{#each-in this.groupedEventTypes as |group eventTypes|}}
<div class="event-group">
{{i18n (concat "admin.web_hooks." group "_event.group_name")}}
{{#each eventTypes as |type|}}
<WebhookEventChooser
@type={{type}}
@group={{group}}
@eventTypes={{this.model.web_hook_event_types}}
/>
{{/each}}
</div>
{{/each-in}}
</div>
{{/unless}}
<label class="subscription-choice">
<RadioButton
@name="subscription-choice"
@value="wildcard"
@selection={{this.model.webhookType}}
@onChange={{action (mut this.model.wildcard_web_hook) true}}
@value={{true}}
@selection={{this.model.wildcard_web_hook}}
/>
{{i18n "admin.web_hooks.wildcard_event"}}
</label>