From 15aaf7f51bd14b97f54a678b15dd75771943332e Mon Sep 17 00:00:00 2001 From: Syed Ali Shahbaz <52925846+alishaz-polymath@users.noreply.github.com> Date: Wed, 16 Apr 2025 17:32:56 +0530 Subject: [PATCH] fix: readonly ics error (#20651) * readonly error fix * warn instead of throwing err * . * . * fix err * dont throw error, only warn * -- * remove skip writing as that's unnecessary * fix api --- .../app-store/ics-feedcalendar/api/add.ts | 4 +- .../ics-feedcalendar/lib/CalendarService.ts | 38 ++++++++++--------- .../ics-feedcalendar/pages/setup/index.tsx | 21 +--------- 3 files changed, 24 insertions(+), 39 deletions(-) diff --git a/packages/app-store/ics-feedcalendar/api/add.ts b/packages/app-store/ics-feedcalendar/api/add.ts index 626a838206..1ae3d89049 100644 --- a/packages/app-store/ics-feedcalendar/api/add.ts +++ b/packages/app-store/ics-feedcalendar/api/add.ts @@ -10,7 +10,7 @@ import { CalendarService } from "../lib"; export default async function handler(req: NextApiRequest, res: NextApiResponse) { if (req.method === "POST") { - const { urls, skipWriting } = req.body; + const { urls } = req.body; // Get user const user = await prisma.user.findFirstOrThrow({ where: { @@ -24,7 +24,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const data = { type: appConfig.type, - key: symmetricEncrypt(JSON.stringify({ urls, skipWriting }), process.env.CALENDSO_ENCRYPTION_KEY || ""), + key: symmetricEncrypt(JSON.stringify({ urls }), process.env.CALENDSO_ENCRYPTION_KEY || ""), userId: user.id, teamId: null, appId: appConfig.slug, diff --git a/packages/app-store/ics-feedcalendar/lib/CalendarService.ts b/packages/app-store/ics-feedcalendar/lib/CalendarService.ts index 19e425e3e2..7a09df9761 100644 --- a/packages/app-store/ics-feedcalendar/lib/CalendarService.ts +++ b/packages/app-store/ics-feedcalendar/lib/CalendarService.ts @@ -40,29 +40,28 @@ const CALENDSO_ENCRYPTION_KEY = process.env.CALENDSO_ENCRYPTION_KEY || ""; export default class ICSFeedCalendarService implements Calendar { private urls: string[] = []; - private skipWriting = false; protected integrationName = "ics-feed_calendar"; constructor(credential: CredentialPayload) { - const { urls, skipWriting } = JSON.parse( - symmetricDecrypt(credential.key as string, CALENDSO_ENCRYPTION_KEY) - ); + const { urls } = JSON.parse(symmetricDecrypt(credential.key as string, CALENDSO_ENCRYPTION_KEY)); this.urls = urls; - this.skipWriting = skipWriting; } createEvent(_event: CalendarEvent, _credentialId: number): Promise { - if (this.skipWriting) { - return Promise.reject(new Error("Event creation is disabled for this calendar.")); - } - throw new Error("createEvent called on read-only ICS feed"); + console.warn("createEvent called on ICS (read-only) feed"); + return Promise.resolve({ + uid: _event.uid || "", + type: this.integrationName, + id: "", + password: "", + url: "", + additionalInfo: { calWarnings: ["ICS feed is read-only"] }, + }); } deleteEvent(_uid: string, _event: CalendarEvent, _externalCalendarId?: string): Promise { - if (this.skipWriting) { - return Promise.reject(new Error("Event creation is disabled for this calendar.")); - } - throw new Error("deleteEvent called on read-only ICS feed"); + console.warn("deleteEvent called on ICS (read-only) feed"); + return Promise.resolve(); } updateEvent( @@ -70,10 +69,15 @@ export default class ICSFeedCalendarService implements Calendar { _event: CalendarEvent, _externalCalendarId?: string ): Promise { - if (this.skipWriting) { - return Promise.reject(new Error("Event creation is disabled for this calendar.")); - } - throw new Error("updateEvent called on read-only ICS feed"); + console.warn("updateEvent called on ICS (read-only) feed"); + return Promise.resolve({ + uid: _event.uid || "", + type: this.integrationName, + id: "", + password: "", + url: "", + additionalInfo: { calWarnings: ["ICS feed is read-only"] }, + }); } fetchCalendars = async (): Promise<{ url: string; vcalendar: ICAL.Component }[]> => { diff --git a/packages/app-store/ics-feedcalendar/pages/setup/index.tsx b/packages/app-store/ics-feedcalendar/pages/setup/index.tsx index 7bc692df5c..3990b3b24b 100644 --- a/packages/app-store/ics-feedcalendar/pages/setup/index.tsx +++ b/packages/app-store/ics-feedcalendar/pages/setup/index.tsx @@ -6,7 +6,6 @@ import { Toaster } from "sonner"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { Alert } from "@calcom/ui/components/alert"; import { Button } from "@calcom/ui/components/button"; -import { CheckboxField } from "@calcom/ui/components/form"; import { Form } from "@calcom/ui/components/form"; import { TextField } from "@calcom/ui/components/form"; import { Icon } from "@calcom/ui/components/icon"; @@ -21,7 +20,6 @@ export default function ICSFeedSetup() { const [urls, setUrls] = useState([""]); const [errorMessage, setErrorMessage] = useState(""); const [errorActionUrl, setErrorActionUrl] = useState(""); - const [skipWriting, setSkipWriting] = useState(false); // track if user opts out of writing to any calendar return (
@@ -45,7 +43,7 @@ export default function ICSFeedSetup() { setErrorMessage(""); const res = await fetch("/api/integrations/ics-feedcalendar/add", { method: "POST", - body: JSON.stringify({ urls, skipWriting }), + body: JSON.stringify({ urls }), headers: { "Content-Type": "application/json", }, @@ -96,23 +94,6 @@ export default function ICSFeedSetup() { {t("add")} -
- setSkipWriting(e.target.checked)} - className="mr-2" - description={t("skip_writing_to_calendar")} - /> -
- - - {errorMessage && (