Scheduling infrastructure for absolutely everyone.
fix: readonly ics error (#20651)
Syed Ali Shahbaz15aaf7f51bd1
diff --git a/packages/app-store/ics-feedcalendar/api/add.ts b/packages/app-store/ics-feedcalendar/api/add.tsindex 626a838206a..1ae3d890494 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 userconst 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.tsindex 19e425e3e2b..7a09df9761c 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<NewCalendarEventType> {- 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<unknown> {- 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<NewCalendarEventType | NewCalendarEventType[]> {- 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.tsxindex 7bc692df5c1..3990b3b24be 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<string[]>([""]);const [errorMessage, setErrorMessage] = useState("");const [errorActionUrl, setErrorActionUrl] = useState("");- const [skipWriting, setSkipWriting] = useState(false); // track if user opts out of writing to any calendarreturn (<div className="bg-emphasis flex h-screen">@@ -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")} <Icon className="inline" name="plus" size={16} /></button>- <div className="mt-3 flex items-center">- <CheckboxField- id="skipWriting"- checked={skipWriting}- onChange={(e) => setSkipWriting(e.target.checked)}- className="mr-2"- description={t("skip_writing_to_calendar")}- />- </div>-- <Alert- className="mt-3"- severity="info"- title={t("notes")}- message={t("skip_writing_to_calendar_note")}- />-{errorMessage && (<Alertseverity="error"