From 8af15d1b1010da12f69e704241e0a9d352e72435 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Fri, 20 Sep 2024 12:13:48 +0200 Subject: [PATCH] Fix compilation without enterprise feature --- crates/common/src/auth/access_token.rs | 6 ++++ .../directory/src/backend/internal/manage.rs | 35 +++++++++++++++++++ crates/directory/src/backend/internal/mod.rs | 6 ++++ crates/directory/src/core/principal.rs | 10 ++++++ crates/jmap/src/api/management/principal.rs | 18 ++++++++++ crates/jmap/src/api/management/queue.rs | 9 ++++- crates/jmap/src/api/management/report.rs | 9 ++++- crates/jmap/src/lib.rs | 12 +++++++ crates/main/Cargo.toml | 2 +- crates/managesieve/Cargo.toml | 1 + crates/managesieve/src/op/putscript.rs | 2 ++ tests/Cargo.toml | 2 +- tests/src/store/import_export.rs | 4 +-- 13 files changed, 110 insertions(+), 6 deletions(-) diff --git a/crates/common/src/auth/access_token.rs b/crates/common/src/auth/access_token.rs index e1e731c6..7ff882e4 100644 --- a/crates/common/src/auth/access_token.rs +++ b/crates/common/src/auth/access_token.rs @@ -60,6 +60,10 @@ impl Core { // Apply principal permissions let mut permissions = role_permissions.finalize(); + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + let mut tenant = None; #[cfg(feature = "enterprise")] if self.is_enterprise_edition() { @@ -89,6 +93,8 @@ impl Core { } } + // SPDX-SnippetEnd + Ok(AccessToken { primary_id: principal.id(), member_of: principal diff --git a/crates/directory/src/backend/internal/manage.rs b/crates/directory/src/backend/internal/manage.rs index abc97fa9..de717dce 100644 --- a/crates/directory/src/backend/internal/manage.rs +++ b/crates/directory/src/backend/internal/manage.rs @@ -161,6 +161,10 @@ impl ManageDirectory for Store { return Err(err_missing(PrincipalField::Name)); } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + // Validate tenant let mut valid_domains = AHashSet::new(); if let Some(tenant_id) = tenant_id { @@ -199,6 +203,8 @@ impl ManageDirectory for Store { } } + // SPDX-SnippetEnd + // Make sure new name is not taken if self .get_principal_id(&name) @@ -209,6 +215,10 @@ impl ManageDirectory for Store { return Err(err_exists(PrincipalField::Name, name)); } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + // Obtain tenant id, only if no default tenant is provided if let (Some(tenant_name), None) = (principal.take_str(PrincipalField::Tenant), tenant_id) { tenant_id = self @@ -262,6 +272,8 @@ impl ManageDirectory for Store { } } } + // SPDX-SnippetEnd + principal.set(PrincipalField::Name, name); // Map member names @@ -440,6 +452,10 @@ impl ManageDirectory for Store { .caused_by(trc::location!())? .ok_or_else(|| not_found(principal_id.to_string()))?; + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + // Make sure tenant has no data let mut batch = BatchBuilder::new(); match principal.typ { @@ -499,6 +515,7 @@ impl ManageDirectory for Store { _ => {} } + // SPDX-SnippetEnd // Unlink all principal's blobs self.blob_hash_unlink_account(principal_id) @@ -636,6 +653,10 @@ impl ManageDirectory for Store { ); } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + // Obtain used quota let mut used_quota = None; if tenant_id.is_none() @@ -652,6 +673,8 @@ impl ManageDirectory for Store { } } + // SPDX-SnippetEnd + // Allowed principal types for Member fields let allowed_member_types = match principal.inner.typ() { Type::Group => &[Type::Individual, Type::Group][..], @@ -731,6 +754,10 @@ impl ManageDirectory for Store { ); } } + + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL ( PrincipalAction::Set, PrincipalField::Tenant, @@ -789,6 +816,8 @@ impl ManageDirectory for Store { pinfo_name.clone(), ); } + + // SPDX-SnippetEnd ( PrincipalAction::Set, PrincipalField::Secrets, @@ -1614,6 +1643,10 @@ impl ManageDirectory for Store { } } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + // Map tenant name if let Some(tenant_id) = principal.take_int(PrincipalField::Tenant) { if fields.is_empty() || fields.contains(&PrincipalField::Tenant) { @@ -1627,6 +1660,8 @@ impl ManageDirectory for Store { } } + // SPDX-SnippetEnd + // Obtain used quota if matches!(principal.typ, Type::Individual | Type::Group | Type::Tenant) && (fields.is_empty() || fields.contains(&PrincipalField::UsedQuota)) diff --git a/crates/directory/src/backend/internal/mod.rs b/crates/directory/src/backend/internal/mod.rs index cc59fcb9..b78a29ba 100644 --- a/crates/directory/src/backend/internal/mod.rs +++ b/crates/directory/src/backend/internal/mod.rs @@ -92,12 +92,18 @@ impl Deserialize for Principal { } impl PrincipalInfo { + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + pub fn has_tenant_access(&self, tenant_id: Option) -> bool { tenant_id.map_or(true, |tenant_id| { self.tenant.map_or(false, |t| tenant_id == t) || (self.typ == Type::Tenant && self.id == tenant_id) }) } + + // SPDX-SnippetEnd } impl Serialize for PrincipalInfo { diff --git a/crates/directory/src/core/principal.rs b/crates/directory/src/core/principal.rs index f6dc00f6..89d67fce 100644 --- a/crates/directory/src/core/principal.rs +++ b/crates/directory/src/core/principal.rs @@ -47,9 +47,13 @@ impl Principal { self.get_int(PrincipalField::Quota).unwrap_or_default() } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL pub fn tenant(&self) -> Option { self.get_int(PrincipalField::Tenant).map(|v| v as u32) } + // SPDX-SnippetEnd pub fn description(&self) -> Option<&str> { self.get_str(PrincipalField::Description) @@ -1018,6 +1022,10 @@ impl Permission { ) } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + pub const fn is_tenant_admin_permission(&self) -> bool { matches!( self, @@ -1069,4 +1077,6 @@ impl Permission { | Permission::JmapPrincipalQuery ) || self.is_user_permission() } + + // SPDX-SnippetEnd } diff --git a/crates/jmap/src/api/management/principal.rs b/crates/jmap/src/api/management/principal.rs index f661e970..add50bfc 100644 --- a/crates/jmap/src/api/management/principal.rs +++ b/crates/jmap/src/api/management/principal.rs @@ -76,6 +76,10 @@ impl JMAP { Type::Resource | Type::Location | Type::Other => Permission::PrincipalCreate, })?; + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + #[cfg(feature = "enterprise")] if (matches!(principal.typ(), Type::Tenant) || principal.has_field(PrincipalField::Tenant)) @@ -84,6 +88,8 @@ impl JMAP { return Err(manage::enterprise()); } + // SPDX-SnippetEnd + // Make sure the current directory supports updates if matches!(principal.typ(), Type::Individual) { self.assert_supported_directory()?; @@ -161,6 +167,10 @@ impl JMAP { })?; } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + let mut tenant = access_token.tenant.map(|t| t.id); #[cfg(feature = "enterprise")] @@ -182,6 +192,8 @@ impl JMAP { return Err(manage::enterprise()); } + // SPDX-SnippetEnd + let mut principals = self .core .storage @@ -211,11 +223,17 @@ impl JMAP { .map(|p| (p.id, p.typ)) .ok_or_else(|| not_found(name.to_string()))?; + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + #[cfg(feature = "enterprise")] if matches!(typ, Type::Tenant) && !self.core.is_enterprise_edition() { return Err(manage::enterprise()); } + // SPDX-SnippetEnd + match *method { Method::GET => { // Validate the access token diff --git a/crates/jmap/src/api/management/queue.rs b/crates/jmap/src/api/management/queue.rs index da72ffaa..596abf65 100644 --- a/crates/jmap/src/api/management/queue.rs +++ b/crates/jmap/src/api/management/queue.rs @@ -115,8 +115,13 @@ impl JMAP { ) -> trc::Result { let params = UrlParams::new(req.uri().query()); + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + // Limit to tenant domains - let mut tenant_domains = None; + let mut tenant_domains: Option> = None; + #[cfg(feature = "enterprise")] if self.core.is_enterprise_edition() { if let Some(tenant) = access_token.tenant { tenant_domains = self @@ -144,6 +149,8 @@ impl JMAP { } } + // SPDX-SnippetEnd + match ( path.get(1).copied().unwrap_or_default(), path.get(2).copied().map(decode_path_element), diff --git a/crates/jmap/src/api/management/report.rs b/crates/jmap/src/api/management/report.rs index 594aa19e..daa91451 100644 --- a/crates/jmap/src/api/management/report.rs +++ b/crates/jmap/src/api/management/report.rs @@ -43,8 +43,13 @@ impl JMAP { path: Vec<&str>, access_token: &AccessToken, ) -> trc::Result { + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + // Limit to tenant domains - let mut tenant_domains = None; + let mut tenant_domains: Option> = None; + #[cfg(feature = "enterprise")] if self.core.is_enterprise_edition() { if let Some(tenant) = access_token.tenant { tenant_domains = self @@ -72,6 +77,8 @@ impl JMAP { } } + // SPDX-SnippetEnd + match ( path.get(1).copied().unwrap_or_default(), path.get(2).copied().map(decode_path_element), diff --git a/crates/jmap/src/lib.rs b/crates/jmap/src/lib.rs index 84d2b9ef..ad83a0bd 100644 --- a/crates/jmap/src/lib.rs +++ b/crates/jmap/src/lib.rs @@ -348,6 +348,10 @@ impl JMAP { { quotas.quota = principal.quota(); + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + #[cfg(feature = "enterprise")] if self.core.is_enterprise_edition() { if let Some(tenant_id) = principal.tenant() { @@ -368,6 +372,8 @@ impl JMAP { .into(); } } + + // SPDX-SnippetEnd } quotas @@ -399,6 +405,10 @@ impl JMAP { } } + // SPDX-SnippetBegin + // SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd + // SPDX-License-Identifier: LicenseRef-SEL + #[cfg(feature = "enterprise")] if self.core.is_enterprise_edition() { if let Some(tenant) = quotas.tenant.filter(|tenant| tenant.quota != 0) { @@ -413,6 +423,8 @@ impl JMAP { } } + // SPDX-SnippetEnd + Ok(()) } diff --git a/crates/main/Cargo.toml b/crates/main/Cargo.toml index a2473ec9..825e319d 100644 --- a/crates/main/Cargo.toml +++ b/crates/main/Cargo.toml @@ -44,4 +44,4 @@ rocks = ["store/rocks"] elastic = ["store/elastic"] s3 = ["store/s3"] redis = ["store/redis"] -enterprise = ["jmap/enterprise", "common/enterprise", "store/enterprise"] +enterprise = ["jmap/enterprise", "common/enterprise", "store/enterprise", "managesieve/enterprise"] diff --git a/crates/managesieve/Cargo.toml b/crates/managesieve/Cargo.toml index 88100fc8..a3694b17 100644 --- a/crates/managesieve/Cargo.toml +++ b/crates/managesieve/Cargo.toml @@ -29,3 +29,4 @@ bincode = "1.3.3" [features] test_mode = [] +enterprise = [] diff --git a/crates/managesieve/src/op/putscript.rs b/crates/managesieve/src/op/putscript.rs index d4ffbe2d..d980a768 100644 --- a/crates/managesieve/src/op/putscript.rs +++ b/crates/managesieve/src/op/putscript.rs @@ -167,6 +167,7 @@ impl Session { batch.add(DirectoryClass::UsedQuota(account_id), update_quota); // Update tenant quota + #[cfg(feature = "enterprise")] if self.jmap.core.is_enterprise_edition() { if let Some(tenant) = resource_token.tenant { batch.add(DirectoryClass::UsedQuota(tenant.id), update_quota); @@ -234,6 +235,7 @@ impl Session { ); // Update tenant quota + #[cfg(feature = "enterprise")] if self.jmap.core.is_enterprise_edition() { if let Some(tenant) = resource_token.tenant { batch.add(DirectoryClass::UsedQuota(tenant.id), script_size); diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 07a578f5..76f51478 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -28,7 +28,7 @@ pop3 = { path = "../crates/pop3", features = ["test_mode"] } smtp = { path = "../crates/smtp", features = ["test_mode"] } common = { path = "../crates/common", features = ["test_mode", "enterprise"] } trc = { path = "../crates/trc" } -managesieve = { path = "../crates/managesieve", features = ["test_mode"] } +managesieve = { path = "../crates/managesieve", features = ["test_mode", "enterprise"] } smtp-proto = { version = "0.1" } mail-send = { version = "0.4", default-features = false, features = ["cram-md5", "ring", "tls12"] } mail-auth = { version = "0.5", features = ["test"] } diff --git a/tests/src/store/import_export.rs b/tests/src/store/import_export.rs index b3af05ae..b90bdec8 100644 --- a/tests/src/store/import_export.rs +++ b/tests/src/store/import_export.rs @@ -5,7 +5,7 @@ */ use ahash::AHashSet; -use common::Core; +use common::{manager::backup::BackupParams, Core}; use jmap_proto::types::{collection::Collection, property::Property}; use store::{ rand, @@ -234,7 +234,7 @@ pub async fn test(db: Store) { // Export store println!("Exporting store..."); let temp_dir = TempDir::new("art_vandelay_tests", true); - core.backup(temp_dir.path.clone()).await; + core.backup(BackupParams::new(temp_dir.path.clone())).await; // Destroy store println!("Destroying store...");