Allow mail rules to not set title or owner
This commit is contained in:
parent
d37051fae1
commit
d8065e3f5a
@ -32,6 +32,7 @@
|
|||||||
<pngx-input-select i18n-title title="Assign document type" [items]="documentTypes" [allowNull]="true" formControlName="assign_document_type"></pngx-input-select>
|
<pngx-input-select i18n-title title="Assign document type" [items]="documentTypes" [allowNull]="true" formControlName="assign_document_type"></pngx-input-select>
|
||||||
<pngx-input-select i18n-title title="Assign correspondent from" [items]="metadataCorrespondentOptions" formControlName="assign_correspondent_from"></pngx-input-select>
|
<pngx-input-select i18n-title title="Assign correspondent from" [items]="metadataCorrespondentOptions" formControlName="assign_correspondent_from"></pngx-input-select>
|
||||||
<pngx-input-select *ngIf="showCorrespondentField" i18n-title title="Assign correspondent" [items]="correspondents" [allowNull]="true" formControlName="assign_correspondent"></pngx-input-select>
|
<pngx-input-select *ngIf="showCorrespondentField" i18n-title title="Assign correspondent" [items]="correspondents" [allowNull]="true" formControlName="assign_correspondent"></pngx-input-select>
|
||||||
|
<pngx-input-check i18n-title title="Assign owner from rule" formControlName="assign_owner_from_rule"></pngx-input-check>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -21,6 +21,7 @@ import {
|
|||||||
MailAction,
|
MailAction,
|
||||||
MailMetadataCorrespondentOption,
|
MailMetadataCorrespondentOption,
|
||||||
} from 'src/app/data/paperless-mail-rule'
|
} from 'src/app/data/paperless-mail-rule'
|
||||||
|
import { CheckComponent } from '../../input/check/check.component'
|
||||||
|
|
||||||
describe('MailRuleEditDialogComponent', () => {
|
describe('MailRuleEditDialogComponent', () => {
|
||||||
let component: MailRuleEditDialogComponent
|
let component: MailRuleEditDialogComponent
|
||||||
@ -41,6 +42,7 @@ describe('MailRuleEditDialogComponent', () => {
|
|||||||
NumberComponent,
|
NumberComponent,
|
||||||
TagsComponent,
|
TagsComponent,
|
||||||
SafeHtmlPipe,
|
SafeHtmlPipe,
|
||||||
|
CheckComponent,
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
NgbActiveModal,
|
NgbActiveModal,
|
||||||
|
@ -79,6 +79,10 @@ const METADATA_TITLE_OPTIONS = [
|
|||||||
id: MailMetadataTitleOption.FromFilename,
|
id: MailMetadataTitleOption.FromFilename,
|
||||||
name: $localize`Use attachment filename as title`,
|
name: $localize`Use attachment filename as title`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: MailMetadataTitleOption.None,
|
||||||
|
name: $localize`Do not assign title from this rule`,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const METADATA_CORRESPONDENT_OPTIONS = [
|
const METADATA_CORRESPONDENT_OPTIONS = [
|
||||||
@ -168,6 +172,7 @@ export class MailRuleEditDialogComponent extends EditDialogComponent<PaperlessMa
|
|||||||
MailMetadataCorrespondentOption.FromNothing
|
MailMetadataCorrespondentOption.FromNothing
|
||||||
),
|
),
|
||||||
assign_correspondent: new FormControl(null),
|
assign_correspondent: new FormControl(null),
|
||||||
|
assign_owner_from_rule: new FormControl(true),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ export enum MailAction {
|
|||||||
export enum MailMetadataTitleOption {
|
export enum MailMetadataTitleOption {
|
||||||
FromSubject = 1,
|
FromSubject = 1,
|
||||||
FromFilename = 2,
|
FromFilename = 2,
|
||||||
|
None = 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum MailMetadataCorrespondentOption {
|
export enum MailMetadataCorrespondentOption {
|
||||||
@ -67,4 +68,6 @@ export interface PaperlessMailRule extends ObjectWithPermissions {
|
|||||||
assign_correspondent_from?: MailMetadataCorrespondentOption
|
assign_correspondent_from?: MailMetadataCorrespondentOption
|
||||||
|
|
||||||
assign_correspondent?: number // PaperlessCorrespondent.id
|
assign_correspondent?: number // PaperlessCorrespondent.id
|
||||||
|
|
||||||
|
assign_owner_from_rule: boolean
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,7 @@ const mail_rules = [
|
|||||||
attachment_type: MailFilterAttachmentType.Everything,
|
attachment_type: MailFilterAttachmentType.Everything,
|
||||||
action: MailAction.MarkRead,
|
action: MailAction.MarkRead,
|
||||||
assign_title_from: MailMetadataTitleOption.FromSubject,
|
assign_title_from: MailMetadataTitleOption.FromSubject,
|
||||||
|
assign_owner_from_rule: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Mail Rule 2',
|
name: 'Mail Rule 2',
|
||||||
@ -44,6 +45,7 @@ const mail_rules = [
|
|||||||
attachment_type: MailFilterAttachmentType.Everything,
|
attachment_type: MailFilterAttachmentType.Everything,
|
||||||
action: MailAction.Delete,
|
action: MailAction.Delete,
|
||||||
assign_title_from: MailMetadataTitleOption.FromSubject,
|
assign_title_from: MailMetadataTitleOption.FromSubject,
|
||||||
|
assign_owner_from_rule: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Mail Rule 3',
|
name: 'Mail Rule 3',
|
||||||
@ -60,6 +62,7 @@ const mail_rules = [
|
|||||||
attachment_type: MailFilterAttachmentType.Everything,
|
attachment_type: MailFilterAttachmentType.Everything,
|
||||||
action: MailAction.Flag,
|
action: MailAction.Flag,
|
||||||
assign_title_from: MailMetadataTitleOption.FromSubject,
|
assign_title_from: MailMetadataTitleOption.FromSubject,
|
||||||
|
assign_owner_from_rule: false,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -128,10 +128,11 @@ class TestConsumptionTemplates(DirectoriesMixin, FileSystemAssertsMixin, TestCas
|
|||||||
filter_attachment_filename="file.pdf",
|
filter_attachment_filename="file.pdf",
|
||||||
maximum_age=30,
|
maximum_age=30,
|
||||||
action=MailRule.MailAction.MARK_READ,
|
action=MailRule.MailAction.MARK_READ,
|
||||||
assign_title_from=MailRule.TitleSource.FROM_SUBJECT,
|
assign_title_from=MailRule.TitleSource.NONE,
|
||||||
assign_correspondent_from=MailRule.CorrespondentSource.FROM_NOTHING,
|
assign_correspondent_from=MailRule.CorrespondentSource.FROM_NOTHING,
|
||||||
order=0,
|
order=0,
|
||||||
attachment_type=MailRule.AttachmentProcessing.ATTACHMENTS_ONLY,
|
attachment_type=MailRule.AttachmentProcessing.ATTACHMENTS_ONLY,
|
||||||
|
assign_owner_from_rule=False,
|
||||||
)
|
)
|
||||||
ct = ConsumptionTemplate.objects.create(
|
ct = ConsumptionTemplate.objects.create(
|
||||||
name="Template 1",
|
name="Template 1",
|
||||||
|
@ -436,6 +436,9 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
elif rule.assign_title_from == MailRule.TitleSource.FROM_FILENAME:
|
elif rule.assign_title_from == MailRule.TitleSource.FROM_FILENAME:
|
||||||
return os.path.splitext(os.path.basename(att.filename))[0]
|
return os.path.splitext(os.path.basename(att.filename))[0]
|
||||||
|
|
||||||
|
elif rule.assign_title_from == MailRule.TitleSource.NONE:
|
||||||
|
return None
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
"Unknown title selector.",
|
"Unknown title selector.",
|
||||||
@ -698,7 +701,9 @@ class MailAccountHandler(LoggingMixin):
|
|||||||
correspondent_id=correspondent.id if correspondent else None,
|
correspondent_id=correspondent.id if correspondent else None,
|
||||||
document_type_id=doc_type.id if doc_type else None,
|
document_type_id=doc_type.id if doc_type else None,
|
||||||
tag_ids=tag_ids,
|
tag_ids=tag_ids,
|
||||||
owner_id=rule.owner.id if rule.owner else None,
|
owner_id=rule.owner.id
|
||||||
|
if (rule.assign_owner_from_rule and rule.owner)
|
||||||
|
else None,
|
||||||
)
|
)
|
||||||
|
|
||||||
consume_task = consume_file.s(
|
consume_task = consume_file.s(
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
# Generated by Django 4.1.11 on 2023-09-18 18:50
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
("paperless_mail", "0021_alter_mailaccount_password"),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name="mailrule",
|
||||||
|
name="assign_owner_from_rule",
|
||||||
|
field=models.BooleanField(
|
||||||
|
default=True,
|
||||||
|
verbose_name="Assign the rule owner to documents",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name="mailrule",
|
||||||
|
name="assign_title_from",
|
||||||
|
field=models.PositiveIntegerField(
|
||||||
|
choices=[
|
||||||
|
(1, "Use subject as title"),
|
||||||
|
(2, "Use attachment filename as title"),
|
||||||
|
(3, "Do not assign title from rule"),
|
||||||
|
],
|
||||||
|
default=1,
|
||||||
|
verbose_name="assign title from",
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
@ -82,6 +82,7 @@ class MailRule(document_models.ModelWithOwner):
|
|||||||
class TitleSource(models.IntegerChoices):
|
class TitleSource(models.IntegerChoices):
|
||||||
FROM_SUBJECT = 1, _("Use subject as title")
|
FROM_SUBJECT = 1, _("Use subject as title")
|
||||||
FROM_FILENAME = 2, _("Use attachment filename as title")
|
FROM_FILENAME = 2, _("Use attachment filename as title")
|
||||||
|
NONE = 3, _("Do not assign title from rule")
|
||||||
|
|
||||||
class CorrespondentSource(models.IntegerChoices):
|
class CorrespondentSource(models.IntegerChoices):
|
||||||
FROM_NOTHING = 1, _("Do not assign a correspondent")
|
FROM_NOTHING = 1, _("Do not assign a correspondent")
|
||||||
@ -225,6 +226,11 @@ class MailRule(document_models.ModelWithOwner):
|
|||||||
verbose_name=_("assign this correspondent"),
|
verbose_name=_("assign this correspondent"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
assign_owner_from_rule = models.BooleanField(
|
||||||
|
_("Assign the rule owner to documents"),
|
||||||
|
default=True,
|
||||||
|
)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.account.name}.{self.name}"
|
return f"{self.account.name}.{self.name}"
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ class MailRuleSerializer(OwnedObjectSerializer):
|
|||||||
"assign_correspondent_from",
|
"assign_correspondent_from",
|
||||||
"assign_correspondent",
|
"assign_correspondent",
|
||||||
"assign_document_type",
|
"assign_document_type",
|
||||||
|
"assign_owner_from_rule",
|
||||||
"order",
|
"order",
|
||||||
"attachment_type",
|
"attachment_type",
|
||||||
"consumption_scope",
|
"consumption_scope",
|
||||||
|
@ -464,6 +464,7 @@ class TestAPIMailRules(DirectoriesMixin, APITestCase):
|
|||||||
"assign_tags": [tag.pk],
|
"assign_tags": [tag.pk],
|
||||||
"assign_correspondent": correspondent.pk,
|
"assign_correspondent": correspondent.pk,
|
||||||
"assign_document_type": document_type.pk,
|
"assign_document_type": document_type.pk,
|
||||||
|
"assign_owner_from_rule": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
response = self.client.post(
|
response = self.client.post(
|
||||||
@ -512,6 +513,10 @@ class TestAPIMailRules(DirectoriesMixin, APITestCase):
|
|||||||
rule1["assign_document_type"],
|
rule1["assign_document_type"],
|
||||||
)
|
)
|
||||||
self.assertEqual(returned_rule1["assign_tags"], rule1["assign_tags"])
|
self.assertEqual(returned_rule1["assign_tags"], rule1["assign_tags"])
|
||||||
|
self.assertEqual(
|
||||||
|
returned_rule1["assign_owner_from_rule"],
|
||||||
|
rule1["assign_owner_from_rule"],
|
||||||
|
)
|
||||||
|
|
||||||
def test_delete_mail_rule(self):
|
def test_delete_mail_rule(self):
|
||||||
"""
|
"""
|
||||||
|
@ -392,6 +392,11 @@ class TestMail(
|
|||||||
assign_title_from=MailRule.TitleSource.FROM_SUBJECT,
|
assign_title_from=MailRule.TitleSource.FROM_SUBJECT,
|
||||||
)
|
)
|
||||||
self.assertEqual(handler._get_title(message, att, rule), "the message title")
|
self.assertEqual(handler._get_title(message, att, rule), "the message title")
|
||||||
|
rule = MailRule(
|
||||||
|
name="b",
|
||||||
|
assign_title_from=MailRule.TitleSource.NONE,
|
||||||
|
)
|
||||||
|
self.assertEqual(handler._get_title(message, att, rule), None)
|
||||||
|
|
||||||
def test_handle_message(self):
|
def test_handle_message(self):
|
||||||
message = self.create_message(
|
message = self.create_message(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user