mirror of
https://github.com/formbricks/formbricks.git
synced 2026-04-24 03:21:20 -05:00
refactor: added authorization to airtable integration and create a common actions file (#1538)
This commit is contained in:
committed by
GitHub
parent
a3028e5685
commit
0c69f8ad43
@@ -0,0 +1,26 @@
|
||||
"use server";
|
||||
|
||||
import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions";
|
||||
import { createOrUpdateIntegration, deleteIntegration } from "@formbricks/lib/integration/service";
|
||||
import { getServerSession } from "next-auth";
|
||||
|
||||
import { canUserAccessIntegration } from "@formbricks/lib/integration/auth";
|
||||
import { AuthorizationError } from "@formbricks/types/errors";
|
||||
import { TIntegrationInput } from "@formbricks/types/integration";
|
||||
|
||||
export async function createOrUpdateIntegrationAction(
|
||||
environmentId: string,
|
||||
integrationData: TIntegrationInput
|
||||
) {
|
||||
return await createOrUpdateIntegration(environmentId, integrationData);
|
||||
}
|
||||
|
||||
export async function deleteIntegrationAction(integrationId: string) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) throw new AuthorizationError("Not authorized");
|
||||
|
||||
const isAuthorized = await canUserAccessIntegration(session.user.id, integrationId);
|
||||
if (!isAuthorized) throw new AuthorizationError("Not authorized");
|
||||
|
||||
return await deleteIntegration(integrationId);
|
||||
}
|
||||
@@ -1,16 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import { getAirtableTables } from "@formbricks/lib/airtable/service";
|
||||
import { createOrUpdateIntegration, deleteIntegration } from "@formbricks/lib/integration/service";
|
||||
import { TIntegrationInput } from "@formbricks/types/integration";
|
||||
|
||||
export async function upsertIntegrationAction(environmentId: string, integrationData: TIntegrationInput) {
|
||||
return await createOrUpdateIntegration(environmentId, integrationData);
|
||||
}
|
||||
|
||||
export async function deleteIntegrationAction(integrationId: string) {
|
||||
return await deleteIntegration(integrationId);
|
||||
}
|
||||
|
||||
export async function refreshTablesAction(environmentId: string) {
|
||||
return await getAirtableTables(environmentId);
|
||||
|
||||
+3
-3
@@ -15,12 +15,12 @@ import { Label } from "@formbricks/ui/Label";
|
||||
import { Modal } from "@formbricks/ui/Modal";
|
||||
import AirtableLogo from "../images/airtable.svg";
|
||||
import { fetchTables } from "@/app/(app)/environments/[environmentId]/integrations/airtable/lib/airtable";
|
||||
import { createOrUpdateIntegrationAction } from "@/app/(app)/environments/[environmentId]/integrations/actions";
|
||||
import Image from "next/image";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { Control, Controller, UseFormSetValue, useForm } from "react-hook-form";
|
||||
import { toast } from "react-hot-toast";
|
||||
import { upsertIntegrationAction } from "../actions";
|
||||
import { TIntegrationItem } from "@formbricks/types/integration";
|
||||
|
||||
type EditModeProps =
|
||||
@@ -183,7 +183,7 @@ export default function AddIntegrationModal(props: AddIntegrationModalProps) {
|
||||
|
||||
const actionMessage = isEditMode ? "updated" : "added";
|
||||
|
||||
await upsertIntegrationAction(environmentId, airtableIntegrationData);
|
||||
await createOrUpdateIntegrationAction(environmentId, airtableIntegrationData);
|
||||
toast.success(`Integration ${actionMessage} successfully`);
|
||||
handleClose();
|
||||
} catch (e) {
|
||||
@@ -215,7 +215,7 @@ export default function AddIntegrationModal(props: AddIntegrationModalProps) {
|
||||
const integrationCopy = { ...airtableIntegration };
|
||||
integrationCopy.config.data.splice(index, 1);
|
||||
|
||||
await upsertIntegrationAction(environmentId, integrationCopy);
|
||||
await createOrUpdateIntegrationAction(environmentId, integrationCopy);
|
||||
handleClose();
|
||||
router.refresh();
|
||||
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
"use client";
|
||||
import Connect from "./Connect";
|
||||
import Home from "../Home";
|
||||
import Home from "./Home";
|
||||
import { useState } from "react";
|
||||
import { TSurvey } from "@formbricks/types/surveys";
|
||||
import { TEnvironment } from "@formbricks/types/environment";
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ import { DeleteDialog } from "@formbricks/ui/DeleteDialog";
|
||||
import AddIntegrationModal, {
|
||||
IntegrationModalInputs,
|
||||
} from "@/app/(app)/environments/[environmentId]/integrations/airtable/components/AddIntegrationModal";
|
||||
import { deleteIntegrationAction } from "@/app/(app)/environments/[environmentId]/integrations/airtable/actions";
|
||||
import { deleteIntegrationAction } from "@/app/(app)/environments/[environmentId]/integrations/actions";
|
||||
import { useState } from "react";
|
||||
import { toast } from "react-hot-toast";
|
||||
import EmptySpaceFiller from "@formbricks/ui/EmptySpaceFiller";
|
||||
@@ -2,30 +2,10 @@
|
||||
|
||||
import { authOptions } from "@/app/api/auth/[...nextauth]/authOptions";
|
||||
import { getSpreadSheets } from "@formbricks/lib/googleSheet/service";
|
||||
import { createOrUpdateIntegration, deleteIntegration } from "@formbricks/lib/integration/service";
|
||||
import { getServerSession } from "next-auth";
|
||||
|
||||
import { hasUserEnvironmentAccess } from "@formbricks/lib/environment/auth";
|
||||
import { canUserAccessIntegration } from "@formbricks/lib/integration/auth";
|
||||
import { AuthorizationError } from "@formbricks/types/errors";
|
||||
import { TIntegrationGoogleSheetsInput } from "@formbricks/types/integration/googleSheet";
|
||||
|
||||
export async function createOrUpdateIntegrationAction(
|
||||
environmentId: string,
|
||||
integrationData: TIntegrationGoogleSheetsInput
|
||||
) {
|
||||
return await createOrUpdateIntegration(environmentId, integrationData);
|
||||
}
|
||||
|
||||
export async function deleteIntegrationAction(integrationId: string) {
|
||||
const session = await getServerSession(authOptions);
|
||||
if (!session) throw new AuthorizationError("Not authorized");
|
||||
|
||||
const isAuthorized = await canUserAccessIntegration(session.user.id, integrationId);
|
||||
if (!isAuthorized) throw new AuthorizationError("Not authorized");
|
||||
|
||||
return await deleteIntegration(integrationId);
|
||||
}
|
||||
|
||||
export async function refreshSheetAction(environmentId: string) {
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { createOrUpdateIntegrationAction } from "@/app/(app)/environments/[environmentId]/integrations/google-sheets/actions";
|
||||
import { createOrUpdateIntegrationAction } from "@/app/(app)/environments/[environmentId]/integrations/actions";
|
||||
import {
|
||||
TIntegrationGoogleSheets,
|
||||
TIntegrationGoogleSheetsConfigData,
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { deleteIntegrationAction } from "@/app/(app)/environments/[environmentId]/integrations/google-sheets/actions";
|
||||
import { deleteIntegrationAction } from "@/app/(app)/environments/[environmentId]/integrations/actions";
|
||||
import { timeSince } from "@formbricks/lib/time";
|
||||
import { TEnvironment } from "@formbricks/types/environment";
|
||||
import {
|
||||
|
||||
Reference in New Issue
Block a user