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

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

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

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

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

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

@ -1,11 +1,26 @@
import { T } from 'nc-help'; import { T } from 'nc-help';
import { validatePayload } from '../meta/api/helpers'; import { validatePayload } from '../meta/api/helpers';
import { NcError } from '../meta/helpers/catchError';
import { Hook, Model } from '../models'; import { Hook, Model } from '../models';
import { invokeWebhook } from '../meta/helpers/webhookHelpers'; import { invokeWebhook } from '../meta/helpers/webhookHelpers';
import populateSamplePayload from '../meta/helpers/populateSamplePayload'; import populateSamplePayload from '../meta/helpers/populateSamplePayload';
import type { HookReqType, HookTestReqType } from 'nocodb-sdk'; 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 }) { export async function hookList(param: { tableId: string }) {
// todo: pagination // todo: pagination
return await Hook.list({ fk_model_id: param.tableId }); 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); validatePayload('swagger.json#/components/schemas/HookReq', param.hook);
validateHookPayload(param.hook.notification);
T.emit('evt', { evt_type: 'webhooks:created' }); T.emit('evt', { evt_type: 'webhooks:created' });
// todo: type correction // todo: type correction
const hook = await Hook.insert({ 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' }); T.emit('evt', { evt_type: 'webhooks:updated' });
validateHookPayload(param.hook.notification);
// todo: correction in swagger // todo: correction in swagger
return await Hook.update(param.hookId, param.hook as any); return await Hook.update(param.hookId, param.hook as any);
} }
@ -50,6 +69,8 @@ export async function hookTest(param: {
param.hookTest param.hookTest
); );
validateHookPayload(param.hookTest.hook?.notification);
const model = await Model.getByIdOrName({ id: param.tableId }); const model = await Model.getByIdOrName({ id: param.tableId });
const { const {
@ -69,6 +90,7 @@ export async function hookTest(param: {
return true; return true;
} }
export async function tableSampleData(param: { export async function tableSampleData(param: {
tableId: string; tableId: string;
operation: 'insert' | 'update'; operation: 'insert' | 'update';

Loading…
Cancel
Save