mirror of
https://github.com/stalwartlabs/mail-server.git
synced 2024-11-13 04:39:02 +08:00
Add enterprise feature to directory crate (#783 ).
Some checks failed
trivy / Check (push) Failing after -9m10s
Some checks failed
trivy / Check (push) Failing after -9m10s
This commit is contained in:
parent
f3943f4a5f
commit
71c3c06c01
7 changed files with 22 additions and 7 deletions
|
@ -42,3 +42,4 @@ tokio = { version = "1.23", features = ["full"] }
|
|||
|
||||
[features]
|
||||
test_mode = []
|
||||
enterprise = []
|
||||
|
|
|
@ -186,13 +186,14 @@ impl ManageDirectory for Store {
|
|||
if name.is_empty() {
|
||||
return Err(err_missing(PrincipalField::Name));
|
||||
}
|
||||
let mut valid_domains: AHashSet<String> = AHashSet::new();
|
||||
|
||||
// SPDX-SnippetBegin
|
||||
// SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
|
||||
// SPDX-License-Identifier: LicenseRef-SEL
|
||||
|
||||
// Validate tenant
|
||||
let mut valid_domains = AHashSet::new();
|
||||
#[cfg(feature = "enterprise")]
|
||||
if let Some(tenant_id) = tenant_id {
|
||||
let tenant = self
|
||||
.query(QueryBy::Id(tenant_id), false)
|
||||
|
@ -246,6 +247,7 @@ impl ManageDirectory for Store {
|
|||
// SPDX-License-Identifier: LicenseRef-SEL
|
||||
|
||||
// Obtain tenant id, only if no default tenant is provided
|
||||
#[cfg(feature = "enterprise")]
|
||||
if let (Some(tenant_name), None) = (principal.take_str(PrincipalField::Tenant), tenant_id) {
|
||||
tenant_id = self
|
||||
.get_principal_info(&tenant_name)
|
||||
|
@ -258,6 +260,7 @@ impl ManageDirectory for Store {
|
|||
}
|
||||
|
||||
// Tenants must provide principal names including a valid domain
|
||||
#[cfg(feature = "enterprise")]
|
||||
if let Some(tenant_id) = tenant_id {
|
||||
if matches!(principal.typ, Type::Tenant) {
|
||||
return Err(error(
|
||||
|
@ -475,13 +478,14 @@ impl ManageDirectory for Store {
|
|||
.await
|
||||
.caused_by(trc::location!())?
|
||||
.ok_or_else(|| not_found(principal_id.to_string()))?;
|
||||
let mut batch = BatchBuilder::new();
|
||||
|
||||
// SPDX-SnippetBegin
|
||||
// SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
|
||||
// SPDX-License-Identifier: LicenseRef-SEL
|
||||
|
||||
// Make sure tenant has no data
|
||||
let mut batch = BatchBuilder::new();
|
||||
#[cfg(feature = "enterprise")]
|
||||
match principal.typ {
|
||||
Type::Individual | Type::Group => {
|
||||
// Update tenant quota
|
||||
|
@ -676,12 +680,14 @@ impl ManageDirectory for Store {
|
|||
);
|
||||
}
|
||||
|
||||
let mut used_quota: Option<i64> = None;
|
||||
|
||||
// SPDX-SnippetBegin
|
||||
// SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
|
||||
// SPDX-License-Identifier: LicenseRef-SEL
|
||||
|
||||
// Obtain used quota
|
||||
let mut used_quota = None;
|
||||
#[cfg(feature = "enterprise")]
|
||||
if tenant_id.is_none()
|
||||
&& changes
|
||||
.iter()
|
||||
|
@ -781,6 +787,7 @@ impl ManageDirectory for Store {
|
|||
// SPDX-SnippetBegin
|
||||
// SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
|
||||
// SPDX-License-Identifier: LicenseRef-SEL
|
||||
#[cfg(feature = "enterprise")]
|
||||
(
|
||||
PrincipalAction::Set,
|
||||
PrincipalField::Tenant,
|
||||
|
@ -1679,6 +1686,7 @@ impl ManageDirectory for Store {
|
|||
// SPDX-License-Identifier: LicenseRef-SEL
|
||||
|
||||
// Map tenant name
|
||||
#[cfg(feature = "enterprise")]
|
||||
if let Some(tenant_id) = principal.take_int(PrincipalField::Tenant) {
|
||||
if fields.is_empty() || fields.contains(&PrincipalField::Tenant) {
|
||||
if let Some(name) = self
|
||||
|
|
|
@ -98,6 +98,7 @@ impl Deserialize for Principal {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "enterprise")]
|
||||
impl PrincipalInfo {
|
||||
// SPDX-SnippetBegin
|
||||
// SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
|
||||
|
@ -113,6 +114,13 @@ impl PrincipalInfo {
|
|||
// SPDX-SnippetEnd
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "enterprise"))]
|
||||
impl PrincipalInfo {
|
||||
pub fn has_tenant_access(&self, _tenant_id: Option<u32>) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for PrincipalInfo {
|
||||
fn serialize(self) -> Vec<u8> {
|
||||
if let Some(tenant) = self.tenant {
|
||||
|
|
|
@ -44,4 +44,4 @@ rocks = ["store/rocks"]
|
|||
elastic = ["store/elastic"]
|
||||
s3 = ["store/s3"]
|
||||
redis = ["store/redis"]
|
||||
enterprise = ["jmap/enterprise", "common/enterprise", "store/enterprise", "managesieve/enterprise"]
|
||||
enterprise = ["jmap/enterprise", "common/enterprise", "store/enterprise", "managesieve/enterprise", "directory/enterprise"]
|
||||
|
|
|
@ -151,7 +151,6 @@ KillSignal=SIGINT
|
|||
Restart=on-failure
|
||||
RestartSec=5
|
||||
ExecStart=__PATH__/bin/stalwart-mail --config=__PATH__/etc/config.toml
|
||||
PermissionsStartOnly=true
|
||||
SyslogIdentifier=stalwart-mail
|
||||
User=stalwart-mail
|
||||
Group=stalwart-mail
|
||||
|
|
|
@ -12,7 +12,6 @@ KillSignal=SIGINT
|
|||
Restart=on-failure
|
||||
RestartSec=5
|
||||
ExecStart=__PATH__/bin/stalwart-mail --config=__PATH__/etc/config.toml
|
||||
PermissionsStartOnly=true
|
||||
SyslogIdentifier=stalwart-mail
|
||||
User=stalwart-mail
|
||||
Group=stalwart-mail
|
||||
|
|
|
@ -19,7 +19,7 @@ redis = ["store/redis"]
|
|||
[dev-dependencies]
|
||||
store = { path = "../crates/store", features = ["test_mode", "enterprise"] }
|
||||
nlp = { path = "../crates/nlp" }
|
||||
directory = { path = "../crates/directory", features = ["test_mode"] }
|
||||
directory = { path = "../crates/directory", features = ["test_mode", "enterprise"] }
|
||||
jmap = { path = "../crates/jmap", features = ["test_mode", "enterprise"] }
|
||||
jmap_proto = { path = "../crates/jmap-proto" }
|
||||
imap = { path = "../crates/imap", features = ["test_mode"] }
|
||||
|
|
Loading…
Reference in a new issue