Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "fix(Zendesk) - use the new internal IDs in content nodes"" #9723

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions connectors/migrations/20250102_clean_zendesk_tickets_articles.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { makeScript } from "scripts/helpers";
import { Op } from "sequelize";

import {
getArticleInternalId,
getTicketInternalId,
} from "@connectors/connectors/zendesk/lib/id_conversions";
import { dataSourceConfigFromConnector } from "@connectors/lib/api/data_source_config";
import { concurrentExecutor } from "@connectors/lib/async_utils";
import { deleteDataSourceDocument } from "@connectors/lib/data_sources";
Expand Down Expand Up @@ -39,10 +35,7 @@ async function cleanTickets(
return deleteDataSourceDocument(
dataSourceConfigFromConnector(connector),
// this is the old internal ID
getTicketInternalId({
connectorId: connector.id,
ticketId: ticket.ticketId,
})
`zendesk-ticket-${connector.id}-${ticket.ticketId}`
);
},
{ concurrency: DOCUMENT_CONCURRENCY }
Expand Down Expand Up @@ -89,10 +82,7 @@ async function cleanArticles(
return deleteDataSourceDocument(
dataSourceConfigFromConnector(connector),
// this is the old internal ID
getArticleInternalId({
connectorId: connector.id,
articleId: article.articleId,
})
`zendesk-article-${connector.id}-${article.articleId}`
);
},
{ concurrency: DOCUMENT_CONCURRENCY }
Expand Down
79 changes: 40 additions & 39 deletions connectors/src/connectors/zendesk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "@connectors/connectors/zendesk/lib/help_center_permissions";
import {
getBrandInternalId,
getIdFromInternalId,
getIdsFromInternalId,
} from "@connectors/connectors/zendesk/lib/id_conversions";
import {
retrieveAllSelectedNodes,
Expand Down Expand Up @@ -359,26 +359,27 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
);
}

