Skip to content

Commit

Permalink
use internalId rather than itemAPIPath for microsoft root
Browse files Browse the repository at this point in the history
  • Loading branch information
philipperolet committed Jul 21, 2024
1 parent 06e6817 commit a0eb33e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 24 deletions.
16 changes: 5 additions & 11 deletions connectors/src/connectors/microsoft/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,7 @@ export class MicrosoftConnectorManager extends BaseConnectorManager<null> {

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
Expand Down Expand Up @@ -283,20 +278,19 @@ export class MicrosoftConnectorManager extends BaseConnectorManager<null> {
}

await MicrosoftRootResource.batchDelete({
resourceIds: Object.entries(permissions).map((internalId) => {
const { itemAPIPath } = typeAndPathFromInternalId(internalId[0]);
return itemAPIPath;
}),
resourceIds: Object.keys(permissions),
connectorId: connector.id,
});

await MicrosoftRootResource.batchMakeNew(
Object.entries(permissions)
.filter(([, permission]) => permission === "read")
.map(([id]) => {
const { nodeType } = typeAndPathFromInternalId(id);
return {
connectorId: connector.id,
...typeAndPathFromInternalId(id),
nodeType,
internalId: id,
};
})
);
Expand Down
9 changes: 7 additions & 2 deletions connectors/src/connectors/microsoft/temporal/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
7 changes: 2 additions & 5 deletions connectors/src/connectors/microsoft/temporal/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions connectors/src/lib/models/microsoft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class MicrosoftRootModel extends Model<
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;
declare connectorId: ForeignKey<ConnectorModel["id"]>;
declare itemAPIPath: string;
declare internalId: string;
declare nodeType: MicrosoftNodeType;
}
MicrosoftRootModel.init(
Expand All @@ -99,7 +99,7 @@ MicrosoftRootModel.init(
type: DataTypes.INTEGER,
allowNull: false,
},
itemAPIPath: {
internalId: {
type: DataTypes.STRING,
allowNull: false,
},
Expand Down
8 changes: 4 additions & 4 deletions connectors/src/resources/microsoft_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class MicrosoftRootResource extends BaseResource<MicrosoftRootModel> {
}) {
return MicrosoftRootModel.destroy({
where: {
itemAPIPath: resourceIds,
internalId: resourceIds,
connectorId,
},
transaction,
Expand Down Expand Up @@ -201,11 +201,11 @@ export class MicrosoftRootResource extends BaseResource<MicrosoftRootModel> {
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,
},
});

Expand All @@ -219,7 +219,7 @@ export class MicrosoftRootResource extends BaseResource<MicrosoftRootModel> {
return {
id: this.id,
nodeType: this.nodeType,
itemApiPath: this.itemAPIPath,
internalId: this.internalId,
connectorId: this.connectorId,
};
}
Expand Down

0 comments on commit a0eb33e

Please sign in to comment.