Coverage for src/paperap/models/workflow/model.py: 100%

1"""

2----------------------------------------------------------------------------

3

4 METADATA:

5

6 File: workflow.py

7 Project: paperap

8 Created: 2025-03-04

9 Version: 0.0.5

10 Author: Jess Mann

11 Email: jess@jmann.me

12 Copyright (c) 2025 Jess Mann

13

14----------------------------------------------------------------------------

15

16 LAST MODIFIED:

17

18 2025-03-04 By Jess Mann

19

20"""

21

22 from __future__ import annotations

23

24 from typing import Any, Optional, Self

25

26 from pydantic import Field

27

28 from paperap.models.abstract.model import StandardModel

29 from paperap.models.mixins.models import MatcherMixin

30 from paperap.models.workflow.queryset import WorkflowActionQuerySet, WorkflowQuerySet, WorkflowTriggerQuerySet

31

32

33 class WorkflowTrigger(StandardModel, MatcherMixin):

34 """

35 Represents a workflow trigger in Paperless-NgX.

36 """

37

38 sources: list[Any] = Field(default_factory=list) # TODO unknown subtype

39 type: int | None = None

40 filter_path: str | None = None

41 filter_filename: str | None = None

42 filter_mailrule: str | None = None

43 filter_has_tags: list[int] = Field(default_factory=list)

44 filter_has_correspondent: int | None = None

45 filter_has_document_type: int | None = None

46

47 class Meta(StandardModel.Meta):

48 queryset = WorkflowTriggerQuerySet

49

50

51 class WorkflowAction(StandardModel):

52 """

53 Represents a workflow action in Paperless-NgX.

54 """

55

56 type: str | None = None

57 assign_title: str | None = None

58 assign_tags: list[int] = Field(default_factory=list)

59 assign_correspondent: int | None = None

60 assign_document_type: int | None = None

61 assign_storage_path: int | None = None

62 assign_owner: int | None = None

63 assign_view_users: list[int] = Field(default_factory=list)

64 assign_view_groups: list[int] = Field(default_factory=list)

65 assign_change_users: list[int] = Field(default_factory=list)

66 assign_change_groups: list[int] = Field(default_factory=list)

67 assign_custom_fields: list[int] = Field(default_factory=list)

68 remove_all_tags: bool | None = None

69 remove_tags: list[int] = Field(default_factory=list)

70 remove_all_correspondents: bool | None = None

71 remove_correspondents: list[int] = Field(default_factory=list)

72 remove_all_document_types: bool | None = None

73 remove_document_types: list[int] = Field(default_factory=list)

74 remove_all_storage_paths: bool | None = None

75 remove_storage_paths: list[int] = Field(default_factory=list)

76 remove_custom_fields: list[int] = Field(default_factory=list)

77 remove_all_custom_fields: bool | None = None

78 remove_all_owners: bool | None = None

79 remove_owners: list[int] = Field(default_factory=list)

80 remove_all_permissions: bool | None = None

81 remove_view_users: list[int] = Field(default_factory=list)

82 remove_view_groups: list[int] = Field(default_factory=list)

83 remove_change_users: list[int] = Field(default_factory=list)

84 remove_change_groups: list[int] = Field(default_factory=list)

85

86 class Meta(StandardModel.Meta):

87 queryset = WorkflowActionQuerySet

88

89

90 class Workflow(StandardModel):

91 """

92 Represents a workflow in Paperless-NgX.

93 """

94

95 name: str

96 order: int | None = None

97 enabled: bool | None = None

98 triggers: list[dict[str, Any]] = Field(default_factory=list)

99 actions: list[dict[str, Any]] = Field(default_factory=list)

100

101 class Meta(StandardModel.Meta):

102 """

103 Metadata for the Workflow model.

104 """

105

106 queryset = WorkflowQuerySet