From a0eb33ec2ff10a9d44316c3eb39b1936ff8b58fa Mon Sep 17 00:00:00 2001 From: filou Date: Sun, 21 Jul 2024 17:24:50 +0200 Subject: [PATCH] use internalId rather than itemAPIPath for microsoft root --- connectors/src/connectors/microsoft/index.ts | 16 +++++----------- .../connectors/microsoft/temporal/activities.ts | 9 +++++++-- .../src/connectors/microsoft/temporal/file.ts | 7 ++----- connectors/src/lib/models/microsoft.ts | 4 ++-- connectors/src/resources/microsoft_resource.ts | 8 ++++---- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/connectors/src/connectors/microsoft/index.ts b/connectors/src/connectors/microsoft/index.ts index fce5076b35f6..6f48b45b7ad7 100644 --- a/connectors/src/connectors/microsoft/index.ts +++ b/connectors/src/connectors/microsoft/index.ts @@ -174,12 +174,7 @@ export class MicrosoftConnectorManager extends BaseConnectorManager { const selectedResources = ( await MicrosoftRootResource.listRootsByConnectorId(connector.id) - ).map((r) => - internalIdFromTypeAndPath({ - nodeType: r.nodeType, - itemAPIPath: r.itemAPIPath, - }) - ); + ).map((r) => r.internalId); // at the time, we only sync sharepoint sites and drives, not team channels // work on teams has been started here and in graph_api.ts but is not yet @@ -283,10 +278,7 @@ export class MicrosoftConnectorManager extends BaseConnectorManager { } await MicrosoftRootResource.batchDelete({ - resourceIds: Object.entries(permissions).map((internalId) => { - const { itemAPIPath } = typeAndPathFromInternalId(internalId[0]); - return itemAPIPath; - }), + resourceIds: Object.keys(permissions), connectorId: connector.id, }); @@ -294,9 +286,11 @@ export class MicrosoftConnectorManager extends BaseConnectorManager { Object.entries(permissions) .filter(([, permission]) => permission === "read") .map(([id]) => { + const { nodeType } = typeAndPathFromInternalId(id); return { connectorId: connector.id, - ...typeAndPathFromInternalId(id), + nodeType, + internalId: id, }; }) ); diff --git a/connectors/src/connectors/microsoft/temporal/activities.ts b/connectors/src/connectors/microsoft/temporal/activities.ts index 5d01a8cd6d47..c32e7da72486 100644 --- a/connectors/src/connectors/microsoft/temporal/activities.ts +++ b/connectors/src/connectors/microsoft/temporal/activities.ts @@ -69,14 +69,19 @@ export async function getSiteNodesToSync( .map(async (resource) => itemToMicrosoftNode( resource.nodeType as "folder" | "drive", - await getItem(client, resource.itemAPIPath) + await getItem( + client, + typeAndPathFromInternalId(resource.internalId).itemAPIPath + ) ) ) ); const rootSitePaths: string[] = rootResources .filter((resource) => resource.nodeType === "site") - .map((resource) => resource.itemAPIPath); + .map( + (resource) => typeAndPathFromInternalId(resource.internalId).itemAPIPath + ); if (rootResources.some((resource) => resource.nodeType === "sites-root")) { const msSites = await getAllPaginatedEntities((nextLink) => diff --git a/connectors/src/connectors/microsoft/temporal/file.ts b/connectors/src/connectors/microsoft/temporal/file.ts index f9f832c0702e..3deeb4ac5d5c 100644 --- a/connectors/src/connectors/microsoft/temporal/file.ts +++ b/connectors/src/connectors/microsoft/temporal/file.ts @@ -16,7 +16,6 @@ import { getClient } from "@connectors/connectors/microsoft"; import { getDriveItemInternalId, getFileDownloadURL, - typeAndPathFromInternalId, } from "@connectors/connectors/microsoft/lib/graph_api"; import { getMimeTypesToSync } from "@connectors/connectors/microsoft/temporal/mime_types"; import { @@ -530,11 +529,9 @@ export async function deleteFolder({ `Deleting Microsoft folder.` ); - const { itemAPIPath } = typeAndPathFromInternalId(internalId); - - const root = await MicrosoftRootResource.fetchByItemAPIPath( + const root = await MicrosoftRootResource.fetchByInternalId( connectorId, - itemAPIPath + internalId ); if (root) { diff --git a/connectors/src/lib/models/microsoft.ts b/connectors/src/lib/models/microsoft.ts index 130c7e885cb5..59c55cbc09c2 100644 --- a/connectors/src/lib/models/microsoft.ts +++ b/connectors/src/lib/models/microsoft.ts @@ -75,7 +75,7 @@ export class MicrosoftRootModel extends Model< declare createdAt: CreationOptional; declare updatedAt: CreationOptional; declare connectorId: ForeignKey; - declare itemAPIPath: string; + declare internalId: string; declare nodeType: MicrosoftNodeType; } MicrosoftRootModel.init( @@ -99,7 +99,7 @@ MicrosoftRootModel.init( type: DataTypes.INTEGER, allowNull: false, }, - itemAPIPath: { + internalId: { type: DataTypes.STRING, allowNull: false, }, diff --git a/connectors/src/resources/microsoft_resource.ts b/connectors/src/resources/microsoft_resource.ts index 9f1bccbc90a3..c3433952ea6c 100644 --- a/connectors/src/resources/microsoft_resource.ts +++ b/connectors/src/resources/microsoft_resource.ts @@ -171,7 +171,7 @@ export class MicrosoftRootResource extends BaseResource { }) { return MicrosoftRootModel.destroy({ where: { - itemAPIPath: resourceIds, + internalId: resourceIds, connectorId, }, transaction, @@ -201,11 +201,11 @@ export class MicrosoftRootResource extends BaseResource { return new Ok(undefined); } - static async fetchByItemAPIPath(connectorId: ModelId, itemAPIPath: string) { + static async fetchByInternalId(connectorId: ModelId, internalId: string) { const blob = await this.model.findOne({ where: { connectorId, - itemAPIPath, + internalId, }, }); @@ -219,7 +219,7 @@ export class MicrosoftRootResource extends BaseResource { return { id: this.id, nodeType: this.nodeType, - itemApiPath: this.itemAPIPath, + internalId: this.internalId, connectorId: this.connectorId, }; }