The impact panel's data. Every successful sign-in over IMAP, POP3,
ManageSieve or SMTP AUTH records, per account and per protocol, one
timestamp -- nothing else: no address, no IP, no client. It is written at
most once an hour per account and protocol, so a mail app polling every
minute costs a read per sign-in and a write an hour. A record that can't be
written is logged and the sign-in goes ahead.
Both switches serve it as a read-only property, recentLegacyUse, as
wouldClose serves the confirmation: a list of {accountId, name, protocol,
lastUsedAt} for sign-ins in the last 30 days, most recent first.
inbuxa:ProtocolPolicy lists every account; inbuxa:TenantProtocolPolicy
lists only its tenant's own (MT-1). Accounts since deleted are left out. It
is computed only when the property is asked for.
The recording sits where the tenant check already runs once the account is
known, which becomes admit_legacy_session: refuse if the account's tenant
has legacy protocols off, otherwise record. A refused sign-in is never
recorded.
The spec leaves the interface to the implementation; a property on each
switch keeps the panel's data behind the same permission as the switch
itself, with no new object.
Unit tests hold the 30-day window to acceptance test 11 (three days ago
listed, forty not), the hourly throttle and the keys. The e2e proves on a
running server that the admin's IMAP and submission sign-ins are listed
with their time, that a second sign-in within the hour isn't written again,
and that a tenant's list holds its own user and nobody outside the tenant.
All 70 checks pass.
187 lines
5.1 KiB
Rust
187 lines
5.1 KiB
Rust
/*
|
|
* SPDX-FileCopyrightText: 2026 Coffey Labs
|
|
*
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
//! `inbuxa:TenantProtocolPolicy/get` and `/set` under `urn:inbuxa:jmap`: one
|
|
//! tenant's legacy mail protocols switch (legacy-protocols spec, LP-9 to
|
|
//! LP-14). One per tenant; its id is the tenant's id.
|
|
//!
|
|
//! `tenantId`, `changedAt` and `changedBy` are the server's to say. A client
|
|
//! that sets them is answered with `invalidProperties`.
|
|
|
|
use crate::object::{AnyId, JmapObject, JmapObjectId};
|
|
use jmap_tools::{Element, Key, Property};
|
|
use std::{borrow::Cow, str::FromStr};
|
|
use types::id::Id;
|
|
|
|
#[derive(Debug, Clone, Default)]
|
|
pub struct TenantProtocolPolicy;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
pub enum TenantProtocolPolicyProperty {
|
|
Id,
|
|
/// Server-set: the tenant this is the switch of.
|
|
TenantId,
|
|
/// The switch: `enabled` or `disabled`.
|
|
LegacyProtocols,
|
|
ChangedAt,
|
|
ChangedBy,
|
|
/// Server-set: who signed in over a legacy protocol in the last 30
|
|
/// days, and when, for the impact panel (LP-15).
|
|
RecentLegacyUse,
|
|
}
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
|
pub enum TenantProtocolPolicyValue {
|
|
Id(Id),
|
|
}
|
|
|
|
impl Property for TenantProtocolPolicyProperty {
|
|
fn try_parse(_: Option<&Key<'_, Self>>, value: &str) -> Option<Self> {
|
|
TenantProtocolPolicyProperty::parse(value)
|
|
}
|
|
|
|
fn to_cow(&self) -> Cow<'static, str> {
|
|
match self {
|
|
TenantProtocolPolicyProperty::Id => "id",
|
|
TenantProtocolPolicyProperty::TenantId => "tenantId",
|
|
TenantProtocolPolicyProperty::LegacyProtocols => "legacyProtocols",
|
|
TenantProtocolPolicyProperty::ChangedAt => "changedAt",
|
|
TenantProtocolPolicyProperty::ChangedBy => "changedBy",
|
|
TenantProtocolPolicyProperty::RecentLegacyUse => "recentLegacyUse",
|
|
}
|
|
.into()
|
|
}
|
|
}
|
|
|
|
impl TenantProtocolPolicyProperty {
|
|
fn parse(value: &str) -> Option<Self> {
|
|
hashify::tiny_map!(value.as_bytes(),
|
|
b"id" => TenantProtocolPolicyProperty::Id,
|
|
b"tenantId" => TenantProtocolPolicyProperty::TenantId,
|
|
b"legacyProtocols" => TenantProtocolPolicyProperty::LegacyProtocols,
|
|
b"changedAt" => TenantProtocolPolicyProperty::ChangedAt,
|
|
b"changedBy" => TenantProtocolPolicyProperty::ChangedBy,
|
|
b"recentLegacyUse" => TenantProtocolPolicyProperty::RecentLegacyUse,
|
|
)
|
|
}
|
|
}
|
|
|
|
impl TenantProtocolPolicyProperty {
|
|
/// Whether this property is the server's to say. A client that sets one
|
|
/// is answered with `invalidProperties`.
|
|
pub fn is_server_set(&self) -> bool {
|
|
matches!(
|
|
self,
|
|
TenantProtocolPolicyProperty::TenantId
|
|
| TenantProtocolPolicyProperty::ChangedAt
|
|
| TenantProtocolPolicyProperty::ChangedBy
|
|
| TenantProtocolPolicyProperty::RecentLegacyUse
|
|
)
|
|
}
|
|
}
|
|
|
|
impl FromStr for TenantProtocolPolicyProperty {
|
|
type Err = ();
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
TenantProtocolPolicyProperty::parse(s).ok_or(())
|
|
}
|
|
}
|
|
|
|
impl Element for TenantProtocolPolicyValue {
|
|
type Property = TenantProtocolPolicyProperty;
|
|
|
|
fn try_parse<P>(key: &Key<'_, Self::Property>, value: &str) -> Option<Self> {
|
|
match key {
|
|
Key::Property(TenantProtocolPolicyProperty::Id) => {
|
|
Id::from_str(value).ok().map(TenantProtocolPolicyValue::Id)
|
|
}
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
fn to_cow(&self) -> Cow<'static, str> {
|
|
match self {
|
|
TenantProtocolPolicyValue::Id(id) => id.to_string().into(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl JmapObject for TenantProtocolPolicy {
|
|
type Property = TenantProtocolPolicyProperty;
|
|
|
|
type Element = TenantProtocolPolicyValue;
|
|
|
|
type Id = Id;
|
|
|
|
type Filter = ();
|
|
|
|
type Comparator = ();
|
|
|
|
type GetArguments = ();
|
|
|
|
type SetArguments<'de> = ();
|
|
|
|
type QueryArguments = ();
|
|
|
|
type CopyArguments = ();
|
|
|
|
type ParseArguments = ();
|
|
|
|
const ID_PROPERTY: Self::Property = TenantProtocolPolicyProperty::Id;
|
|
}
|
|
|
|
impl From<Id> for TenantProtocolPolicyValue {
|
|
fn from(id: Id) -> Self {
|
|
TenantProtocolPolicyValue::Id(id)
|
|
}
|
|
}
|
|
|
|
impl JmapObjectId for TenantProtocolPolicyValue {
|
|
fn as_id(&self) -> Option<Id> {
|
|
match self {
|
|
TenantProtocolPolicyValue::Id(id) => Some(*id),
|
|
}
|
|
}
|
|
|
|
fn as_any_id(&self) -> Option<AnyId> {
|
|
match self {
|
|
TenantProtocolPolicyValue::Id(id) => Some(AnyId::Id(*id)),
|
|
}
|
|
}
|
|
|
|
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 = TenantProtocolPolicyValue::Id(id);
|
|
true
|
|
} else {
|
|
false
|
|
}
|
|
}
|
|
}
|
|
|
|
impl JmapObjectId for TenantProtocolPolicyProperty {
|
|
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
|
|
}
|
|
}
|