const { type, objectId } = getIdFromInternalId(connectorId, id);
const { type, objectIds } = getIdsFromInternalId(connectorId, id);
const { brandId } = objectIds;
switch (type) {
case "brand": {
if (permission === "none") {
const updatedBrand = await forbidSyncZendeskBrand({
connectorId,
brandId: objectId,
brandId,
});
if (updatedBrand) {
toBeSignaledBrandIds.add(objectId);
toBeSignaledBrandIds.add(brandId);
}
}
if (permission === "read") {
const wasBrandUpdated = await allowSyncZendeskBrand({
connectorId,
connectionId,
brandId: objectId,
brandId,
});
if (wasBrandUpdated) {
toBeSignaledBrandIds.add(objectId);
toBeSignaledBrandIds.add(brandId);
}
}
break;
Expand All @@ -387,20 +388,20 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
if (permission === "none") {
const updatedBrandHelpCenter = await forbidSyncZendeskHelpCenter({
connectorId,
brandId: objectId,
brandId,
});
if (updatedBrandHelpCenter) {
toBeSignaledHelpCenterIds.add(updatedBrandHelpCenter.brandId);
toBeSignaledHelpCenterIds.add(brandId);
}
}
if (permission === "read") {
const wasBrandUpdated = await allowSyncZendeskHelpCenter({
connectorId,
connectionId,
brandId: objectId,
brandId,
});
if (wasBrandUpdated) {
toBeSignaledHelpCenterIds.add(objectId);
toBeSignaledHelpCenterIds.add(brandId);
}
}
break;
Expand All @@ -409,46 +410,46 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
if (permission === "none") {
const updatedBrandTickets = await forbidSyncZendeskTickets({
connectorId,
brandId: objectId,
brandId,
});
if (updatedBrandTickets) {
toBeSignaledTicketsIds.add(updatedBrandTickets.brandId);
toBeSignaledTicketsIds.add(brandId);
}
}
if (permission === "read") {
const wasBrandUpdated = await allowSyncZendeskTickets({
connectorId,
connectionId,
brandId: objectId,
brandId,
});
if (wasBrandUpdated) {
toBeSignaledTicketsIds.add(objectId);
toBeSignaledTicketsIds.add(brandId);
}
}
break;
}
case "category": {
const { categoryId } = objectIds;
if (permission === "none") {
const updatedCategory = await forbidSyncZendeskCategory({
connectorId,
categoryId: objectId.categoryId,
categoryId,
});
if (updatedCategory) {
toBeSignaledCategoryIds.add(updatedCategory.categoryId);
categoryBrandIds[updatedCategory.categoryId] =
updatedCategory.brandId;
toBeSignaledCategoryIds.add(categoryId);
categoryBrandIds[categoryId] = brandId;
}
}
if (permission === "read") {
const newCategory = await allowSyncZendeskCategory({
connectorId,
connectionId,
categoryId: objectId.categoryId,
brandId: objectId.brandId,
categoryId,
brandId,
});
if (newCategory) {
toBeSignaledCategoryIds.add(newCategory.categoryId);
categoryBrandIds[newCategory.categoryId] = newCategory.brandId;
toBeSignaledCategoryIds.add(categoryId);
categoryBrandIds[categoryId] = brandId;
}
}
break;
Expand All @@ -457,7 +458,7 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
case "article":
case "ticket":
logger.error(
{ connectorId, objectId },
{ connectorId, objectIds, type },
"[Zendesk] Cannot set permissions for a single article or ticket"
);
return new Err(
Expand Down Expand Up @@ -504,33 +505,33 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
const articleIds: number[] = [];
const ticketIds: number[] = [];
internalIds.forEach((internalId) => {
const { type, objectId } = getIdFromInternalId(
const { type, objectIds } = getIdsFromInternalId(
this.connectorId,
internalId
);
switch (type) {
case "brand": {
brandIds.push(objectId);
brandIds.push(objectIds.brandId);
return;
}
case "tickets": {
brandTicketsIds.push(objectId);
brandTicketsIds.push(objectIds.brandId);
return;
}
case "help-center": {
brandHelpCenterIds.push(objectId);
brandHelpCenterIds.push(objectIds.brandId);
return;
}
case "category": {
categoryIds.push(objectId.categoryId);
categoryIds.push(objectIds.categoryId);
return;
}
case "article": {
articleIds.push(objectId);
articleIds.push(objectIds.articleId);
return;
}
case "ticket": {
ticketIds.push(objectId);
ticketIds.push(objectIds.ticketId);
return;
}
default: {
Expand Down Expand Up @@ -597,7 +598,8 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
}): Promise<Result<string[], Error>> {
const { connectorId } = this;

const { type, objectId } = getIdFromInternalId(connectorId, internalId);
const { type, objectIds } = getIdsFromInternalId(connectorId, internalId);
const { brandId } = objectIds;
switch (type) {
case "brand": {
return new Ok([internalId]);
Expand All @@ -607,20 +609,19 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
case "tickets": {
return new Ok([
internalId,
getBrandInternalId({ connectorId, brandId: objectId }),
getBrandInternalId({ connectorId, brandId }),
]);
}
case "category": {
const category = await ZendeskCategoryResource.fetchByCategoryId({
connectorId,
categoryId: objectId.categoryId,
categoryId: objectIds.categoryId,
});
if (category) {
return new Ok(category.getParentInternalIds(connectorId));
} else {
const { brandId, categoryId } = objectId;
logger.error(
{ connectorId, categoryId, brandId },
{ connectorId, ...objectIds },
"[Zendesk] Category not found"
);
return new Err(new Error("Category not found"));
Expand All @@ -629,13 +630,13 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
case "article": {
const article = await ZendeskArticleResource.fetchByArticleId({
connectorId,
articleId: objectId,
articleId: objectIds.articleId,
});
if (article) {
return new Ok(article.getParentInternalIds(connectorId));
} else {
logger.error(
{ connectorId, articleId: objectId },
{ connectorId, ...objectIds },
"[Zendesk] Article not found"
);
return new Err(new Error("Article not found"));
Expand All @@ -644,13 +645,13 @@ export class ZendeskConnectorManager extends BaseConnectorManager<null> {
case "ticket": {
const ticket = await ZendeskTicketResource.fetchByTicketId({
connectorId,
ticketId: objectId,
ticketId: objectIds.ticketId,
});
if (ticket) {
return new Ok(ticket.getParentInternalIds(connectorId));
} else {
logger.error(
{ connectorId, ticketId: objectId },
{ connectorId, ...objectIds },
"[Zendesk] Ticket not found"
);
return new Err(new Error("Ticket not found"));
Expand Down
Loading
Loading