Files
inbuxa-server/crates/jmap-proto/src/object/inbuxa_deleted_account.rs
T
jcoffey-dev ecbdfd533b Undelete: deleted accounts are kept for their period, hold their addresses, and are restored or destroyed through inbuxa:DeletedAccount (UD-15 to UD-17a)
With archiveDeletedAccountsFor set, a destroyed account's record is kept in
the fork subspace with its id, its DestroyAccount task is due at the end of
the period, and its shares are suspended both ways. Its addresses can't be
taken by new accounts, aliases, lists or masks. inbuxa:DeletedAccount/get
lists kept accounts to server and tenant administrators; /set restores one
with a new password (same id, task cancelled, shares reinstated) or destroys
it now. The destroy task also clears undelete's own records.
Acceptance test 14; test 16 written as the ignored undelete_compat.
2026-09-18 21:35:48 -07:00

182 lines
4.6 KiB
Rust

/*
* SPDX-FileCopyrightText: 2026 Coffey Labs
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
//! `inbuxa:DeletedAccount/get` and `/set` under `urn:inbuxa:jmap`: deleted
//! accounts kept for their period, listed, restored or destroyed for good
//! (undelete spec, UD-15 to UD-17).
use crate::{
object::{AnyId, JmapObject, JmapObjectId},
types::date::UTCDate,
};
use jmap_tools::{Element, Key, Property};
use std::{borrow::Cow, str::FromStr};
use types::id::Id;
#[derive(Debug, Clone, Default)]
pub struct DeletedAccount;
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DeletedAccountProperty {
Id,
Name,
Addresses,
MemberTenantId,
DeletedAt,
KeptUntil,
Restore,
Password,
}
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum DeletedAccountValue {
Id(Id),
Date(UTCDate),
}
impl Property for DeletedAccountProperty {
fn try_parse(_: Option<&Key<'_, Self>>, value: &str) -> Option<Self> {
DeletedAccountProperty::parse(value)
}
fn to_cow(&self) -> Cow<'static, str> {
match self {
DeletedAccountProperty::Id => "id",
DeletedAccountProperty::Name => "name",
DeletedAccountProperty::Addresses => "addresses",
DeletedAccountProperty::MemberTenantId => "memberTenantId",
DeletedAccountProperty::DeletedAt => "deletedAt",
DeletedAccountProperty::KeptUntil => "keptUntil",
DeletedAccountProperty::Restore => "restore",
DeletedAccountProperty::Password => "password",
}
.into()
}
}
impl DeletedAccountProperty {
fn parse(value: &str) -> Option<Self> {
hashify::tiny_map!(value.as_bytes(),
b"id" => DeletedAccountProperty::Id,
b"name" => DeletedAccountProperty::Name,
b"addresses" => DeletedAccountProperty::Addresses,
b"memberTenantId" => DeletedAccountProperty::MemberTenantId,
b"deletedAt" => DeletedAccountProperty::DeletedAt,
b"keptUntil" => DeletedAccountProperty::KeptUntil,
b"restore" => DeletedAccountProperty::Restore,
b"password" => DeletedAccountProperty::Password,
)
}
}
impl FromStr for DeletedAccountProperty {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
DeletedAccountProperty::parse(s).ok_or(())
}
}
impl Element for DeletedAccountValue {
type Property = DeletedAccountProperty;
fn try_parse<P>(key: &Key<'_, Self::Property>, value: &str) -> Option<Self> {
match key {
Key::Property(DeletedAccountProperty::Id | DeletedAccountProperty::MemberTenantId) => {
Id::from_str(value).ok().map(DeletedAccountValue::Id)
}
Key::Property(DeletedAccountProperty::DeletedAt | DeletedAccountProperty::KeptUntil) => {
UTCDate::from_str(value).ok().map(DeletedAccountValue::Date)
}
_ => None,
}
}
fn to_cow(&self) -> Cow<'static, str> {
match self {
DeletedAccountValue::Id(id) => id.to_string().into(),
DeletedAccountValue::Date(date) => date.to_string().into(),
}
}
}
impl JmapObject for DeletedAccount {
type Property = DeletedAccountProperty;
type Element = DeletedAccountValue;
type Id = Id;
type Filter = ();
type Comparator = ();
type GetArguments = ();
type SetArguments<'de> = ();
type QueryArguments = ();
type CopyArguments = ();
type ParseArguments = ();
const ID_PROPERTY: Self::Property = DeletedAccountProperty::Id;
}
impl From<Id> for DeletedAccountValue {
fn from(id: Id) -> Self {
DeletedAccountValue::Id(id)
}
}
impl JmapObjectId for DeletedAccountValue {
fn as_id(&self) -> Option<Id> {
match self {
DeletedAccountValue::Id(id) => Some(*id),
_ => None,
}
}
fn as_any_id(&self) -> Option<AnyId> {
match self {
DeletedAccountValue::Id(id) => Some(AnyId::Id(*id)),
_ => None,
}
}
fn as_id_ref(&self) -> Option<&str> {
None
}
fn try_set_id(&mut self, new_id: AnyId) -> bool {
if let AnyId::Id(id) = new_id {
*self = DeletedAccountValue::Id(id);
true
} else {
false
}
}
}
impl JmapObjectId for DeletedAccountProperty {
fn as_id(&self) -> Option<Id> {
None
}
fn as_any_id(&self) -> Option<AnyId> {
None
}
fn as_id_ref(&self) -> Option<&str> {
None
}
fn try_set_id(&mut self, _: AnyId) -> bool {
false
}
}