From 20e4187162790b02e150e06b7cbc86bc30e0808b Mon Sep 17 00:00:00 2001 From: Shams mosowi Date: Tue, 25 Aug 2020 10:33:58 +1000 Subject: [PATCH] remove actions --- .../functions/src/actions/index.ts | 74 ------------------- 1 file changed, 74 deletions(-) delete mode 100644 cloud_functions/functions/src/actions/index.ts diff --git a/cloud_functions/functions/src/actions/index.ts b/cloud_functions/functions/src/actions/index.ts deleted file mode 100644 index 6c20b9e5..00000000 --- a/cloud_functions/functions/src/actions/index.ts +++ /dev/null @@ -1,74 +0,0 @@ -import * as functions from "firebase-functions"; -import * as _ from "lodash"; -import * as admin from "firebase-admin"; - -import { hasAnyRole } from "../utils/auth"; -import config from "../functionConfig"; // generated using generateConfig.ts - -type ActionData = { - ref: { - id: string; - path: string; - parentId: string; - }; - row: any; - column: any; - action: "run" | "redo" | "undo"; -}; - -type ActionScript = ( - data: ActionData, - context: functions.https.CallableContext -) => { - message: string; - redo: boolean; - undo: boolean; - status: string; - success: Boolean; -}; -const functionConfig: { - AllowedRoles: string[]; - functionName: string; - actionScripts: { - run: ActionScript; - undo: ActionScript; - redo: ActionScript; - }; -} = config; - -const { AllowedRoles, functionName, actionScripts } = functionConfig; -const serverTimestamp = admin.firestore.FieldValue.serverTimestamp; - -const actionCallable = async ( - data: ActionData, - context: functions.https.CallableContext -) => { - const authorized = - AllowedRoles && AllowedRoles.length !== 0 - ? hasAnyRole(AllowedRoles, context) - : true; - - if (!context.auth || !authorized) { - console.warn(`unauthorized user ${context}`); - return { - success: false, - message: "you don't have permissions to preform this action", - }; - } - const result = actionScripts[data.action](data, context); - return { - message: result.message, - cellValue: { - redo: result.redo, - status: result.status, - completedAt: serverTimestamp(), - ranBy: context.auth.uid, - undo: result.undo, - }, - success: result.success, - }; -}; - -export const FT_actions = { - [functionName]: functions.https.onCall(actionCallable), -};