From d254d209afb9caad4aabc9627266de86945f59e0 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Sun, 27 Jul 2025 12:10:16 +0200 Subject: [PATCH] Allow to send e-mails as group, while member of that group (closes #485) --- crates/common/src/auth/access_token.rs | 29 ++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/crates/common/src/auth/access_token.rs b/crates/common/src/auth/access_token.rs index 5204cd8a..6bd37c81 100644 --- a/crates/common/src/auth/access_token.rs +++ b/crates/common/src/auth/access_token.rs @@ -99,18 +99,35 @@ impl Server { // SPDX-SnippetEnd + // Build member of and e-mail addresses + let primary_id = principal.id(); + let member_of = principal + .member_of_mut() + .map(std::mem::take) + .unwrap_or_default(); + let mut emails = principal.emails; + for &group_id in &member_of { + if let Some(group) = self + .store() + .query(QueryParams::id(group_id).with_return_member_of(false)) + .await + .caused_by(trc::location!())? + { + if group.typ == Type::Group { + emails.extend(group.emails); + } + } + } + // Build access token let mut access_token = AccessToken { - primary_id: principal.id(), - member_of: principal - .member_of_mut() - .map(std::mem::take) - .unwrap_or_default(), + primary_id, + member_of, access_to: VecMap::new(), tenant, name: principal.name, description: principal.description, - emails: principal.emails, + emails, quota: principal.quota.unwrap_or_default(), locale: principal.data.iter().find_map(|data| { if let PrincipalData::Locale(v) = data {