8c607153c0
Server: E-3 invite_kind; E-12 link ?from=<admin name>, E-4 passes it into kvitt://invite; X-Kvitt-App-Version-Name stored in devices.app_version_name (migration 0003, schema 3); OpenAPI and examples follow. Phone: :core:model, :core:fakes, :data, features and :app updated together; goldens re-recorded for S-20 (version name) and new S-1/S-22 states. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TQd3pEP9UeN2uifbHknQ7B
83 lines
2.6 KiB
Rust
83 lines
2.6 KiB
Rust
//! Invite objects (SPEC §14.3.3, §14.3.4 E-3, E-12, E-13).
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use utoipa::ToSchema;
|
|
use uuid::Uuid;
|
|
|
|
use super::device::Device;
|
|
use super::user::User;
|
|
use super::{TimestampSchema, UuidSchema};
|
|
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum InviteKind {
|
|
AdminSetup,
|
|
Partner,
|
|
Device,
|
|
}
|
|
|
|
/// `code` and `link` only in the `POST /invites` response; `null` in `GET /invites`.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
|
pub struct Invite {
|
|
#[schema(value_type = UuidSchema)]
|
|
pub id: Uuid,
|
|
pub kind: InviteKind,
|
|
#[schema(value_type = Option<UuidSchema>, required = true)]
|
|
pub target_user_id: Option<Uuid>,
|
|
#[schema(required = true)]
|
|
pub code: Option<String>,
|
|
#[schema(required = true)]
|
|
pub link: Option<String>,
|
|
#[schema(value_type = TimestampSchema)]
|
|
pub created_at: String,
|
|
#[schema(value_type = TimestampSchema)]
|
|
pub expires_at: String,
|
|
}
|
|
|
|
/// E-13 `GET /invites`.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
|
pub struct InviteList {
|
|
pub invites: Vec<Invite>,
|
|
}
|
|
|
|
/// E-3 `POST /invites/accept`. `display_name` is required for `admin_setup` and `partner` invites
|
|
/// (`invalid_request` if missing) and ignored for `device`.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
|
pub struct AcceptInviteRequest {
|
|
pub code: String,
|
|
pub device_name: String,
|
|
#[serde(default, skip_serializing_if = "Option::is_none")]
|
|
#[schema(value_type = String)]
|
|
pub display_name: Option<String>,
|
|
}
|
|
|
|
/// E-3 response. The token is shown only here. `invite_kind` is the kind of the accepted invite, so the app shows
|
|
/// the profile step (S-2) only after a `partner` pairing (AC-2.10).
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
|
pub struct AcceptInviteResponse {
|
|
pub token: String,
|
|
pub invite_kind: InviteKind,
|
|
pub user: User,
|
|
pub device: Device,
|
|
pub household: Vec<User>,
|
|
}
|
|
|
|
/// The kinds an admin may create (E-12).
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum CreateInviteKind {
|
|
Partner,
|
|
Device,
|
|
}
|
|
|
|
/// E-12 `POST /invites`. `target_user_id` is optional and nullable (absent = null); required for `device`, must be
|
|
/// null for `partner`.
|
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
|
|
pub struct CreateInviteRequest {
|
|
#[schema(inline)]
|
|
pub kind: CreateInviteKind,
|
|
#[serde(default)]
|
|
#[schema(value_type = Option<UuidSchema>)]
|
|
pub target_user_id: Option<Uuid>,
|
|
}
|