Skip to content
Merged
11 changes: 4 additions & 7 deletions server/src/api/apps/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub async fn list_apps(
.into_response();
};

match repo.list_by_tenant(&tenant.to_object_id()).await {
match repo.list_by_tenant(&tenant).await {
Ok(apps) => {
let details: Vec<AppDetail> = apps.iter().map(to_detail).collect();
Json(json!({ "apps": details })).into_response()
Expand Down Expand Up @@ -189,10 +189,7 @@ pub async fn delete_app(
.into_response();
};

match repo
.delete_app(&tenant.to_object_id(), &app_id.to_object_id())
.await
{
match repo.delete_app(&tenant, &app_id).await {
Ok(true) => StatusCode::NO_CONTENT.into_response(),
Ok(false) => (
StatusCode::NOT_FOUND,
Expand Down Expand Up @@ -240,7 +237,7 @@ pub async fn serve_aasa(State(state): State<Arc<AppState>>, headers: HeaderMap)
};

let Some(ios_app) = repo
.find_by_tenant_platform(tenant_id.as_object_id(), "ios")
.find_by_tenant_platform(&tenant_id, "ios")
.await
.ok()
.flatten()
Expand Down Expand Up @@ -309,7 +306,7 @@ pub async fn serve_assetlinks(State(state): State<Arc<AppState>>, headers: Heade
};

let Some(android_app) = repo
.find_by_tenant_platform(tenant_id.as_object_id(), "android")
.find_by_tenant_platform(&tenant_id, "android")
.await
.ok()
.flatten()
Expand Down
7 changes: 2 additions & 5 deletions server/src/api/auth/publishable_keys/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ pub async fn list_sdk_keys(
.into_response();
};

match sdk_keys_repo.list_by_tenant(&tenant.to_object_id()).await {
match sdk_keys_repo.list_by_tenant(&tenant).await {
Ok(docs) => {
let keys: Vec<SdkKeyDetail> = docs
.iter()
Expand Down Expand Up @@ -189,10 +189,7 @@ pub async fn revoke_sdk_key(
.into_response();
};

match sdk_keys_repo
.revoke(&tenant.to_object_id(), &key_id.to_object_id())
.await
{
match sdk_keys_repo.revoke(&tenant, &key_id).await {
Ok(true) => StatusCode::NO_CONTENT.into_response(),
Ok(false) => (
StatusCode::NOT_FOUND,
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/billing/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub async fn create_stripe_portal(
.into_response();
};

let tenant_doc = match tenants.find_by_id(&tenant.to_object_id()).await {
let tenant_doc = match tenants.find_by_id(&tenant).await {
Ok(Some(t)) => t,
Ok(None) => {
return (
Expand Down Expand Up @@ -286,7 +286,7 @@ pub async fn cancel_subscription(
)
.into_response();
};
let tenant_doc = match tenants.find_by_id(&tenant.to_object_id()).await {
let tenant_doc = match tenants.find_by_id(&tenant).await {
Ok(Some(t)) => t,
Ok(None) => {
return (
Expand Down
8 changes: 3 additions & 5 deletions server/src/api/billing/stripe_webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ async fn handle_subscription_upsert(
};

tenants
.apply_subscription_update(&tenant_id.to_object_id(), update)
.apply_subscription_update(&tenant_id, update)
.await?;

Ok(())
Expand All @@ -283,9 +283,7 @@ async fn handle_subscription_deleted(
tracing::warn!(customer = %sub.customer, "stripe_webhook_deleted_no_tenant");
return Ok(());
};
tenants
.clear_subscription(&tenant_id.to_object_id())
.await?;
tenants.clear_subscription(&tenant_id).await?;
Ok(())
}

Expand Down Expand Up @@ -324,7 +322,7 @@ async fn handle_invoice_status(
..SubscriptionUpdate::default()
};
tenants
.apply_subscription_update(&tenant_id.to_object_id(), update)
.apply_subscription_update(&tenant_id, update)
.await?;
Ok(())
}
Expand Down
22 changes: 5 additions & 17 deletions server/src/api/conversions/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@ pub async fn create_source(
.into_response();
}

match repo
.create_source(tenant.to_object_id(), name, req.source_type)
.await
{
match repo.create_source(tenant, name, req.source_type).await {
Ok(source) => {
let resp = CreateSourceResponse {
id: source.id,
Expand Down Expand Up @@ -113,7 +110,7 @@ pub async fn list_sources(
.into_response();
};

let mut sources = match repo.list_sources(&tenant.to_object_id()).await {
let mut sources = match repo.list_sources(&tenant).await {
Ok(s) => s,
Err(e) => {
tracing::error!(error = %e, "Failed to list sources");
Expand All @@ -128,10 +125,7 @@ pub async fn list_sources(
// Auto-provision a default custom source if the tenant has none. This is the
// zero-ceremony dev flow: first GET returns a usable webhook URL immediately.
if sources.is_empty() {
match repo
.get_or_create_default_custom_source(tenant.to_object_id())
.await
{
match repo.get_or_create_default_custom_source(tenant).await {
Ok(source) => sources.push(source),
Err(e) => {
tracing::error!(error = %e, "Failed to auto-provision default source");
Expand Down Expand Up @@ -175,10 +169,7 @@ pub async fn get_source(
.into_response();
};

match repo
.find_source_by_id(&tenant.to_object_id(), &id.to_object_id())
.await
{
match repo.find_source_by_id(&tenant, &id).await {
Ok(Some(source)) => Json(to_detail(&state, &source)).into_response(),
Ok(None) => (
StatusCode::NOT_FOUND,
Expand Down Expand Up @@ -223,10 +214,7 @@ pub async fn delete_source(
.into_response();
};

match repo
.delete_source(&tenant.to_object_id(), &id.to_object_id())
.await
{
match repo.delete_source(&tenant, &id).await {
Ok(true) => StatusCode::NO_CONTENT.into_response(),
Ok(false) => (
StatusCode::NOT_FOUND,
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/domains/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub async fn list_domains(
.into_response();
};

match repo.list_by_tenant(&tenant.to_object_id()).await {
match repo.list_by_tenant(&tenant).await {
Ok(domains) => {
let details: Vec<DomainDetail> = domains
.iter()
Expand Down Expand Up @@ -221,7 +221,7 @@ pub async fn delete_domain(
.into_response();
};

match repo.delete_domain(&tenant.to_object_id(), &domain).await {
match repo.delete_domain(&tenant, &domain).await {
Ok(true) => {
// Remove TLS certificate from Fly.io (best-effort).
// DB is authoritative — orphaned certs are harmless and can be cleaned up later.
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/lifecycle/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub async fn lifecycle_click(
};

let link = repo
.find_link_by_tenant_and_id(&tenant.to_object_id(), &req.link_id)
.find_link_by_tenant_and_id(&tenant, &req.link_id)
.await
.ok()
.flatten();
Expand Down Expand Up @@ -176,7 +176,7 @@ pub async fn lifecycle_attribute(
};

let link = repo
.find_link_by_tenant_and_id(&tenant.to_object_id(), &req.link_id)
.find_link_by_tenant_and_id(&tenant, &req.link_id)
.await
.ok()
.flatten();
Expand Down
2 changes: 1 addition & 1 deletion server/src/api/links/qr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(crate) async fn render_link_qr(
};

let Some(link) = repo
.find_link_by_tenant_and_id(&tenant.to_object_id(), &link_id)
.find_link_by_tenant_and_id(&tenant, &link_id)
.await
.ok()
.flatten()
Expand Down
10 changes: 5 additions & 5 deletions server/src/api/links/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pub async fn resolve_link_custom(
}

let Some(link) = repo
.find_link_by_tenant_and_id(domain.tenant_id.as_object_id(), &link_id)
.find_link_by_tenant_and_id(&domain.tenant_id, &link_id)
.await
.ok()
.flatten()
Expand Down Expand Up @@ -665,12 +665,12 @@ async fn do_resolve(
Platform::Other => "android",
};
let app = apps_repo
.find_by_tenant_platform(link.tenant_id.as_object_id(), preferred)
.find_by_tenant_platform(&link.tenant_id, preferred)
.await
.ok()
.flatten()
.or(apps_repo
.find_by_tenant_platform(link.tenant_id.as_object_id(), fallback)
.find_by_tenant_platform(&link.tenant_id, fallback)
.await
.ok()
.flatten());
Expand All @@ -686,7 +686,7 @@ async fn do_resolve(
// Look up alternate domain for the "Open in App" button.
let alternate_domain = if let Some(domains_repo) = &state.domains_repo {
domains_repo
.find_alternate_by_tenant(link.tenant_id.as_object_id())
.find_alternate_by_tenant(&link.tenant_id)
.await
.ok()
.flatten()
Expand Down Expand Up @@ -884,7 +884,7 @@ async fn lookup_tenant_domain(
return (None, false);
};
let domains = repo
.list_by_tenant(tenant_id.as_object_id())
.list_by_tenant(tenant_id)
.await
.ok()
.unwrap_or_default();
Expand Down
24 changes: 5 additions & 19 deletions server/src/api/webhooks/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub async fn list_webhooks(
.into_response();
};

match repo.list_by_tenant(&tenant.to_object_id()).await {
match repo.list_by_tenant(&tenant).await {
Ok(webhooks) => {
let details: Vec<WebhookDetail> = webhooks
.into_iter()
Expand Down Expand Up @@ -162,10 +162,7 @@ pub async fn delete_webhook(
.into_response();
};

match repo
.delete_webhook(&tenant.to_object_id(), &webhook_id.to_object_id())
.await
{
match repo.delete_webhook(&tenant, &webhook_id).await {
Ok(true) => StatusCode::NO_CONTENT.into_response(),
Ok(false) => (
StatusCode::NOT_FOUND,
Expand Down Expand Up @@ -210,8 +207,6 @@ pub async fn patch_webhook(
.into_response();
};

let oid = webhook_id.to_object_id();

if req.active.is_none() && req.events.is_none() && req.url.is_none() {
return (
StatusCode::BAD_REQUEST,
Expand Down Expand Up @@ -245,22 +240,13 @@ pub async fn patch_webhook(
}

match repo
.update_webhook(
&tenant.to_object_id(),
&oid,
req.active,
req.events,
req.url,
)
.update_webhook(&tenant, &webhook_id, req.active, req.events, req.url)
.await
{
Ok(true) => {
// Fetch updated webhook to return.
let webhooks = repo
.list_by_tenant(&tenant.to_object_id())
.await
.unwrap_or_default();
match webhooks.iter().find(|w| w.id.to_object_id() == oid) {
let webhooks = repo.list_by_tenant(&tenant).await.unwrap_or_default();
match webhooks.iter().find(|w| w.id == webhook_id) {
Some(w) => Json(json!({
"id": w.id,
"url": w.url,
Expand Down
4 changes: 2 additions & 2 deletions server/src/mcp/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl RiftMcp {
Parameters(input): Parameters<CreateSourceInput>,
Extension(parts): Extension<Parts>,
) -> Result<Json<CreateSourceOutput>, String> {
let tenant_id = self.auth_context(&parts).await?.tenant_id.to_object_id();
let tenant_id = self.auth_context(&parts).await?.tenant_id;
let repo = self
.conversions_repo
.as_ref()
Expand Down Expand Up @@ -336,7 +336,7 @@ impl RiftMcp {
Parameters(_input): Parameters<ListSourcesInput>,
Extension(parts): Extension<Parts>,
) -> Result<Json<ListSourcesOutput>, String> {
let tenant_id = self.auth_context(&parts).await?.tenant_id.to_object_id();
let tenant_id = self.auth_context(&parts).await?.tenant_id;
let repo = self
.conversions_repo
.as_ref()
Expand Down
14 changes: 3 additions & 11 deletions server/src/services/affiliates/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,9 @@ impl AffiliatesService {

// Per-affiliate cap. Counted at the repo level via the scope filter
// so a compromised tenant key can't spam unbounded credentials.
let aff_oid = affiliate_id.to_object_id();
let existing = self
.secret_keys_repo
.list_by_tenant_and_affiliate(ctx.tenant_id.as_object_id(), &aff_oid)
.list_by_tenant_and_affiliate(&ctx.tenant_id, &affiliate_id)
.await
.map_err(AffiliateError::Internal)?;
if existing.len() >= MAX_CREDENTIALS_PER_AFFILIATE {
Expand Down Expand Up @@ -210,10 +209,7 @@ impl AffiliatesService {
.ok_or(AffiliateError::NotFound)?;

self.secret_keys_repo
.list_by_tenant_and_affiliate(
ctx.tenant_id.as_object_id(),
&affiliate_id.to_object_id(),
)
.list_by_tenant_and_affiliate(&ctx.tenant_id, &affiliate_id)
.await
.map_err(AffiliateError::Internal)
}
Expand All @@ -236,11 +232,7 @@ impl AffiliatesService {

let deleted = self
.secret_keys_repo
.delete_affiliate_credential(
ctx.tenant_id.as_object_id(),
&affiliate_id.to_object_id(),
&key_id.to_object_id(),
)
.delete_affiliate_credential(&ctx.tenant_id, &affiliate_id, &key_id)
.await
.map_err(AffiliateError::Internal)?;

Expand Down
Loading
Loading