From 3fcc9035bb2e25d860f36db95ec50d46d6d7b1fc Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Mon, 19 May 2025 00:41:31 +0500 Subject: [PATCH] Fix calendar service (#8981) --- dev/tool/src/calendar.ts | 10 +++++++++- services/calendar/pod-calendar/src/auth.ts | 6 +++--- services/calendar/pod-calendar/src/pushHandler.ts | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/dev/tool/src/calendar.ts b/dev/tool/src/calendar.ts index d6ef9ebd02..7cc2659c7e 100644 --- a/dev/tool/src/calendar.ts +++ b/dev/tool/src/calendar.ts @@ -1,5 +1,11 @@ import calendar from '@hcengineering/calendar' -import { type PersonId, type WorkspaceInfoWithStatus, type WorkspaceUuid, systemAccountUuid } from '@hcengineering/core' +import { + type PersonId, + type WorkspaceInfoWithStatus, + type WorkspaceUuid, + isActiveMode, + systemAccountUuid +} from '@hcengineering/core' import { getClient as getKvsClient } from '@hcengineering/kvs-client' import { createClient, getAccountClient } from '@hcengineering/server-client' import { generateToken } from '@hcengineering/server-token' @@ -129,6 +135,7 @@ async function migrateCalendarIntegrations ( if (ws == null) { continue } + if (!isActiveMode(ws.mode)) continue token.workspace = ws.uuid const personId = await getPersonIdByEmail(ws.uuid, token.email, token.userId) @@ -215,6 +222,7 @@ async function migrateCalendarHistory ( if (ws == null) { continue } + if (!isActiveMode(ws.mode)) continue const personId = await getPersonIdByEmail(ws.uuid, history.email, history.userId) if (personId == null) { diff --git a/services/calendar/pod-calendar/src/auth.ts b/services/calendar/pod-calendar/src/auth.ts index 02c453cec7..d99b6bd6df 100644 --- a/services/calendar/pod-calendar/src/auth.ts +++ b/services/calendar/pod-calendar/src/auth.ts @@ -25,7 +25,7 @@ import { getClient } from './client' import { addUserByEmail, removeUserByEmail } from './kvsUtils' import { IncomingSyncManager, lock } from './sync' import { CALENDAR_INTEGRATION, GoogleEmail, SCOPES, State, Token, User } from './types' -import { getGoogleClient, getServiceToken } from './utils' +import { getGoogleClient, getWorkspaceToken } from './utils' import { WatchController } from './watch' interface AuthResult { @@ -58,7 +58,7 @@ export class AuthController { await ctx.with('Create auth controller', { workspace: state.workspace, user: state.userId }, async () => { const mutex = await lock(`${state.workspace}:${state.userId}`) try { - const client = await getClient(getServiceToken()) + const client = await getClient(getWorkspaceToken(state.workspace)) const txOp = new TxOperations(client, core.account.System) const controller = new AuthController(ctx, accountClient, txOp, state) await controller.process(code) @@ -78,7 +78,7 @@ export class AuthController { await ctx.with('Signout auth controller', { workspace, userId }, async () => { const mutex = await lock(`${workspace}:${userId}`) try { - const client = await getClient(getServiceToken()) + const client = await getClient(getWorkspaceToken(workspace)) const txOp = new TxOperations(client, core.account.System) const controller = new AuthController(ctx, accountClient, txOp, { userId, diff --git a/services/calendar/pod-calendar/src/pushHandler.ts b/services/calendar/pod-calendar/src/pushHandler.ts index 177e1d34fd..bca596c1cd 100644 --- a/services/calendar/pod-calendar/src/pushHandler.ts +++ b/services/calendar/pod-calendar/src/pushHandler.ts @@ -19,7 +19,7 @@ import { getClient } from './client' import { getUserByEmail } from './kvsUtils' import { IncomingSyncManager } from './sync' import { GoogleEmail, Token } from './types' -import { getGoogleClient, getServiceToken } from './utils' +import { getGoogleClient, getWorkspaceToken } from './utils' export class PushHandler { constructor ( @@ -29,7 +29,7 @@ export class PushHandler { async sync (token: Token, calendarId: string | null): Promise { await this.ctx.with('Push handler', { workspace: token.workspace, user: token.userId }, async () => { - const client = await getClient(getServiceToken()) + const client = await getClient(getWorkspaceToken(token.workspace)) const txOp = new TxOperations(client, core.account.System) const res = getGoogleClient() res.auth.setCredentials(token)