mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Use discreet model for email / webhook
This commit is contained in:
@@ -323,27 +323,29 @@
|
||||
</div>
|
||||
}
|
||||
@case (WorkflowActionType.Email) {
|
||||
<div class="row">
|
||||
<div class="row" [formGroup]="formGroup.get('email')">
|
||||
<input type="hidden" formControlName="id" />
|
||||
<div class="col">
|
||||
<pngx-input-text i18n-title title="Email subject" formControlName="email_subject" [error]="error?.actions?.[i]?.email_subject"></pngx-input-text>
|
||||
<pngx-input-textarea i18n-title title="Email body" formControlName="email_body" [error]="error?.actions?.[i]?.email_body"></pngx-input-textarea>
|
||||
<pngx-input-text i18n-title title="Email recipients" formControlName="email_to" [error]="error?.actions?.[i]?.email_to"></pngx-input-text>
|
||||
<pngx-input-switch i18n-title title="Attach document" formControlName="email_include_document"></pngx-input-switch>
|
||||
<pngx-input-text i18n-title title="Email subject" formControlName="subject" [error]="error?.actions?.[i]?.email?.subject"></pngx-input-text>
|
||||
<pngx-input-textarea i18n-title title="Email body" formControlName="body" [error]="error?.actions?.[i]?.email?.body"></pngx-input-textarea>
|
||||
<pngx-input-text i18n-title title="Email recipients" formControlName="to" [error]="error?.actions?.[i]?.email?.to"></pngx-input-text>
|
||||
<pngx-input-switch i18n-title title="Attach document" formControlName="include_document"></pngx-input-switch>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
@case (WorkflowActionType.Webhook) {
|
||||
<div class="row">
|
||||
<div class="row" [formGroup]="formGroup.get('webhook')">
|
||||
<input type="hidden" formControlName="id" />
|
||||
<div class="col">
|
||||
<pngx-input-text i18n-title title="Webhook url" formControlName="webhook_url" [error]="error?.actions?.[i]?.webhook_url"></pngx-input-text>
|
||||
<pngx-input-switch i18n-title title="Use parameters for webhook body" formControlName="webhook_use_params"></pngx-input-switch>
|
||||
@if (formGroup.get('webhook_use_params').value) {
|
||||
<pngx-input-entries i18n-title title="Webhook params" formControlName="webhook_params" [error]="error?.actions?.[i]?.webhook_params"></pngx-input-entries>
|
||||
<pngx-input-text i18n-title title="Webhook url" formControlName="url" [error]="error?.actions?.[i]?.url"></pngx-input-text>
|
||||
<pngx-input-switch i18n-title title="Use parameters for webhook body" formControlName="use_params"></pngx-input-switch>
|
||||
@if (formGroup.get('webhook').value['use_params']) {
|
||||
<pngx-input-entries i18n-title title="Webhook params" formControlName="params" [error]="error?.actions?.[i]?.params"></pngx-input-entries>
|
||||
} @else {
|
||||
<pngx-input-textarea i18n-title title="Webhook body" formControlName="webhook_body" [error]="error?.actions?.[i]?.webhook_body"></pngx-input-textarea>
|
||||
<pngx-input-textarea i18n-title title="Webhook body" formControlName="body" [error]="error?.actions?.[i]?.body"></pngx-input-textarea>
|
||||
}
|
||||
<pngx-input-entries i18n-title title="Webhook headers" formControlName="webhook_headers" [error]="error?.actions?.[i]?.webhook_headers"></pngx-input-entries>
|
||||
<pngx-input-switch i18n-title title="Include document" formControlName="webhook_include_document"></pngx-input-switch>
|
||||
<pngx-input-entries i18n-title title="Webhook headers" formControlName="headers" [error]="error?.actions?.[i]?.headers"></pngx-input-entries>
|
||||
<pngx-input-switch i18n-title title="Include document" formControlName="include_document"></pngx-input-switch>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
@@ -347,4 +347,15 @@ describe('WorkflowEditDialogComponent', () => {
|
||||
component.actionFields.at(0).get('remove_change_groups').disabled
|
||||
).toBeFalsy()
|
||||
})
|
||||
|
||||
it('should prune empty nested objects on save', () => {
|
||||
component.object = workflow
|
||||
component.addTrigger()
|
||||
component.addAction()
|
||||
expect(component.objectForm.get('actions').value[0].email).not.toBeNull()
|
||||
expect(component.objectForm.get('actions').value[0].webhook).not.toBeNull()
|
||||
component.save()
|
||||
expect(component.objectForm.get('actions').value[0].email).toBeNull()
|
||||
expect(component.objectForm.get('actions').value[0].webhook).toBeNull()
|
||||
})
|
||||
})
|
||||
|
@@ -410,18 +410,22 @@ export class WorkflowEditDialogComponent
|
||||
remove_all_custom_fields: new FormControl(
|
||||
action.remove_all_custom_fields
|
||||
),
|
||||
email_subject: new FormControl(action.email_subject),
|
||||
email_body: new FormControl(action.email_body),
|
||||
email_to: new FormControl(action.email_to),
|
||||
email_include_document: new FormControl(action.email_include_document),
|
||||
webhook_url: new FormControl(action.webhook_url),
|
||||
webhook_use_params: new FormControl(action.webhook_use_params),
|
||||
webhook_params: new FormControl(action.webhook_params),
|
||||
webhook_body: new FormControl(action.webhook_body),
|
||||
webhook_headers: new FormControl(action.webhook_headers),
|
||||
webhook_include_document: new FormControl(
|
||||
action.webhook_include_document
|
||||
),
|
||||
email: new FormGroup({
|
||||
id: new FormControl(action.email?.id),
|
||||
subject: new FormControl(action.email?.subject),
|
||||
body: new FormControl(action.email?.body),
|
||||
to: new FormControl(action.email?.to),
|
||||
include_document: new FormControl(!!action.email?.include_document),
|
||||
}),
|
||||
webhook: new FormGroup({
|
||||
id: new FormControl(action.webhook?.id),
|
||||
url: new FormControl(action.webhook?.url),
|
||||
use_params: new FormControl(action.webhook?.use_params),
|
||||
params: new FormControl(action.webhook?.params),
|
||||
body: new FormControl(action.webhook?.body),
|
||||
headers: new FormControl(action.webhook?.headers),
|
||||
include_document: new FormControl(!!action.webhook?.include_document),
|
||||
}),
|
||||
}),
|
||||
{ emitEvent }
|
||||
)
|
||||
@@ -523,16 +527,22 @@ export class WorkflowEditDialogComponent
|
||||
remove_all_permissions: false,
|
||||
remove_custom_fields: [],
|
||||
remove_all_custom_fields: false,
|
||||
email_subject: null,
|
||||
email_body: null,
|
||||
email_to: null,
|
||||
email_include_document: false,
|
||||
webhook_url: null,
|
||||
webhook_use_params: true,
|
||||
webhook_params: null,
|
||||
webhook_body: null,
|
||||
webhook_headers: null,
|
||||
webhook_include_document: false,
|
||||
email: {
|
||||
id: null,
|
||||
subject: null,
|
||||
body: null,
|
||||
to: null,
|
||||
include_document: false,
|
||||
},
|
||||
webhook: {
|
||||
id: null,
|
||||
url: null,
|
||||
use_params: true,
|
||||
params: null,
|
||||
body: null,
|
||||
headers: null,
|
||||
include_document: false,
|
||||
},
|
||||
}
|
||||
this.object.actions.push(action)
|
||||
this.createActionField(action)
|
||||
@@ -563,4 +573,18 @@ export class WorkflowEditDialogComponent
|
||||
c.get('id').setValue(null, { emitEvent: false })
|
||||
)
|
||||
}
|
||||
|
||||
save(): void {
|
||||
this.objectForm
|
||||
.get('actions')
|
||||
.value.forEach((action: WorkflowAction, i) => {
|
||||
if (action.type !== WorkflowActionType.Webhook) {
|
||||
action.webhook = null
|
||||
}
|
||||
if (action.type !== WorkflowActionType.Email) {
|
||||
action.email = null
|
||||
}
|
||||
})
|
||||
super.save()
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,31 @@ export enum WorkflowActionType {
|
||||
Email = 3,
|
||||
Webhook = 4,
|
||||
}
|
||||
|
||||
export interface WorkflowActionEmail extends ObjectWithId {
|
||||
subject?: string
|
||||
|
||||
body?: string
|
||||
|
||||
to?: string
|
||||
|
||||
include_document?: boolean
|
||||
}
|
||||
|
||||
export interface WorkflowActionWebhook extends ObjectWithId {
|
||||
url?: string
|
||||
|
||||
use_params?: boolean
|
||||
|
||||
params?: object
|
||||
|
||||
body?: string
|
||||
|
||||
headers?: object
|
||||
|
||||
include_document?: boolean
|
||||
}
|
||||
|
||||
export interface WorkflowAction extends ObjectWithId {
|
||||
type: WorkflowActionType
|
||||
|
||||
@@ -65,23 +90,7 @@ export interface WorkflowAction extends ObjectWithId {
|
||||
|
||||
remove_all_custom_fields?: boolean
|
||||
|
||||
email_subject?: string
|
||||
email?: WorkflowActionEmail
|
||||
|
||||
email_body?: string
|
||||
|
||||
email_to?: string
|
||||
|
||||
email_include_document?: boolean
|
||||
|
||||
webhook_url?: string
|
||||
|
||||
webhook_use_params?: boolean
|
||||
|
||||
webhook_params?: object
|
||||
|
||||
webhook_body?: string
|
||||
|
||||
webhook_headers?: object
|
||||
|
||||
webhook_include_document?: boolean
|
||||
webhook?: WorkflowActionWebhook
|
||||
}
|
||||
|
Reference in New Issue
Block a user