Browse Source

refactor: only allow url hook and disable app api call if env is set

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5272/head
Pranav C 2 years ago
parent
commit
49272e8a9f
  1. 31
      packages/nc-gui/components/webhook/Editor.vue
  2. 1
      packages/nc-gui/composables/useGlobal/state.ts
  3. 1
      packages/nc-gui/composables/useGlobal/types.ts
  4. 5
      packages/nc-gui/pages/account/index.vue
  5. 5
      packages/nc-gui/pages/account/index/[page].vue
  6. 22
      packages/nocodb/src/lib/services/hook.svc.ts

31
packages/nc-gui/components/webhook/Editor.vue

@ -13,6 +13,7 @@ import {
reactive,
ref,
useApi,
useGlobal,
useI18n,
useNuxtApp,
watch,
@ -32,6 +33,8 @@ const { $e } = useNuxtApp()
const { api, isLoading: loading } = useApi()
const { appInfo } = $(useGlobal())
const meta = inject(MetaInj, ref())
const useForm = Form.useForm
@ -170,16 +173,20 @@ const eventList = [
{ text: ['After', 'Delete'], value: ['after', 'delete'] },
]
const notificationList = [
{ type: 'URL' },
{ type: 'Email' },
{ type: 'Slack' },
{ type: 'Microsoft Teams' },
{ type: 'Discord' },
{ type: 'Mattermost' },
{ type: 'Twilio' },
{ type: 'Whatsapp Twilio' },
]
const notificationList = computed(() => {
return appInfo.isCloud
? [{ type: 'URL' }]
: [
{ type: 'URL' },
{ type: 'Email' },
{ type: 'Slack' },
{ type: 'Microsoft Teams' },
{ type: 'Discord' },
{ type: 'Mattermost' },
{ type: 'Twilio' },
{ type: 'Whatsapp Twilio' },
]
})
const methodList = [
{ title: 'GET' },
@ -414,7 +421,9 @@ watch(
{ immediate: true },
)
onMounted(loadPluginList)
onMounted(() => {
if (!appInfo.isCoud) loadPluginList()
})
</script>
<template>

1
packages/nc-gui/composables/useGlobal/state.ts

@ -99,6 +99,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State {
version: '0.0.0',
ncAttachmentFieldSize: 20,
ncMaxAttachmentsAllowed: 10,
isCloud: false,
})
/** reactive token payload */

1
packages/nc-gui/composables/useGlobal/types.ts

@ -22,6 +22,7 @@ export interface AppInfo {
ee?: boolean
ncAttachmentFieldSize: number
ncMaxAttachmentsAllowed: number
isCloud: boolean
}
export interface StoredState {

5
packages/nc-gui/pages/account/index.vue

@ -2,8 +2,11 @@
import { navigateTo, useUIPermission } from '#imports'
const { isUIAllowed } = useUIPermission()
const $route = useRoute()
const { appInfo } = useGlobal()
const selectedKeys = computed(() => [
/^\/account\/users\/?$/.test($route.fullPath)
? isUIAllowed('superAdminUserManagement')
@ -68,7 +71,7 @@ const openKeys = ref([/^\/account\/users/.test($route.fullPath) && 'users'])
</div>
</a-menu-item>
<a-menu-item
v-if="isUIAllowed('appStore')"
v-if="isUIAllowed('appStore') && !appInfo.isCloud"
key="apps"
class="group active:(!ring-0) hover:(!bg-primary !bg-opacity-25)"
@click="navigateTo('/account/apps')"

5
packages/nc-gui/pages/account/index/[page].vue

@ -1,7 +1,10 @@
<script setup lang="ts">
const { appInfo } = useGlobal()
</script>
<template>
<AccountUserManagement v-if="$route.params.page === 'users'" />
<AccountToken v-else-if="$route.params.page === 'tokens'" />
<AccountAppStore v-else-if="$route.params.page === 'apps'" />
<AccountAppStore v-else-if="$route.params.page === 'apps' && !appInfo.isCloud" />
<AccountLicense v-else-if="$route.params.page === 'license'" />
<span v-else></span>
</template>

22
packages/nocodb/src/lib/services/hook.svc.ts

@ -1,11 +1,26 @@
import { T } from 'nc-help';
import { validatePayload } from '../meta/api/helpers';
import { NcError } from '../meta/helpers/catchError';
import { Hook, Model } from '../models';
import { invokeWebhook } from '../meta/helpers/webhookHelpers';
import populateSamplePayload from '../meta/helpers/populateSamplePayload';
import type { HookReqType, HookTestReqType } from 'nocodb-sdk';
function validateHookPayload(notificationJsonOrObject: string | object) {
let notification: { type?: string } = {};
try {
notification =
typeof notificationJsonOrObject === 'string'
? JSON.parse(notificationJsonOrObject)
: notificationJsonOrObject;
} catch {}
if (notification.type !== 'URL' && process.env.NC_CLOUD) {
NcError.badRequest('Only URL notification is supported');
}
}
export async function hookList(param: { tableId: string }) {
// todo: pagination
return await Hook.list({ fk_model_id: param.tableId });
@ -17,6 +32,8 @@ export async function hookCreate(param: {
}) {
validatePayload('swagger.json#/components/schemas/HookReq', param.hook);
validateHookPayload(param.hook.notification);
T.emit('evt', { evt_type: 'webhooks:created' });
// todo: type correction
const hook = await Hook.insert({
@ -37,6 +54,8 @@ export async function hookUpdate(param: { hookId: string; hook: HookReqType }) {
T.emit('evt', { evt_type: 'webhooks:updated' });
validateHookPayload(param.hook.notification);
// todo: correction in swagger
return await Hook.update(param.hookId, param.hook as any);
}
@ -50,6 +69,8 @@ export async function hookTest(param: {
param.hookTest
);
validateHookPayload(param.hookTest.hook?.notification);
const model = await Model.getByIdOrName({ id: param.tableId });
const {
@ -69,6 +90,7 @@ export async function hookTest(param: {
return true;
}
export async function tableSampleData(param: {
tableId: string;
operation: 'insert' | 'update';

Loading…
Cancel
Save