Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(ownership): type the non-user owner rollout gate (#7142)

Will Hutchinson9005b7da81fd
diff --git a/services/document_storage_service/src/config.rs b/services/document_storage_service/src/config.rs
index c9654965bb..a78c1f6ca5 100644
--- a/services/document_storage_service/src/config.rs
+++ b/services/document_storage_service/src/config.rs
@@ -1,10 +1,14 @@
use anyhow::Context;
pub use dictation::outbound::OpenaiApiKey;
+use entity_registry::NonUserOwners;
use macro_auth::InternalApiKey;
pub use macro_env::Environment;
use macro_env_var::{env_vars, maybe_env_vars};
use secretsmanager_client::LocalOrRemoteSecret;
+#[cfg(test)]
+mod test;
+
pub const DEFAULT_PRESIGNED_URL_EXPIRY_SECONDS: u64 = 900; // 15 minutes
/// Allow long recordings to play and seek without the signed URL expiring mid-session.
pub const CALL_RECORDING_PRESIGNED_URL_EXPIRY_SECONDS: u64 = 6 * 60 * 60;
@@ -57,6 +61,8 @@ env_vars! {
}
maybe_env_vars! {
+ /// Rollout gate for entities owned by bots or teams.
+ pub struct EnableNonUserOwners;
/// Optional name of the LiveKit agent to dispatch for call transcription.
pub struct LivekitTranscriptionAgentName;
/// Shared secret for internal call endpoints (e.g. transcript ingestion from the agent).
@@ -165,11 +171,8 @@ pub struct Config {
#[macro_config_default(true)]
pub legacy_comment_writes_enabled: bool,
- /// Lets a team-scoped bot with no acting user own the documents it
- /// creates. When `false` (the default) the document create routes answer
- /// those bots with 403, so every new document stays user-owned.
- #[macro_config_default(false)]
- pub enable_non_user_owners: bool,
+ /// Lets a team-scoped bot with no acting user own the documents it creates.
+ pub enable_non_user_owners: EnableNonUserOwners,
/// The number of seconds a signed document or call recording URL is valid for.
#[macro_config_default(DEFAULT_PRESIGNED_URL_EXPIRY_SECONDS)]
@@ -198,4 +201,20 @@ impl Config {
pub fn from_env() -> anyhow::Result<Self> {
macro_config::ConfigLoader::load::<Config>().context("failed to load config")
}
+
+ pub fn non_user_owners(&self) -> anyhow::Result<NonUserOwners> {
+ parse_non_user_owners(self.enable_non_user_owners.value())
+ }
+}
+
+fn parse_non_user_owners(value: Option<&str>) -> anyhow::Result<NonUserOwners> {
+ let enabled = value
+ .unwrap_or("false")
+ .parse::<bool>()
+ .context("ENABLE_NON_USER_OWNERS must be `true` or `false`")?;
+ Ok(if enabled {
+ NonUserOwners::Enabled
+ } else {
+ NonUserOwners::Disabled
+ })
}
diff --git a/services/document_storage_service/src/config/test.rs b/services/document_storage_service/src/config/test.rs
new file mode 100644
index 0000000000..793e68ad1d
--- /dev/null
+++ b/services/document_storage_service/src/config/test.rs
@@ -0,0 +1,31 @@
+use super::*;
+
+#[test]
+fn missing_or_false_gate_disables_non_user_owners() {
+ assert_eq!(
+ parse_non_user_owners(None).unwrap(),
+ NonUserOwners::Disabled
+ );
+ assert_eq!(
+ parse_non_user_owners(Some("false")).unwrap(),
+ NonUserOwners::Disabled
+ );
+}
+
+#[test]
+fn true_gate_enables_non_user_owners() {
+ assert_eq!(
+ parse_non_user_owners(Some("true")).unwrap(),
+ NonUserOwners::Enabled
+ );
+}
+
+#[test]
+fn invalid_gate_value_is_rejected() {
+ let error = parse_non_user_owners(Some("yes")).unwrap_err();
+
+ assert_eq!(
+ error.to_string(),
+ "ENABLE_NON_USER_OWNERS must be `true` or `false`"
+ );
+}
diff --git a/services/document_storage_service/src/main.rs b/services/document_storage_service/src/main.rs
index 4e268ccd54..20e6c4dafc 100644
--- a/services/document_storage_service/src/main.rs
+++ b/services/document_storage_service/src/main.rs
@@ -77,7 +77,7 @@ use email::{
outbound::EmailPgRepo,
};
use embedding::embedding_provider::openai::TextEmbedding3Small;
-use entity_registry::{NonUserOwners, OwnerGrantPolicy};
+use entity_registry::OwnerGrantPolicy;
use entity_registry_db_utils::OwnedEntityRegistrar;
use favorites::{
domain::{mutation_service::FavoritesMutationServiceImpl, service::FavoritesServiceImpl},
@@ -213,6 +213,7 @@ async fn run() -> anyhow::Result<()> {
.resolve_remote_secrets(env, &secretsmanager_client)
.await
.context("expected to be able to resolve config secrets")?;
+ let non_user_owners = config.non_user_owners()?;
tracing::trace!("initialized config");
@@ -1691,11 +1692,7 @@ async fn run() -> anyhow::Result<()> {
lexical_client: lexical_client.clone(),
creator: document_creator,
document_permission_jwt_secret: config.document_permission_jwt.as_ref().to_string(),
- non_user_owners: if config.enable_non_user_owners {
- NonUserOwners::Enabled
- } else {
- NonUserOwners::Disabled
- },
+ non_user_owners,
},
config: Arc::new(config),
channel_service: channels_service.clone(),