diff --git a/crates/common/src/storage/branding.rs b/crates/common/src/storage/branding.rs index bc8efd8e..65de0adc 100644 --- a/crates/common/src/storage/branding.rs +++ b/crates/common/src/storage/branding.rs @@ -17,7 +17,9 @@ use types::id::Id; impl Server { /// The logos that apply to a domain name, most specific first. An unknown /// name gets what a known domain with no logo of its own gets (BT-6). - pub async fn logos_for(&self, name: &str) -> trc::Result> { + /// With `dark`, each level offers its dark-mode logo before its own + /// logo (BT-27). + pub async fn logos_for(&self, name: &str, dark: bool) -> trc::Result> { let mut domain = None; for candidate in logo::lookup_names(name) { if let Some(found) = self.domain(&candidate).await? { @@ -26,35 +28,46 @@ impl Server { } } let registry = self.registry(); - let domain_logo = match &domain { + let (domain_logo, domain_dark) = match &domain { Some(domain) => registry .object::(Id::from(domain.id)) .await? - .and_then(|d| d.logo), - None => None, + .map_or((None, None), |d| (d.logo, d.logo_dark)), + None => (None, None), }; let tenant_id = domain.as_ref().and_then(|d| d.id_tenant); - let tenant_logo = match tenant_id { + let (tenant_logo, tenant_dark) = match tenant_id { Some(tenant_id) => registry .object::(Id::from(tenant_id)) .await? - .and_then(|t| t.logo), - None => None, + .map_or((None, None), |t| (t.logo, t.logo_dark)), + None => (None, None), }; - let server_logo = registry + let (server_logo, server_dark) = registry .object::(Id::singleton()) .await? - .and_then(|e| e.logo_url); - Ok(logo::chain([ - ( - Source::Domain(domain.as_ref().map_or(u32::MAX, |d| d.id)), - domain_logo.as_deref(), - ), - ( - Source::Tenant(tenant_id.unwrap_or(u32::MAX)), - tenant_logo.as_deref(), - ), - (Source::Server, server_logo.as_deref()), - ])) + .map_or((None, None), |e| (e.logo_url, e.logo_url_dark)); + let domain_source = Source::Domain(domain.as_ref().map_or(u32::MAX, |d| d.id)); + let tenant_source = Source::Tenant(tenant_id.unwrap_or(u32::MAX)); + Ok(logo::chain(logo::levels( + [ + ( + domain_source, + domain_logo.as_deref(), + domain_dark.as_deref(), + ), + ( + tenant_source, + tenant_logo.as_deref(), + tenant_dark.as_deref(), + ), + ( + Source::Server, + server_logo.as_deref(), + server_dark.as_deref(), + ), + ], + dark, + ))) } } diff --git a/crates/common/src/storage/mod.rs b/crates/common/src/storage/mod.rs index d2e18882..fee6ee80 100644 --- a/crates/common/src/storage/mod.rs +++ b/crates/common/src/storage/mod.rs @@ -101,13 +101,13 @@ impl Server { } // inbuxa: BT-9: the first logo mail can carry inline; none leaves the - // built-in INBUXA logo + // built-in INBUXA logo. Email is always light (BT-27) pub async fn logo_resource( &self, domain: &str, ) -> trc::Result>>> { Ok(self - .logos_for(domain) + .logos_for(domain, false) .await? .into_iter() .find(|logo| logo.is_embeddable()) diff --git a/crates/features/src/branding/logo.rs b/crates/features/src/branding/logo.rs index 1773357f..d0cb36d2 100644 --- a/crates/features/src/branding/logo.rs +++ b/crates/features/src/branding/logo.rs @@ -203,6 +203,23 @@ pub fn chain<'x>(candidates: impl IntoIterator)> logos } +/// The candidates `chain` takes, from each level's logo and dark-mode logo, +/// most specific level first. For a dark page a level offers its dark logo, +/// then its own; a light page never gets a dark logo (BT-27). +pub fn levels<'x>( + levels: impl IntoIterator, Option<&'x str>)>, + dark: bool, +) -> Vec<(Source, Option<&'x str>)> { + let mut out = Vec::new(); + for (source, light, dark_logo) in levels { + if dark { + out.push((source, dark_logo)); + } + out.push((source, light)); + } + out +} + /// The names to try for a domain name D (BT-1): D, then D without its /// leftmost label while at least two labels remain. Lowercase. pub fn lookup_names(name: &str) -> Vec { @@ -300,6 +317,44 @@ mod tests { assert!(logos[1].is_embeddable()); } + #[test] + fn dark_logos() { + let light = "https://example.org/light.png"; + let dark = "https://example.org/dark.png"; + let server_dark = "https://example.org/server-dark.png"; + let candidates = |d| { + chain(levels( + [ + (Source::Domain(1), Some(light), None), + (Source::Tenant(2), None, Some(dark)), + (Source::Server, None, Some(server_dark)), + ], + d, + )) + }; + // A level's own logo beats a less specific level's dark logo + assert_eq!(candidates(true)[0], Logo::Url(light.into())); + // A light page never gets a dark logo + assert_eq!(candidates(false), vec![Logo::Url(light.into())]); + // Within a level, the dark logo comes first; an unusable one falls + // back to the level's own + let logos = chain(levels( + [ + (Source::Domain(1), Some(light), Some(dark)), + (Source::Tenant(2), Some(light), Some("admin")), + ], + true, + )); + assert_eq!( + logos, + vec![ + Logo::Url(dark.into()), + Logo::Url(light.into()), + Logo::Url(light.into()) + ] + ); + } + #[test] fn names() { assert_eq!( diff --git a/crates/features/src/branding/writes.rs b/crates/features/src/branding/writes.rs index 081128e6..e537e602 100644 --- a/crates/features/src/branding/writes.rs +++ b/crates/features/src/branding/writes.rs @@ -15,9 +15,22 @@ use registry::schema::prelude::{Object, ObjectInner, Property}; /// The logo and template fields an object carries, with their checks. fn fields(inner: &ObjectInner) -> Vec<(Property, Option<&str>, fn(&str) -> Result<(), String>)> { match inner { - ObjectInner::Enterprise(o) => vec![(Property::LogoUrl, o.logo_url.as_deref(), logo::check)], - ObjectInner::Domain(o) => vec![(Property::Logo, o.logo.as_deref(), logo::check)], - ObjectInner::Tenant(o) => vec![(Property::Logo, o.logo.as_deref(), logo::check)], + ObjectInner::Enterprise(o) => vec![ + (Property::LogoUrl, o.logo_url.as_deref(), logo::check), + ( + Property::LogoUrlDark, + o.logo_url_dark.as_deref(), + logo::check, + ), + ], + ObjectInner::Domain(o) => vec![ + (Property::Logo, o.logo.as_deref(), logo::check), + (Property::LogoDark, o.logo_dark.as_deref(), logo::check), + ], + ObjectInner::Tenant(o) => vec![ + (Property::Logo, o.logo.as_deref(), logo::check), + (Property::LogoDark, o.logo_dark.as_deref(), logo::check), + ], ObjectInner::OAuthClient(o) => vec![(Property::Logo, o.logo.as_deref(), logo::check)], ObjectInner::CalendarAlarm(o) => { vec![(Property::Template, o.template.as_deref(), templates::check)] diff --git a/crates/http/src/branding.rs b/crates/http/src/branding.rs index 4d052dd5..1a784d6a 100644 --- a/crates/http/src/branding.rs +++ b/crates/http/src/branding.rs @@ -43,6 +43,15 @@ fn requested_domain(req: &HttpRequest) -> String { .unwrap_or_default() } +/// Whether `/logo` was asked for the dark-mode logo, with `?theme=dark` +/// (BT-27). Anything else is the light one. +fn wants_dark(req: &HttpRequest) -> bool { + req.uri().query().is_some_and(|query| { + http_proto::form_urlencoded::parse(query.as_bytes()) + .any(|(key, value)| key == "theme" && value.eq_ignore_ascii_case("dark")) + }) +} + /// Whether the browser is loading `/logo` as an image, as an `` does /// (BT-26). A link opened, a frame, a script or a client that doesn't say /// isn't. @@ -60,10 +69,11 @@ fn is_https(url: &str) -> bool { } /// `GET /logo`: the image, a redirect to a URL logo, or `404` when no -/// custom logo applies. The server never fetches a URL (BT-7). +/// custom logo applies. The server never fetches a URL (BT-7). With +/// `?theme=dark`, a dark-mode logo where one is set (BT-27). pub async fn logo(server: &Server, req: &HttpRequest) -> trc::Result { let response = match server - .logos_for(&requested_domain(req)) + .logos_for(&requested_domain(req), wants_dark(req)) .await? .into_iter() .find(|logo| !matches!(logo, Logo::Url(url) if !is_https(url))) diff --git a/crates/registry/src/inbuxa_tests.rs b/crates/registry/src/inbuxa_tests.rs index bc989b67..c12ddf98 100644 --- a/crates/registry/src/inbuxa_tests.rs +++ b/crates/registry/src/inbuxa_tests.rs @@ -12,8 +12,8 @@ use crate::{ enums::{MtaRouteType, OidcOpaqueTokens}, prelude::{ObjectImpl, ObjectInner, ObjectType}, structs::{ - Bootstrap, Directory, DirectoryBootstrap, MtaRoute, MtaRouteCommon, - MtaRouteInbuxaRelay, OidcDirectory, + Bootstrap, Directory, DirectoryBootstrap, Domain, Enterprise, MtaRoute, MtaRouteCommon, + MtaRouteInbuxaRelay, OidcDirectory, Tenant, }, }, types::{EnumImpl, map::Map}, @@ -148,3 +148,74 @@ fn inbuxa_relay_routes_are_stored_after_the_others() { ); assert_eq!(MtaRouteType::from_id(3), Some(MtaRouteType::InbuxaRelay)); } + +/// An object as it was stored at `version`, before its last field: today's +/// bytes with the version byte replaced and the unset field taken off the end. +fn without_last_field(object: &T, version: u8) -> Vec { + let mut unset = Vec::new(); + None::.pickle(&mut unset); + let mut bytes = object.to_pickled_vec(); + assert!(bytes.ends_with(&unset)); + bytes.truncate(bytes.len() - unset.len()); + bytes[0] = version; + bytes +} + +// branding BT-27: domains, tenants and the server-wide branding saved before +// the dark-mode logo read back without one; saved now, with it +#[test] +fn logos_saved_before_dark_mode_read_back_without_a_dark_logo() { + let domain = Domain { + name: "example.org".to_string(), + logo: Some("https://example.org/logo.png".to_string()), + allow_scim_provisioning: true, + ..Default::default() + }; + let tenant = Tenant { + name: "t".to_string(), + logo: Some("https://example.org/t.png".to_string()), + ..Default::default() + }; + let enterprise = Enterprise { + logo_url: Some("https://example.org/server.png".to_string()), + ..Default::default() + }; + assert_eq!( + read(ObjectType::Domain, &without_last_field(&domain, 1)), + ObjectInner::Domain(domain.clone()) + ); + assert_eq!( + read(ObjectType::Tenant, &without_last_field(&tenant, 0)), + ObjectInner::Tenant(tenant.clone()) + ); + assert_eq!( + read(ObjectType::Enterprise, &without_last_field(&enterprise, 0)), + ObjectInner::Enterprise(enterprise.clone()) + ); + + let dark = Some("https://example.org/dark.png".to_string()); + let domain = Domain { + logo_dark: dark.clone(), + ..domain + }; + let tenant = Tenant { + logo_dark: dark.clone(), + ..tenant + }; + let enterprise = Enterprise { + logo_url_dark: dark, + ..enterprise + }; + assert_eq!( + read(ObjectType::Domain, &domain.to_pickled_vec()), + ObjectInner::Domain(domain) + ); + assert_eq!( + read(ObjectType::Tenant, &tenant.to_pickled_vec()), + ObjectInner::Tenant(tenant) + ); + assert_eq!( + read(ObjectType::Enterprise, &enterprise.to_pickled_vec()), + ObjectInner::Enterprise(enterprise) + ); +} diff --git a/crates/registry/src/schema/properties.rs b/crates/registry/src/schema/properties.rs index 1b4b2f6c..5cedf7b0 100644 --- a/crates/registry/src/schema/properties.rs +++ b/crates/registry/src/schema/properties.rs @@ -993,6 +993,9 @@ pub enum Property { Relays = 939, // inbuxa: #397: a trace's kind, as x:Trace/query filters it Kind = 940, + // inbuxa: branding BT-27, dark-mode logos + LogoDark = 941, + LogoUrlDark = 942, RequireClientRegistration = 615, RequireScopes = 608, RequireTls = 525, diff --git a/crates/registry/src/schema/properties_impl.rs b/crates/registry/src/schema/properties_impl.rs index e349b25d..828df96e 100644 --- a/crates/registry/src/schema/properties_impl.rs +++ b/crates/registry/src/schema/properties_impl.rs @@ -868,6 +868,8 @@ impl EnumImpl for Property { b"locale" => Property::Locale, b"logo" => Property::Logo, b"logoUrl" => Property::LogoUrl, + b"logoDark" => Property::LogoDark, + b"logoUrlDark" => Property::LogoUrlDark, b"loiterBanPeriod" => Property::LoiterBanPeriod, b"loiterBanRate" => Property::LoiterBanRate, b"lossy" => Property::Lossy, @@ -1814,6 +1816,8 @@ impl EnumImpl for Property { Property::Locale => "locale", Property::Logo => "logo", Property::LogoUrl => "logoUrl", + Property::LogoDark => "logoDark", + Property::LogoUrlDark => "logoUrlDark", Property::LoiterBanPeriod => "loiterBanPeriod", Property::LoiterBanRate => "loiterBanRate", Property::Lossy => "lossy", @@ -3039,6 +3043,8 @@ impl EnumImpl for Property { 938 => Some(Property::IntrospectionClientSecret), 939 => Some(Property::Relays), 940 => Some(Property::Kind), + 941 => Some(Property::LogoDark), + 942 => Some(Property::LogoUrlDark), 615 => Some(Property::RequireClientRegistration), 608 => Some(Property::RequireScopes), 525 => Some(Property::RequireTls), @@ -3250,7 +3256,7 @@ impl EnumImpl for Property { } } - const COUNT: usize = 940; + const COUNT: usize = 943; } impl serde::Serialize for Property { diff --git a/crates/registry/src/schema/structs.rs b/crates/registry/src/schema/structs.rs index 779de1d3..c1592b13 100644 --- a/crates/registry/src/schema/structs.rs +++ b/crates/registry/src/schema/structs.rs @@ -2737,6 +2737,9 @@ pub struct Domain { pub description: Option, #[serde(rename = "logo")] pub logo: Option, + // inbuxa: branding BT-27 + #[serde(rename = "logoDark")] + pub logo_dark: Option, #[serde(rename = "certificateManagement")] pub certificate_management: CertificateManagement, #[serde(rename = "dkimManagement")] @@ -2880,6 +2883,9 @@ pub struct Enterprise { pub license_key: SecretKeyOptional, #[serde(rename = "logoUrl")] pub logo_url: Option, + // inbuxa: branding BT-27 + #[serde(rename = "logoUrlDark")] + pub logo_url_dark: Option, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -5868,6 +5874,9 @@ pub struct Tenant { pub created_at: UTCDateTime, #[serde(rename = "logo")] pub logo: Option, + // inbuxa: branding BT-27 + #[serde(rename = "logoDark")] + pub logo_dark: Option, #[serde(rename = "roles")] pub roles: Roles, #[serde(rename = "permissions")] diff --git a/crates/registry/src/schema/structs_impl.rs b/crates/registry/src/schema/structs_impl.rs index 8a9f19c5..3bc1f29a 100644 --- a/crates/registry/src/schema/structs_impl.rs +++ b/crates/registry/src/schema/structs_impl.rs @@ -19839,7 +19839,8 @@ impl RegistryJsonPropertyPatch for DnsServerYandexCloud { impl ObjectImpl for Domain { const FLAGS: u64 = OBJ_FILTER_TENANT | OBJ_SEQ_ID; - const VERSION: u8 = 1; + // inbuxa: 2: logoDark (branding BT-27) + const VERSION: u8 = 2; const OBJECT: ObjectType = ObjectType::Domain; fn validate(&self, errors: &mut Vec) -> bool { @@ -19868,6 +19869,11 @@ impl ObjectImpl for Domain { errors.push(ValidationError::required(Property::Logo)); } } + if let Some(value) = &self.logo_dark { + if value.is_empty() { + errors.push(ValidationError::required(Property::LogoDark)); + } + } let value = &self.certificate_management; value.validate(errors); let value = &self.dkim_management; @@ -19939,6 +19945,7 @@ impl Pickle for Domain { self.allow_relaying.pickle(out); self.report_address_uri.pickle(out); self.allow_scim_provisioning.pickle(out); + self.logo_dark.pickle(out); } fn unpickle(stream: &mut crate::pickle::PickledStream<'_>) -> Option { @@ -19961,6 +19968,10 @@ impl Pickle for Domain { if stream.version() >= 1 { this.allow_scim_provisioning = Pickle::unpickle(stream)?; } + // inbuxa: branding BT-27, stored from version 2 + if stream.version() >= 2 { + this.logo_dark = Pickle::unpickle(stream)?; + } Some(this) } } @@ -19974,6 +19985,7 @@ impl Default for Domain { created_at: Default::default(), description: Default::default(), logo: Default::default(), + logo_dark: Default::default(), certificate_management: Default::default(), dkim_management: Default::default(), dns_management: Default::default(), @@ -19997,6 +20009,7 @@ impl IntoValue for Domain { map.insert_unchecked(Property::CreatedAt, self.created_at.into_value()); map.insert_unchecked(Property::Description, self.description.into_value()); map.insert_unchecked(Property::Logo, self.logo.into_value()); + map.insert_unchecked(Property::LogoDark, self.logo_dark.into_value()); map.insert_unchecked( Property::CertificateManagement, self.certificate_management.into_value(), @@ -20040,6 +20053,7 @@ impl RegistryJsonPropertyPatch for Domain { Some(Property::CreatedAt) => pointer.assert_server_set(), Some(Property::Description) => self.description.patch(pointer, value), Some(Property::Logo) => self.logo.patch(pointer, value), + Some(Property::LogoDark) => self.logo_dark.patch(pointer, value), Some(Property::CertificateManagement) => { self.certificate_management.patch(pointer, value) } @@ -20923,7 +20937,8 @@ impl RegistryJsonPropertyPatch for EncryptionSettings { impl ObjectImpl for Enterprise { const FLAGS: u64 = OBJ_SINGLETON; - const VERSION: u8 = 0; + // inbuxa: 1: logoUrlDark (branding BT-27) + const VERSION: u8 = 1; const OBJECT: ObjectType = ObjectType::Enterprise; fn validate(&self, errors: &mut Vec) -> bool { @@ -20937,6 +20952,11 @@ impl ObjectImpl for Enterprise { errors.push(ValidationError::required(Property::LogoUrl)); } } + if let Some(value) = &self.logo_url_dark { + if value.is_empty() { + errors.push(ValidationError::required(Property::LogoUrlDark)); + } + } errors.len() == neb } @@ -20948,6 +20968,7 @@ impl Pickle for Enterprise { self.api_key.pickle(out); self.license_key.pickle(out); self.logo_url.pickle(out); + self.logo_url_dark.pickle(out); } fn unpickle(stream: &mut crate::pickle::PickledStream<'_>) -> Option { @@ -20955,6 +20976,10 @@ impl Pickle for Enterprise { this.api_key = Pickle::unpickle(stream)?; this.license_key = Pickle::unpickle(stream)?; this.logo_url = Pickle::unpickle(stream)?; + // inbuxa: branding BT-27, stored from version 1 + if stream.version() >= 1 { + this.logo_url_dark = Pickle::unpickle(stream)?; + } Some(this) } } @@ -20965,6 +20990,7 @@ impl Default for Enterprise { api_key: Default::default(), license_key: Default::default(), logo_url: Default::default(), + logo_url_dark: Default::default(), } } } @@ -20975,6 +21001,7 @@ impl IntoValue for Enterprise { map.insert_unchecked(Property::ApiKey, self.api_key.into_value()); map.insert_unchecked(Property::LicenseKey, self.license_key.into_value()); map.insert_unchecked(Property::LogoUrl, self.logo_url.into_value()); + map.insert_unchecked(Property::LogoUrlDark, self.logo_url_dark.into_value()); JmapValue::Object(map) } } @@ -20991,6 +21018,9 @@ impl RegistryJsonPropertyPatch for Enterprise { Some(Property::LogoUrl) => self .logo_url .patch(pointer.with_validators(&[StringValidator::Trim]), value), + Some(Property::LogoUrlDark) => self + .logo_url_dark + .patch(pointer.with_validators(&[StringValidator::Trim]), value), Some(Property::Type) => Ok(MaybeUnpatched::Unpatched { property: Property::Type, value, @@ -44475,7 +44505,8 @@ impl RegistryJsonPropertyPatch for TaskTlsReport { impl ObjectImpl for Tenant { const FLAGS: u64 = OBJ_SEQ_ID; - const VERSION: u8 = 0; + // inbuxa: 1: logoDark (branding BT-27) + const VERSION: u8 = 1; const OBJECT: ObjectType = ObjectType::Tenant; fn validate(&self, errors: &mut Vec) -> bool { @@ -44493,6 +44524,11 @@ impl ObjectImpl for Tenant { errors.push(ValidationError::required(Property::Logo)); } } + if let Some(value) = &self.logo_dark { + if value.is_empty() { + errors.push(ValidationError::required(Property::LogoDark)); + } + } let value = &self.roles; value.validate(errors); let value = &self.permissions; @@ -44514,6 +44550,7 @@ impl Pickle for Tenant { self.roles.pickle(out); self.permissions.pickle(out); self.quotas.pickle(out); + self.logo_dark.pickle(out); } fn unpickle(stream: &mut crate::pickle::PickledStream<'_>) -> Option { @@ -44524,6 +44561,10 @@ impl Pickle for Tenant { this.roles = Pickle::unpickle(stream)?; this.permissions = Pickle::unpickle(stream)?; this.quotas = Pickle::unpickle(stream)?; + // inbuxa: branding BT-27, stored from version 1 + if stream.version() >= 1 { + this.logo_dark = Pickle::unpickle(stream)?; + } Some(this) } } @@ -44534,6 +44575,7 @@ impl Default for Tenant { name: Default::default(), created_at: Default::default(), logo: Default::default(), + logo_dark: Default::default(), roles: Default::default(), permissions: Default::default(), quotas: Default::default(), @@ -44547,6 +44589,7 @@ impl IntoValue for Tenant { map.insert_unchecked(Property::Name, self.name.into_value()); map.insert_unchecked(Property::CreatedAt, self.created_at.into_value()); map.insert_unchecked(Property::Logo, self.logo.into_value()); + map.insert_unchecked(Property::LogoDark, self.logo_dark.into_value()); map.insert_unchecked(Property::Roles, self.roles.into_value()); map.insert_unchecked(Property::Permissions, self.permissions.into_value()); map.insert_unchecked(Property::Quotas, self.quotas.into_value()); @@ -44564,6 +44607,7 @@ impl RegistryJsonPropertyPatch for Tenant { Some(Property::Name) => self.name.patch(pointer, value), Some(Property::CreatedAt) => pointer.assert_server_set(), Some(Property::Logo) => self.logo.patch(pointer, value), + Some(Property::LogoDark) => self.logo_dark.patch(pointer, value), Some(Property::Roles) => self.roles.patch(pointer, value), Some(Property::Permissions) => self.permissions.patch(pointer, value), Some(Property::Quotas) => self.quotas.patch(pointer, value), diff --git a/docs/spec/features/branding-and-templates.md b/docs/spec/features/branding-and-templates.md index 46ea3ff5..6609a96d 100644 --- a/docs/spec/features/branding-and-templates.md +++ b/docs/spec/features/branding-and-templates.md @@ -268,14 +268,28 @@ Each requirement has an ID, and tests name the IDs they check. can't follow BT-5's redirect to another origin without that origin's CORS headers, and an image element can. +### Dark mode + +- **BT-27.** Each level can also hold a logo for dark mode: `logoDark` on a + domain and on a tenant, `logoUrlDark` on `x:Enterprise`. Each is written + and read like the level's own logo (BT-3, BT-4) and changed by whoever can + change that logo (BT-24, BT-25). `GET /logo?theme=dark` resolves BT-1's + chain with each level offering its dark logo first, then its own logo, so + a domain's own logo still beats the server-wide dark one. Without + `theme=dark`, or with any other value, a dark logo is never served. Email + always uses the light logo (BT-9). The built-in sign-in and RSVP pages ask + for `theme=dark` when they show dark, and inbuxa Admin and inbuxa Webmail + when their theme is dark. **Decision**: a separate field per level, as + requested in community t/304, rather than one value holding both images. + ## Interfaces - **Existing, unchanged:** `x:Enterprise/get` and `/set`, `x:CalendarAlarm/get` and `/set`, `x:CalendarScheduling/get` and `/set`, `x:Domain/get` and `/set`, their permissions; `GET /calendar/rsvp`; `POST /api/calendar/rsvp`. -- **New:** `GET /logo` (BT-5), with an optional `domain` parameter. The fork's - own pages already call it. +- **New:** `GET /logo` (BT-5), with optional `domain` and `theme` + (BT-27) parameters. The fork's own pages already call it. - **Per principal:** the applicable logo over JMAP, as proposed in multi-tenancy MT-22, following BT-1's full chain (BT-2). - **Errors:** RFC 8620 `invalidProperties`, naming the field, with the parse @@ -350,6 +364,10 @@ marked **(compat)** also runs against a copy of INBUXA's data. redirect, and their built-in logo when `/logo` is `404` (BT-26). 18. **(compat)** Every logo and template INBUXA holds reads back unchanged, and each renders or is served as it did before cutover (BT-4, BT-19). +19. With a dark logo on the server and a light one on a domain, + `/logo?theme=dark` for that domain serves the domain's logo; with a dark + logo on the domain too, it serves that one. `/logo` without the + parameter never serves a dark logo (BT-27). ## Open questions / to observe @@ -394,10 +412,10 @@ Built 2026-09-18 from this spec, clean-room, under the multi-tenancy hand-off brief's rules. The rules live in `crates/features` (`inbuxa-features`, module `branding`); the domain lookup in `crates/common/src/storage/branding.rs`; `/logo` and the RSVP page's answer in `crates/http/src/branding.rs`; upstream -files carry hooks marked `inbuxa:`. Acceptance tests 1 to 17 pass as +files carry hooks marked `inbuxa:`. Acceptance tests 1 to 17 and 19 pass as `tests/src/system/branding.rs`. -- **BT-1 to BT-26:** built. +- **BT-1 to BT-27:** built. - **ihasmail changes** belong to inbuxa-webmail and aren't part of this repository. - **Test 18 (compat)** is written as `branding_compat`, ignored, and unrun diff --git a/resources/html-templates/calendar-rsvp.html b/resources/html-templates/calendar-rsvp.html index 8983e794..c3b1d7b0 100644 --- a/resources/html-templates/calendar-rsvp.html +++ b/resources/html-templates/calendar-rsvp.html @@ -1054,7 +1054,13 @@ var wrap = $('logo-wrap'); function showDefault() { wrap.removeAttribute('data-loading'); } var target = apiUrl.replace(/\/api\/calendar\/rsvp$/, '') + '/logo'; - if (domain) target += '?domain=' + encodeURIComponent(domain); + var params = []; + if (domain) params.push('domain=' + encodeURIComponent(domain)); + // The dark-mode logo when this page shows dark (branding BT-27) + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + params.push('theme=dark'); + } + if (params.length) target += '?' + params.join('&'); // An image element, not fetch: it can follow /logo's redirect to // a URL logo on another origin (branding BT-26) var img = new Image(); diff --git a/resources/html-templates/calendar-rsvp.html.min b/resources/html-templates/calendar-rsvp.html.min index c3d66855..affbab6d 100644 --- a/resources/html-templates/calendar-rsvp.html.min +++ b/resources/html-templates/calendar-rsvp.html.min @@ -1 +1 @@ - Respond to invitation · inbuxa
\ No newline at end of file + Respond to invitation · inbuxa
\ No newline at end of file diff --git a/resources/html-templates/calendar-rsvp.html.min.gz b/resources/html-templates/calendar-rsvp.html.min.gz index 12c34790..b16ca2ee 100644 Binary files a/resources/html-templates/calendar-rsvp.html.min.gz and b/resources/html-templates/calendar-rsvp.html.min.gz differ diff --git a/resources/html-templates/login.html b/resources/html-templates/login.html index 971cbf2e..d4b000cb 100644 --- a/resources/html-templates/login.html +++ b/resources/html-templates/login.html @@ -423,13 +423,20 @@ (function loadCustomLogo() { var wrap = $('logo-wrap'); function showDefault() { wrap.removeAttribute('data-loading'); } - var target = '/logo'; + var params = []; if (loginHint) { var at = loginHint.lastIndexOf('@'); if (at !== -1 && at < loginHint.length - 1) { - target = '/logo?domain=' + encodeURIComponent(loginHint.slice(at + 1).toLowerCase()); + params.push('domain=' + encodeURIComponent(loginHint.slice(at + 1).toLowerCase())); } } + // The dark-mode logo when this page shows dark (branding BT-27) + var theme = document.documentElement.getAttribute('data-theme'); + if (theme === 'dark' || (theme !== 'light' && window.matchMedia && + window.matchMedia('(prefers-color-scheme: dark)').matches)) { + params.push('theme=dark'); + } + var target = '/logo' + (params.length ? '?' + params.join('&') : ''); // An image element, not fetch: it can follow /logo's redirect to // a URL logo on another origin (branding BT-26) var img = new Image(); diff --git a/resources/html-templates/login.html.min b/resources/html-templates/login.html.min index 4a4c4814..f0b78892 100644 --- a/resources/html-templates/login.html.min +++ b/resources/html-templates/login.html.min @@ -1 +1 @@ - Sign in · inbuxa

Sign in

Enter your credentials to continue

\ No newline at end of file + Sign in · inbuxa

Sign in

Enter your credentials to continue

\ No newline at end of file diff --git a/resources/html-templates/login.html.min.gz b/resources/html-templates/login.html.min.gz index d1764f06..a842b4b7 100644 Binary files a/resources/html-templates/login.html.min.gz and b/resources/html-templates/login.html.min.gz differ diff --git a/resources/schema/schema.json.gz b/resources/schema/schema.json.gz index 75638c39..1f6a80ca 100644 Binary files a/resources/schema/schema.json.gz and b/resources/schema/schema.json.gz differ diff --git a/resources/schema/schema.json.sha256 b/resources/schema/schema.json.sha256 index 321fdf85..fb5ebcb1 100644 --- a/resources/schema/schema.json.sha256 +++ b/resources/schema/schema.json.sha256 @@ -1 +1 @@ -tjQMv-CeqHA-z8bOAHPTnpuw9ATSrQAZELY4GRK0yDs \ No newline at end of file +k2_7GSOn4Rjf0ktF3x3Z88Z1u4hUHT_I_gEoRH_viO8 \ No newline at end of file diff --git a/tests/src/system/branding.rs b/tests/src/system/branding.rs index fe4f51ae..ebc3a89d 100644 --- a/tests/src/system/branding.rs +++ b/tests/src/system/branding.rs @@ -486,6 +486,72 @@ pub async fn test(test: &mut TestServer) { assert!(refused, "test 16: {object:?} {response:?}"); } + // Acceptance test 19: dark-mode logos (BT-27). The server-wide dark logo + // doesn't beat a domain's own logo; the domain's dark one does, and a + // light page never gets a dark logo. A tenant administrator sets its + // domain's dark logo, but not the server-wide one. + admin + .registry_update_object( + ObjectType::Enterprise, + Id::singleton(), + json!({"logoUrlDark": "https://logo.example.org/server-dark.png"}), + ) + .await; + let answer = get(&admin, "/logo?domain=t-brand.example.org&theme=dark", None).await; + assert_eq!( + answer.header("content-type"), + "image/png", + "test 19: the domain's own logo" + ); + let answer = get_image(&admin, "/logo?domain=nowhere.example.net&theme=dark").await; + assert_eq!(answer.status, StatusCode::FOUND, "test 19"); + assert_eq!( + answer.header("location"), + "https://logo.example.org/server-dark.png", + "test 19: the server-wide dark logo" + ); + admin + .registry_update_object_expect_err( + ObjectType::Domain, + t_domain, + json!({"logoDark": "javascript:alert(1)"}), + ) + .await + .assert_type(SetErrorType::InvalidProperties) + .assert_properties(&["logoDark"]); + t_admin + .registry_update_object( + ObjectType::Domain, + t_domain, + json!({"logoDark": data_url("image/gif", b"GIF89a\x01\0\x01\0\0\0\0;")}), + ) + .await; + let dark = get(&admin, "/logo?domain=t-brand.example.org&theme=dark", None).await; + assert_eq!(dark.header("content-type"), "image/gif", "test 19: dark"); + dark.assert_logo_headers("test 19"); + let light = get(&admin, "/logo?domain=t-brand.example.org", None).await; + assert_eq!(light.header("content-type"), "image/png", "test 19: light"); + let other = get(&admin, "/logo?domain=t-brand.example.org&theme=sepia", None).await; + assert_eq!(other.header("content-type"), "image/png", "test 19: other"); + let response = t_admin + .registry_update( + ObjectType::Enterprise, + [( + Id::singleton(), + json!({"logoUrlDark": "https://logo.example.org/x.png"}), + )], + ) + .await; + let refused = response + .0 + .pointer(&format!( + "/methodResponses/0/1/notUpdated/{}", + Id::singleton() + )) + .is_some() + || response.0.pointer("/methodResponses/0/0") == Some(&json!("error")); + assert!(refused, "test 19: {response:?}"); + // Acceptance test 17: the built-in pages load /logo through an image // element, which follows a redirect and falls back on error (BT-26) for page in [ @@ -495,11 +561,15 @@ pub async fn test(test: &mut TestServer) { assert!(page.contains("img.src = target"), "test 17"); assert!(page.contains("img.onerror = showDefault"), "test 17"); assert!(!page.contains("fetch(target"), "test 17"); + assert!(page.contains("params.push('theme=dark')"), "test 19"); } // Clean up admin - .registry_update_setting(Enterprise::default(), &[Property::LogoUrl]) + .registry_update_setting( + Enterprise::default(), + &[Property::LogoUrl, Property::LogoUrlDark], + ) .await; admin .registry_update_setting(CalendarAlarm::default(), &[Property::Template])