Skip to main content

paperless_api/
workflow.rs

1//! Types related to paperless workflows.
2
3use std::collections::HashMap;
4
5use serde::Deserialize;
6use serde_repr::{Deserialize_repr, Serialize_repr};
7
8use paperless_api_macros::UpdateDto;
9
10/// A workflow
11#[derive(Debug, Clone, Deserialize, UpdateDto)]
12pub struct Workflow {
13    /// Unique identifier of the workflow.
14    #[dto(skip)]
15    pub id: crate::id::WorkflowId,
16
17    /// Whether the workflow is enabled.
18    pub enabled: bool,
19
20    /// Name of the workflow.
21    pub name: String,
22
23    /// Order of the workflow in the list.
24    pub order: Option<i32>,
25
26    /// Triggers that determine when the workflow is executed.
27    #[dto(skip)] // TODO
28    pub triggers: Vec<WorkflowTrigger>,
29
30    /// Actions that are executed when the workflow is triggered.
31    #[dto(skip)] // TODO
32    pub actions: Vec<WorkflowAction>,
33}
34
35/// A trigger that determines when a workflow is executed.
36#[derive(Debug, Clone, Deserialize)]
37pub struct WorkflowTrigger {
38    pub id: crate::id::WorkflowTriggerId,
39
40    #[serde(rename = "type")]
41    pub trigger_type: WorkflowTriggerType,
42}
43
44/// An action that can be executed when a workflow is triggered.
45#[derive(Debug, Clone, Deserialize)]
46pub struct WorkflowAction {
47    pub id: crate::id::WorkflowActionId,
48
49    #[serde(rename = "type")]
50    pub action_type: WorkflowActionType,
51
52    pub webhook: Option<WebhookAction>,
53}
54
55/// The type of trigger that determines when a workflow is executed.
56#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
57#[repr(u8)]
58pub enum WorkflowTriggerType {
59    ProcessingStarted = 1,
60    DocumentAdded = 2,
61    DocumentUpdated = 3,
62    Scheduled = 4,
63}
64
65/// The type of action that is executed when a workflow is triggered.
66#[derive(Debug, Clone, Serialize_repr, Deserialize_repr)]
67#[repr(u8)]
68pub enum WorkflowActionType {
69    Assign = 1,
70    Remove = 2,
71    Email = 3,
72    Webhook = 4,
73}
74
75/// A webhook action that can be executed when a workflow is triggered.
76#[derive(Debug, Clone, Deserialize)]
77pub struct WebhookAction {
78    pub id: crate::id::WebhookActionId,
79    pub url: String,
80
81    pub use_params: bool,
82    pub as_json: bool,
83    pub include_document: bool,
84
85    pub body: Option<String>,
86    pub headers: Option<HashMap<String, String>>,
87    pub params: Option<HashMap<String, String>>,
88}