Skip to main content

ironflow_api/entities/
approval_delegation.rs

1//! Approval delegation request and response DTOs.
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use uuid::Uuid;
6use validator::Validate;
7
8use ironflow_store::entities::ApprovalDelegation;
9
10/// Approval delegation response.
11#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
12#[derive(Debug, Serialize)]
13pub struct ApprovalDelegationResponse {
14    /// Delegation ID.
15    pub id: Uuid,
16    /// User handing over their approval power.
17    pub from_user_id: Uuid,
18    /// User receiving the approval power.
19    pub to_user_id: Uuid,
20    /// Start of the validity window (inclusive).
21    pub valid_from: DateTime<Utc>,
22    /// End of the validity window (exclusive).
23    pub valid_until: DateTime<Utc>,
24    /// Glob on the workflow name. `None` means every workflow.
25    pub workflow_filter: Option<String>,
26    /// When the delegation was created.
27    pub created_at: DateTime<Utc>,
28}
29
30impl From<ApprovalDelegation> for ApprovalDelegationResponse {
31    fn from(d: ApprovalDelegation) -> Self {
32        Self {
33            id: d.id,
34            from_user_id: d.from_user_id,
35            to_user_id: d.to_user_id,
36            valid_from: d.valid_from,
37            valid_until: d.valid_until,
38            workflow_filter: d.workflow_filter,
39            created_at: d.created_at,
40        }
41    }
42}
43
44/// Create delegation request body.
45///
46/// The delegator is always the authenticated caller: a delegation can only be
47/// granted by the person handing over their own approval power.
48#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))]
49#[derive(Debug, Deserialize, Validate)]
50pub struct CreateApprovalDelegationRequest {
51    /// User receiving the delegated approval power.
52    pub to_user_id: Uuid,
53    /// Start of the window. Defaults to now when omitted.
54    pub valid_from: Option<DateTime<Utc>>,
55    /// End of the window (exclusive).
56    pub valid_until: DateTime<Utc>,
57    /// Optional glob on the workflow name, e.g. `"deploy-*"`. `None` = all workflows.
58    pub workflow_filter: Option<String>,
59}
60
61/// Query parameters for listing delegations.
62///
63/// Both user filters are honoured for an admin only; a non-admin always sees
64/// exactly the delegations they granted or received. Pagination applies to
65/// everyone.
66#[cfg_attr(feature = "openapi", derive(utoipa::IntoParams, utoipa::ToSchema))]
67#[derive(Debug, Deserialize)]
68pub struct ListApprovalDelegationsQuery {
69    /// Only delegations granted by this user.
70    pub from_user_id: Option<Uuid>,
71    /// Only delegations received by this user.
72    pub to_user_id: Option<Uuid>,
73    /// Page number (1-based, defaults to 1).
74    pub page: Option<u32>,
75    /// Items per page (defaults to 20, max 100).
76    pub per_page: Option<u32>,
77}