diff --git a/src-ui/src/app/components/manage/settings/settings.component.ts b/src-ui/src/app/components/manage/settings/settings.component.ts
index 8efbb486e..818ad6b14 100644
--- a/src-ui/src/app/components/manage/settings/settings.component.ts
+++ b/src-ui/src/app/components/manage/settings/settings.component.ts
@@ -31,7 +31,7 @@ import { ViewportScroller } from '@angular/common'
import { TourService } from 'ngx-ui-tour-ng-bootstrap'
import { PaperlessMailAccount } from 'src/app/data/paperless-mail-account'
import { PaperlessMailRule } from 'src/app/data/paperless-mail-rule'
-import { MailAccountService as MailAccountService } from 'src/app/services/rest/mail-account.service'
+import { MailAccountService } from 'src/app/services/rest/mail-account.service'
import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { MailAccountEditDialogComponent } from '../../common/edit-dialog/mail-account-edit-dialog/mail-account-edit-dialog.component'
@@ -477,28 +477,30 @@ export class SettingsComponent
}
editMailAccount(account: PaperlessMailAccount) {
- console.log(account)
-
var modal = this.modalService.open(MailAccountEditDialogComponent, {
backdrop: 'static',
size: 'xl',
})
modal.componentInstance.dialogMode = 'edit'
modal.componentInstance.object = account
- // TODO: saving
- // modal.componentInstance.success
- // .pipe(
- // switchMap((newStoragePath) => {
- // return this.storagePathService
- // .listAll()
- // .pipe(map((storagePaths) => ({ newStoragePath, storagePaths })))
- // })
- // )
- // .pipe(takeUntil(this.unsubscribeNotifier))
- // .subscribe(({ newStoragePath, storagePaths }) => {
- // this.storagePaths = storagePaths.results
- // this.documentForm.get('storage_path').setValue(newStoragePath.id)
- // })
+ modal.componentInstance.success
+ .pipe(takeUntil(this.unsubscribeNotifier))
+ .subscribe({
+ next: (newMailAccount) => {
+ this.toastService.showInfo(
+ $localize`Saved account "${newMailAccount.name}".`
+ )
+ this.mailAccountService.listAll().subscribe((r) => {
+ this.mailAccounts = r.results
+ this.initialize()
+ })
+ },
+ error: (e) => {
+ this.toastService.showError(
+ $localize`Error saving account: ${e.toString()}.`
+ )
+ },
+ })
}
deleteMailAccount(account: PaperlessMailAccount) {
@@ -517,28 +519,31 @@ export class SettingsComponent
}
editMailRule(rule: PaperlessMailRule) {
- console.log(rule)
-
var modal = this.modalService.open(MailRuleEditDialogComponent, {
backdrop: 'static',
size: 'xl',
})
modal.componentInstance.dialogMode = 'edit'
modal.componentInstance.object = rule
- // TODO: saving
- // modal.componentInstance.success
- // .pipe(
- // switchMap((newStoragePath) => {
- // return this.storagePathService
- // .listAll()
- // .pipe(map((storagePaths) => ({ newStoragePath, storagePaths })))
- // })
- // )
- // .pipe(takeUntil(this.unsubscribeNotifier))
- // .subscribe(({ newStoragePath, storagePaths }) => {
- // this.storagePaths = storagePaths.results
- // this.documentForm.get('storage_path').setValue(newStoragePath.id)
- // })
+ modal.componentInstance.success
+ .pipe(takeUntil(this.unsubscribeNotifier))
+ .subscribe({
+ next: (newMailRule) => {
+ this.toastService.showInfo(
+ $localize`Saved rule "${newMailRule.name}".`
+ )
+ this.mailRuleService.listAll().subscribe((r) => {
+ this.mailRules = r.results
+
+ this.initialize()
+ })
+ },
+ error: (e) => {
+ this.toastService.showError(
+ $localize`Error saving rule: ${e.toString()}.`
+ )
+ },
+ })
}
deleteMailRule(rule: PaperlessMailRule) {
diff --git a/src-ui/src/app/data/paperless-mail-rule.ts b/src-ui/src/app/data/paperless-mail-rule.ts
index 31d734739..0f0e417f8 100644
--- a/src-ui/src/app/data/paperless-mail-rule.ts
+++ b/src-ui/src/app/data/paperless-mail-rule.ts
@@ -101,7 +101,7 @@ export interface PaperlessMailRule extends ObjectWithId {
order: number
- account: PaperlessMailAccount
+ account: number // PaperlessMailAccount.id
folder: string
@@ -123,11 +123,11 @@ export interface PaperlessMailRule extends ObjectWithId {
assign_title_from: MailMetadataTitleOption
- assign_tags?: PaperlessTag[]
+ assign_tags?: number[] // PaperlessTag.id
- assign_document_type?: PaperlessDocumentType
+ assign_document_type?: number // PaperlessDocumentType.id
assign_correspondent_from?: MailMetadataCorrespondentOption
- assign_correspondent?: PaperlessCorrespondent
+ assign_correspondent?: number // PaperlessCorrespondent.id
}
diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py
index 86e0f4a12..d2fa10af9 100644
--- a/src/documents/serialisers.py
+++ b/src/documents/serialisers.py
@@ -716,7 +716,17 @@ class MailAccountSerializer(serializers.ModelSerializer):
return mail_account
+class AccountField(serializers.PrimaryKeyRelatedField):
+ def get_queryset(self):
+ return MailAccount.objects.all()
+
+
class MailRuleSerializer(serializers.ModelSerializer):
+ account = AccountField(allow_null=True)
+ assign_correspondent = CorrespondentField(allow_null=True)
+ assign_tags = TagsField(many=True)
+ assign_document_type = DocumentTypeField(allow_null=True)
+
class Meta:
model = MailRule
depth = 1