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.

fix(gmail): broken email links (#3747)

Will Hutchinson5567164f8fad
diff --git a/js/app/packages/app/component/GmailReauthenticationPrompt.tsx b/js/app/packages/app/component/GmailReauthenticationPrompt.tsx
new file mode 100644
index 0000000000..ac7b8ab9b5
--- /dev/null
+++ b/js/app/packages/app/component/GmailReauthenticationPrompt.tsx
@@ -0,0 +1,66 @@
+import { emailAuthUrl } from '@core/auth/email';
+import { toast } from '@core/component/Toast/Toast';
+import { authServiceClient } from '@service-auth/client';
+import { onMount } from 'solid-js';
+
+let gmailReauthenticationToastId: number | undefined;
+
+function clearGmailReauthenticationToastState(): void {
+ gmailReauthenticationToastId = undefined;
+}
+
+function handleGmailReauthenticationToastAction(): void {
+ if (gmailReauthenticationToastId !== undefined) {
+ toast.dismiss(gmailReauthenticationToastId);
+ }
+ clearGmailReauthenticationToastState();
+
+ window.location.href = emailAuthUrl({
+ returnPath: `${window.location.pathname}${window.location.search}${window.location.hash}`,
+ });
+}
+
+function showGmailReauthenticationToast(): void {
+ if (gmailReauthenticationToastId !== undefined) return;
+
+ gmailReauthenticationToastId = toast.custom(
+ {
+ title: 'Reconnect Gmail',
+ content(): string {
+ return 'Your Gmail authorization has expired. Reconnect Gmail to restore email sync.';
+ },
+ actions: [
+ {
+ label: 'Reconnect',
+ onClick: handleGmailReauthenticationToastAction,
+ },
+ ],
+ },
+ {
+ persistent: true,
+ onDismiss: clearGmailReauthenticationToastState,
+ }
+ );
+}
+
+async function checkGmailReauthenticationStatus(): Promise<void> {
+ const response = await authServiceClient.checkGmailLinkStatus();
+
+ const needsReauthentication = response.isOk()
+ ? response.value.reauthentication_required
+ : response.error.some(
+ (error) => error.code === 'REAUTHENTICATION_REQUIRED'
+ );
+
+ if (needsReauthentication) {
+ showGmailReauthenticationToast();
+ }
+}
+
+export function GmailReauthenticationPrompt() {
+ onMount(() => {
+ void checkGmailReauthenticationStatus();
+ });
+
+ return null;
+}
diff --git a/js/app/packages/app/component/Layout.tsx b/js/app/packages/app/component/Layout.tsx
index 401fb38455..9b9af81ddb 100644
--- a/js/app/packages/app/component/Layout.tsx
+++ b/js/app/packages/app/component/Layout.tsx
@@ -34,6 +34,7 @@ import { CommandMenu } from './command';
import { DevStatusBar } from './DevStatusBar';
import { GithubReauthenticationPrompt } from './GithubReauthenticationPrompt';
import GlobalShortcuts from './GlobalHotkeys';
+import { GmailReauthenticationPrompt } from './GmailReauthenticationPrompt';
import { GlobalShareModal } from './global-share-modal/GlobalShareModal';
import { ItemDndProvider } from './ItemDragAndDrop';
import { IosShareSheet } from './ios-share-sheet/IosShareSheet';
@@ -139,6 +140,7 @@ function LayoutInner(props: RouteSectionProps) {
<Show when={isAuthenticated()}>
<Show when={!AUTH_URLS.includes(location.pathname)}>
<GithubReauthenticationPrompt />
+ <GmailReauthenticationPrompt />
</Show>
<GlobalShortcuts />
<Show when={!isMobile()}>
diff --git a/js/app/packages/core/auth/email.ts b/js/app/packages/core/auth/email.ts
index 2ea9c84fc7..66996db15f 100644
--- a/js/app/packages/core/auth/email.ts
+++ b/js/app/packages/core/auth/email.ts
@@ -9,7 +9,7 @@ type EmailAuthParams = {
returnPath?: string;
};
-function emailAuthUrl(params: EmailAuthParams) {
+export function emailAuthUrl(params: EmailAuthParams) {
const idpName = params.idpName ?? GOOGLE_GMAIL_IDP;
const returnUrl = `${window.location.origin}${params.returnPath ?? ROUTER_BASE}`;
diff --git a/js/app/packages/service-clients/service-auth/client.ts b/js/app/packages/service-clients/service-auth/client.ts
index 7ed082d330..1a612240d4 100644
--- a/js/app/packages/service-clients/service-auth/client.ts
+++ b/js/app/packages/service-clients/service-auth/client.ts
@@ -17,6 +17,7 @@ import type {
EnrichGithubPullRequestsProxyRequest,
EnrichGithubPullRequestsResponse,
GithubLinkStatusResponse,
+ GmailLinkStatusResponse,
InitGithubLinkResponse,
InitGmailLinkResponse,
PatchSubscriptionTierRequest,
@@ -593,6 +594,18 @@ export const authServiceClient = {
).map((result) => result);
},
+ async checkGmailLinkStatus() {
+ return (
+ await fetchWithAuth<
+ GmailLinkStatusResponse,
+ GithubReauthenticationErrorCode
+ >(`${authHost}/link/gmail/status`, {
+ method: 'GET',
+ errorResponseHandler: githubErrorResponseHandler,
+ })
+ ).map((result) => result);
+ },
+
/**
* Initializes the github account link for the user.
* Returns the url you need to redirect user to to start the link.
diff --git a/js/app/packages/service-clients/service-auth/generated/client.ts b/js/app/packages/service-clients/service-auth/generated/client.ts
index f3c6b70dab..3aa9041d58 100644
--- a/js/app/packages/service-clients/service-auth/generated/client.ts
+++ b/js/app/packages/service-clients/service-auth/generated/client.ts
@@ -25,6 +25,7 @@ import type {
GetUserInfo,
GetUserLinkExistsParams,
GithubLinkStatusResponse,
+ GmailLinkStatusResponse,
InitGithubLinkParams,
InitGithubLinkResponse,
InitGmailLinkParams,
@@ -873,6 +874,75 @@ export const initGmailLink = async (
} as initGmailLinkResponse;
};
+/**
+ * @summary Checks whether the authenticated user's gmail link is valid.
+ */
+export type checkGmailLinkStatusResponse200 = {
+ data: GmailLinkStatusResponse;
+ status: 200;
+};
+
+export type checkGmailLinkStatusResponse401 = {
+ data: ErrorResponse;
+ status: 401;
+};
+
+export type checkGmailLinkStatusResponse404 = {
+ data: ErrorResponse;
+ status: 404;
+};
+
+export type checkGmailLinkStatusResponse428 = {
+ data: ErrorResponse;
+ status: 428;
+};
+
+export type checkGmailLinkStatusResponse500 = {
+ data: ErrorResponse;
+ status: 500;
+};
+
+export type checkGmailLinkStatusResponseSuccess =
+ checkGmailLinkStatusResponse200 & {
+ headers: Headers;
+ };
+export type checkGmailLinkStatusResponseError = (
+ | checkGmailLinkStatusResponse401
+ | checkGmailLinkStatusResponse404
+ | checkGmailLinkStatusResponse428
+ | checkGmailLinkStatusResponse500
+) & {
+ headers: Headers;
+};
+
+export type checkGmailLinkStatusResponse =
+ | checkGmailLinkStatusResponseSuccess
+ | checkGmailLinkStatusResponseError;
+
+export const getCheckGmailLinkStatusUrl = () => {
+ return `/link/gmail/status`;
+};
+
+export const checkGmailLinkStatus = async (
+ options?: RequestInit
+): Promise<checkGmailLinkStatusResponse> => {
+ const res = await fetch(getCheckGmailLinkStatusUrl(), {
+ ...options,
+ method: 'GET',
+ });
+
+ const body = [204, 205, 304].includes(res.status) ? null : await res.text();
+
+ const data: checkGmailLinkStatusResponse['data'] = body
+ ? JSON.parse(body)
+ : {};
+ return {
+ data,
+ status: res.status,
+ headers: res.headers,
+ } as checkGmailLinkStatusResponse;
+};
+
/**
* @summary Completes the apple login flow
*/
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/gmailLinkStatusResponse.ts b/js/app/packages/service-clients/service-auth/generated/schemas/gmailLinkStatusResponse.ts
new file mode 100644
index 0000000000..0244219654
--- /dev/null
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/gmailLinkStatusResponse.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * authentication_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+export interface GmailLinkStatusResponse {
+ /** Whether the user must reauthenticate their Gmail link. */
+ reauthentication_required: boolean;
+}
diff --git a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
index f46046cec0..5495b47d00 100644
--- a/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
+++ b/js/app/packages/service-clients/service-auth/generated/schemas/index.ts
@@ -55,6 +55,7 @@ export * from './githubPullRequestCommentUpdatedAt';
export * from './githubPullRequestCommentUrl';
export * from './githubPullRequestRef';
export * from './githubPullRequestStatus';
+export * from './gmailLinkStatusResponse';
export * from './initGithubLinkParams';
export * from './initGithubLinkResponse';
export * from './initGmailLinkParams';
diff --git a/js/app/packages/service-clients/service-auth/openapi.json b/js/app/packages/service-clients/service-auth/openapi.json
index f070cde555..eaaff9f661 100644
--- a/js/app/packages/service-clients/service-auth/openapi.json
+++ b/js/app/packages/service-clients/service-auth/openapi.json
@@ -680,6 +680,65 @@
}
}
},
+ "/link/gmail/status": {
+ "get": {
+ "tags": ["link::gmail"],
+ "summary": "Checks whether the authenticated user's gmail link is valid.",
+ "operationId": "check_gmail_link_status",
+ "responses": {
+ "200": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/GmailLinkStatusResponse"
+ }
+ }
+ }
+ },
+ "401": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "404": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "428": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ },
+ "500": {
+ "description": "",
+ "content": {
+ "application/json": {
+ "schema": {
+ "$ref": "#/components/schemas/ErrorResponse"
+ }
+ }
+ }
+ }
+ }
+ }
+ },
"/login/apple": {
"post": {
"tags": ["login::apple"],
@@ -3916,6 +3975,16 @@
"description": "The normalized lifecycle status for a GitHub pull request.",
"enum": ["open", "closed", "merged"]
},
+ "GmailLinkStatusResponse": {
+ "type": "object",
+ "required": ["reauthentication_required"],
+ "properties": {
+ "reauthentication_required": {
+ "type": "boolean",
+ "description": "Whether the user must reauthenticate their Gmail link."
+ }
+ }
+ },
"InitGithubLinkResponse": {
"type": "object",
"required": ["authorization_url", "link_id"],
diff --git a/js/bun.lock b/js/bun.lock
index 198ad6c4b1..d8a2279d66 100644
--- a/js/bun.lock
+++ b/js/bun.lock
@@ -827,7 +827,7 @@
"@img/sharp-win32-x64": ["@img/[email protected]", "", { "os": "win32", "cpu": "x64" }, "sha512-+29YMsqY2/9eFEiW93eqWnuLcWcufowXewwSNIT6UwZdUUCrM3oFjMWH/Z6/TMmb4hlFenmfAVbpWeup2jryCw=="],
- "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8"],
+ "@inkibra/tauri-plugins": ["@inkibra/tauri-plugins@github:macro-inc/tauri-plugins#26537c8", { "dependencies": { "react": "^18.3.1", "react-dom": "^18.3.1" } }, "macro-inc-tauri-plugins-26537c8", "sha512-6p5xQAkS6Uw6J8Uh0vlj6MjKZXWps5E1Gu0hciBFq1E2BfPBZAgdeeafKnR3diNb4SXWK0JML49nAr+o5PhwKw=="],
"@inquirer/external-editor": ["@inquirer/[email protected]", "", { "dependencies": { "chardet": "^2.1.1", "iconv-lite": "^0.7.0" }, "peerDependencies": { "@types/node": ">=18" }, "optionalPeers": ["@types/node"] }, "sha512-RWbSrDiYmO4LbejWY7ttpxczuwQyZLBUyygsA9Nsv95hpzUWwnNTVQmAq3xuh7vNwCp07UTmE5i11XAEExx4RA=="],
@@ -2547,7 +2547,7 @@
"pathval": ["[email protected]", "", {}, "sha512-//nshmD55c46FuFw26xV/xFAaB5HF9Xdap7HJBBnrKdAd6/GxDBaNA1870O79+9ueg61cZLSVc+OaFlfmObYVQ=="],
- "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6"],
+ "pdfjs-dist": ["pdfjs-dist@github:macro-inc/pdf.js#f9b2ce6", { "dependencies": { "dommatrix": "^1.0.3", "web-streams-polyfill": "^3.2.1" }, "peerDependencies": { "worker-loader": "^3.0.8" }, "optionalPeers": ["worker-loader"] }, "macro-inc-pdf.js-f9b2ce6", "sha512-HDFaPbCxLG2GHpf1smUG97nku5aPGBGaCcIbK05dGdp07TBLUlDcXsM4WcE82mO5W4RBPIBVYobX5N/6M6NFrA=="],
"performance-now": ["[email protected]", "", {}, "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow=="],
diff --git a/rust/cloud-storage/.sqlx/query-42175eb671a66713c2bb172aed854b0fd109b0089bbb4951379ea045012ad6f6.json b/rust/cloud-storage/.sqlx/query-42175eb671a66713c2bb172aed854b0fd109b0089bbb4951379ea045012ad6f6.json
new file mode 100644
index 0000000000..cc245b938c
--- /dev/null
+++ b/rust/cloud-storage/.sqlx/query-42175eb671a66713c2bb172aed854b0fd109b0089bbb4951379ea045012ad6f6.json
@@ -0,0 +1,22 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT id FROM email_links\n WHERE macro_id = $1\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "id",
+ "type_info": "Uuid"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text"
+ ]
+ },
+ "nullable": [
+ false
+ ]
+ },
+ "hash": "42175eb671a66713c2bb172aed854b0fd109b0089bbb4951379ea045012ad6f6"
+}
diff --git a/rust/cloud-storage/.sqlx/query-5202bbfa20ba1bb7f8f28a42e4e35dd42ea503b82a670c2d648a1889eaf6936e.json b/rust/cloud-storage/.sqlx/query-5202bbfa20ba1bb7f8f28a42e4e35dd42ea503b82a670c2d648a1889eaf6936e.json
deleted file mode 100644
index a752bf3ee2..0000000000
--- a/rust/cloud-storage/.sqlx/query-5202bbfa20ba1bb7f8f28a42e4e35dd42ea503b82a670c2d648a1889eaf6936e.json
+++ /dev/null
@@ -1,27 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n INSERT INTO comms_channel_participants (channel_id, role, user_id)\n VALUES ($1, $2, $3)\n ON CONFLICT (channel_id, user_id) DO NOTHING\n ",
- "describe": {
- "columns": [],
- "parameters": {
- "Left": [
- "Uuid",
- {
- "Custom": {
- "name": "comms_participant_role",
- "kind": {
- "Enum": [
- "owner",
- "admin",
- "member"
- ]
- }
- }
- },
- "Text"
- ]
- },
- "nullable": []
- },
- "hash": "5202bbfa20ba1bb7f8f28a42e4e35dd42ea503b82a670c2d648a1889eaf6936e"
-}
diff --git a/rust/cloud-storage/authentication_service/src/api/link/github.rs b/rust/cloud-storage/authentication_service/src/api/link/github.rs
index 603f388f35..c7051ce82e 100644
--- a/rust/cloud-storage/authentication_service/src/api/link/github.rs
+++ b/rust/cloud-storage/authentication_service/src/api/link/github.rs
@@ -14,7 +14,7 @@ use crate::api::{context::ApiContext, oauth2::OAuthState};
use model::response::{EmptyResponse, ErrorResponse};
-const REAUTHENTICATION_REQUIRED_MESSAGE: &str = "ReauthenticationRequired";
+pub const REAUTHENTICATION_REQUIRED_MESSAGE: &str = "ReauthenticationRequired";
#[derive(serde::Deserialize, serde::Serialize, Debug, utoipa::ToSchema)]
pub struct GithubLinkStatusResponse {
diff --git a/rust/cloud-storage/authentication_service/src/api/link/gmail.rs b/rust/cloud-storage/authentication_service/src/api/link/gmail.rs
index be75b73ddc..7451afa7eb 100644
--- a/rust/cloud-storage/authentication_service/src/api/link/gmail.rs
+++ b/rust/cloud-storage/authentication_service/src/api/link/gmail.rs
@@ -11,7 +11,9 @@ use model_user::axum_extractor::MacroUserExtractor;
use serde_utils::urlencode::UrlEncoded;
use url::Url;
-use crate::api::{context::ApiContext, oauth2::OAuthState};
+use crate::api::{
+ context::ApiContext, link::github::REAUTHENTICATION_REQUIRED_MESSAGE, oauth2::OAuthState,
+};
const GOOGLE_AUTHORIZATION_URL: &str = "https://accounts.google.com/o/oauth2/v2/auth";
const GMAIL_IDENTITY_PROVIDER_NAME: &str = "google_gmail";
@@ -141,3 +143,89 @@ pub async fn init_gmail_link_handler(
link_id,
}))
}
+
+#[derive(serde::Deserialize, serde::Serialize, Debug, utoipa::ToSchema)]
+pub struct GmailLinkStatusResponse {
+ /// Whether the user must reauthenticate their Gmail link.
+ pub reauthentication_required: bool,
+}
+
+#[derive(thiserror::Error, Debug)]
+pub enum GmailLinkStatusError {
+ #[error("reauthentication required")]
+ ReauthenticationRequired,
+ #[error("internal")]
+ Internal(#[from] anyhow::Error),
+}
+
+impl IntoResponse for GmailLinkStatusError {
+ fn into_response(self) -> Response {
+ match &self {
+ GmailLinkStatusError::ReauthenticationRequired => (
+ StatusCode::PRECONDITION_REQUIRED,
+ Json(ErrorResponse {
+ message: REAUTHENTICATION_REQUIRED_MESSAGE.into(),
+ }),
+ ),
+ GmailLinkStatusError::Internal(_) => (
+ StatusCode::INTERNAL_SERVER_ERROR,
+ Json(ErrorResponse {
+ message: "internal error occurred".into(),
+ }),
+ ),
+ }
+ .into_response()
+ }
+}
+
+/// Checks whether the authenticated user's gmail link is valid.
+#[utoipa::path(
+ get,
+ operation_id = "check_gmail_link_status",
+ path = "/link/gmail/status",
+ responses(
+ (status = 200, body=GmailLinkStatusResponse),
+ (status = 401, body=ErrorResponse),
+ (status = 404, body=ErrorResponse),
+ (status = 428, body=ErrorResponse),
+ (status = 500, body=ErrorResponse),
+ )
+ )]
+#[tracing::instrument(skip(ctx, ip_context, user_context), fields(client_ip=%ip_context, user_id=%user_context.macro_user_id), err)]
+pub async fn check_gmail_link_status_handler(
+ State(ctx): State<ApiContext>,
+ ip_context: ClientIp,
+ user_context: MacroUserExtractor,
+) -> Result<Json<GmailLinkStatusResponse>, GmailLinkStatusError> {
+ // Check if the user has an email link in db
+ if macro_db_client::email::check_user_email_link(&ctx.db, &user_context.macro_user_id)
+ .await
+ .map_err(GmailLinkStatusError::Internal)?
+ {
+ let links = ctx
+ .auth_client
+ .get_links(&user_context.user_context.fusion_user_id, None)
+ .await
+ .map_err(|e| GmailLinkStatusError::Internal(e.into()))?;
+
+ let result = links
+ .iter()
+ .filter_map(|l| {
+ if l.identity_provider_name.eq("google_gmail") {
+ Some(true)
+ } else {
+ None
+ }
+ })
+ .collect::<Vec<bool>>();
+
+ // If no, return 428
+ if result.is_empty() {
+ return Err(GmailLinkStatusError::ReauthenticationRequired);
+ }
+ }
+
+ Ok(Json(GmailLinkStatusResponse {
+ reauthentication_required: false,
+ }))
+}
diff --git a/rust/cloud-storage/authentication_service/src/api/link/mod.rs b/rust/cloud-storage/authentication_service/src/api/link/mod.rs
index 04ec123b5e..592b123575 100644
--- a/rust/cloud-storage/authentication_service/src/api/link/mod.rs
+++ b/rust/cloud-storage/authentication_service/src/api/link/mod.rs
@@ -19,4 +19,5 @@ pub fn router(_state: ApiContext) -> Router<ApiContext> {
get(github::check_github_link_status_handler),
)
.route("/gmail", post(gmail::init_gmail_link_handler))
+ .route("/gmail/status", get(gmail::check_gmail_link_status_handler))
}
diff --git a/rust/cloud-storage/authentication_service/src/api/swagger.rs b/rust/cloud-storage/authentication_service/src/api/swagger.rs
index 6bbac983c5..12e461abea 100644
--- a/rust/cloud-storage/authentication_service/src/api/swagger.rs
+++ b/rust/cloud-storage/authentication_service/src/api/swagger.rs
@@ -21,7 +21,7 @@ use crate::api::email::resend_fusionauth_verify_user_email::ResendFusionauthVeri
use crate::api::jwt::macro_api_token::MacroApiTokenResponse;
use crate::api::link::create_in_progress_link::CreateInProgressLinkResponse;
use crate::api::link::github::{GithubLinkStatusResponse, InitGithubLinkResponse};
-use crate::api::link::gmail::InitGmailLinkResponse;
+use crate::api::link::gmail::{GmailLinkStatusResponse, InitGmailLinkResponse};
use crate::api::merge::create_merge_request::CreateAccountMergeRequest;
use crate::api::user::create_user::CreateUserRequest;
use crate::api::user::get_legacy_user_permissions::GetLegacyUserPermissionsResponse;
@@ -79,6 +79,7 @@ use model::user::{
link::github::delete_github_link_handler,
link::github::check_github_link_status_handler,
link::gmail::init_gmail_link_handler,
+ link::gmail::check_gmail_link_status_handler,
/// /github_pull_requests
github_pull_requests::handler,
@@ -179,6 +180,7 @@ use model::user::{
InitGithubLinkResponse,
GithubLinkStatusResponse,
InitGmailLinkResponse,
+ GmailLinkStatusResponse,
// GitHub pull requests
EnrichGithubPullRequestsProxyRequest,
diff --git a/rust/cloud-storage/macro_db_client/src/email.rs b/rust/cloud-storage/macro_db_client/src/email.rs
new file mode 100644
index 0000000000..ecc6775e59
--- /dev/null
+++ b/rust/cloud-storage/macro_db_client/src/email.rs
@@ -0,0 +1,21 @@
+use macro_user_id::user_id::MacroUserIdStr;
+
+/// Check if email link exists for user
+#[tracing::instrument(skip(db))]
+pub async fn check_user_email_link(
+ db: &sqlx::Pool<sqlx::Postgres>,
+ macro_user_id: &MacroUserIdStr<'static>,
+) -> anyhow::Result<bool> {
+ let link_id = sqlx::query!(
+ r#"
+ SELECT id FROM email_links
+ WHERE macro_id = $1
+ "#,
+ macro_user_id.as_ref()
+ )
+ .map(|row| row.id)
+ .fetch_optional(db)
+ .await?;
+
+ Ok(link_id.is_some())
+}
diff --git a/rust/cloud-storage/macro_db_client/src/lib.rs b/rust/cloud-storage/macro_db_client/src/lib.rs
index 3f37aaf349..834d0e173f 100644
--- a/rust/cloud-storage/macro_db_client/src/lib.rs
+++ b/rust/cloud-storage/macro_db_client/src/lib.rs
@@ -12,6 +12,7 @@ pub mod dcs;
pub mod document;
pub mod document_text;
pub mod docx_unzip;
+pub mod email;
pub mod entity_name;
pub mod experiment;
pub mod experiment_log;