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
This commit is contained in:
1 parent
c89a1877ae
commit
15aaf7f51b
3 files changed
+24
-39
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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 }[]> => {
|
||||
|
||||
@@ -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 calendar
|
||||
|
||||
return (
|
||||
<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 && (
|
||||
<Alert
|
||||
severity="error"
|
||||
|
||||
Reference in new issue
Block a user