From 81aa1e3ad1e0a72f20c93e81986b93ee507854f2 Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Tue, 26 Nov 2024 05:46:53 +0000 Subject: [PATCH] fix(nocodb): move custom url to ee --- .../src/controllers/custom-urls.controller.ts | 38 ----- .../meta/migrations/XcMigrationSourcev2.ts | 4 - .../meta/migrations/v2/nc_068_custom_url.ts | 44 ------ packages/nocodb/src/models/CustomUrl.ts | 133 +----------------- packages/nocodb/src/modules/noco.module.ts | 6 - packages/nocodb/src/schema/swagger-v2.json | 87 ------------ .../src/services/custom-urls.service.ts | 17 --- 7 files changed, 7 insertions(+), 322 deletions(-) delete mode 100644 packages/nocodb/src/controllers/custom-urls.controller.ts delete mode 100644 packages/nocodb/src/meta/migrations/v2/nc_068_custom_url.ts delete mode 100644 packages/nocodb/src/services/custom-urls.service.ts diff --git a/packages/nocodb/src/controllers/custom-urls.controller.ts b/packages/nocodb/src/controllers/custom-urls.controller.ts deleted file mode 100644 index e93295eec4..0000000000 --- a/packages/nocodb/src/controllers/custom-urls.controller.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { - Body, - Controller, - Get, - HttpCode, - Param, - Post, - UseGuards, -} from '@nestjs/common'; -import { GlobalGuard } from '~/guards/global/global.guard'; -import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard'; -import { CustomUrlsService } from 'src/services/custom-urls.service'; - -@Controller() -@UseGuards(MetaApiLimiterGuard, GlobalGuard) -export class CustomUrlsController { - constructor(protected readonly customUrlsService: CustomUrlsService) {} - - @Get([ - '/api/v1/db/meta/custom-url/:customPath', - '/api/v2/meta/custom-url/:customPath', - ]) - async getOriginalPath(@Param('customPath') customPath: string) { - return await this.customUrlsService.getOriginalPath(customPath); - } - - @Post(['/api/v1/db/meta/custom-url/check-path', '/api/v2/meta/check-path']) - @HttpCode(200) - async checkAvailability( - @Body() - body: { - id?: string; - custom_path?: string; - }, - ) { - return await this.customUrlsService.checkAvailability(body); - } -} diff --git a/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts b/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts index d37f1c9f28..15e2908e10 100644 --- a/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts +++ b/packages/nocodb/src/meta/migrations/XcMigrationSourcev2.ts @@ -55,7 +55,6 @@ import * as nc_065_encrypt_flag from '~/meta/migrations/v2/nc_065_encrypt_flag'; import * as nc_066_ai_button from '~/meta/migrations/v2/nc_066_ai_button'; import * as nc_067_personal_view from '~/meta/migrations/v2/nc_067_personal_view'; import * as nc_068_user_delete from '~/meta/migrations/v2/nc_068_user_delete'; -import * as nc_068_custom_url from '~/meta/migrations/v2/nc_068_custom_url'; // Create a custom migration source class export default class XcMigrationSourcev2 { @@ -122,7 +121,6 @@ export default class XcMigrationSourcev2 { 'nc_066_ai_button', 'nc_067_personal_view', 'nc_068_user_delete', - 'nc_068_custom_url', ]); } @@ -246,8 +244,6 @@ export default class XcMigrationSourcev2 { return nc_067_personal_view; case 'nc_068_user_delete': return nc_068_user_delete; - case 'nc_068_custom_url': - return nc_068_custom_url; } } } diff --git a/packages/nocodb/src/meta/migrations/v2/nc_068_custom_url.ts b/packages/nocodb/src/meta/migrations/v2/nc_068_custom_url.ts deleted file mode 100644 index 1e03520f01..0000000000 --- a/packages/nocodb/src/meta/migrations/v2/nc_068_custom_url.ts +++ /dev/null @@ -1,44 +0,0 @@ -import type { Knex } from 'knex'; -import { MetaTable } from '~/utils/globals'; - -const up = async (knex: Knex) => { - await knex.schema.createTable(MetaTable.CUSTOM_URLS, (table) => { - table.string('id', 20); - - table.string('fk_workspace_id', 20); - - table.string('base_id', 20); - - table.string('fk_model_id', 20); - - table.string('view_id', 20); - - table.string('original_path'); - - table.string('custom_path'); - - table.timestamps(true, true); - }); - - await knex.schema.alterTable(MetaTable.PROJECT, (table) => { - table.string('fk_custom_url_id', 20).index(); - }); - - await knex.schema.alterTable(MetaTable.VIEWS, (table) => { - table.string('fk_custom_url_id', 20).index(); - }); -}; - -const down = async (knex: Knex) => { - await knex.schema.dropTable(MetaTable.CUSTOM_URLS); - - await knex.schema.alterTable(MetaTable.PROJECT, (table) => { - table.dropColumn('fk_custom_url_id'); - }); - - await knex.schema.alterTable(MetaTable.VIEWS, (table) => { - table.dropColumn('fk_custom_url_id'); - }); -}; - -export { up, down }; diff --git a/packages/nocodb/src/models/CustomUrl.ts b/packages/nocodb/src/models/CustomUrl.ts index 2906c12fc6..fc374be395 100644 --- a/packages/nocodb/src/models/CustomUrl.ts +++ b/packages/nocodb/src/models/CustomUrl.ts @@ -1,13 +1,4 @@ import Noco from '~/Noco'; -import { extractProps } from '~/helpers/extractProps'; -import { - CacheGetType, - CacheScope, - MetaTable, - RootScopes, -} from '~/utils/globals'; -import NocoCache from '~/cache/NocoCache'; -import { NcError } from 'src/helpers/catchError'; export default class CustomUrl { id?: string; @@ -26,153 +17,43 @@ export default class CustomUrl { params: Pick, ncMeta = Noco.ncMeta, ) { - const condition = extractProps(params, ['id', 'view_id', 'custom_path']); - - const customUrl = await ncMeta.metaGet2( - RootScopes.ROOT, - RootScopes.ROOT, - MetaTable.CUSTOM_URLS, - condition, - ); - - return customUrl && new CustomUrl(customUrl); + return {} as CustomUrl; } public static async getOriginUrlByCustomPath( customPath: string, ncMeta = Noco.ncMeta, ) { - let customUrl = await NocoCache.get( - `${CacheScope.CUSTOM_URLS}:${customPath}`, - CacheGetType.TYPE_OBJECT, - ); - - if (!customUrl) { - customUrl = await ncMeta.metaGet2( - RootScopes.ROOT, - RootScopes.ROOT, - MetaTable.CUSTOM_URLS, - { - custom_path: customPath, - }, - ); - - if (customUrl) { - NocoCache.set(`${CacheScope.CUSTOM_URLS}:${customPath}`, customUrl); - } - } - - if (!customUrl) { - NcError.notFound(); - } - - return customUrl?.original_path; + return ''; } public static async insert( customUrl: Partial, ncMeta = Noco.ncMeta, ) { - const insertData = extractProps(customUrl, [ - 'fk_workspace_id', - 'base_id', - 'fk_model_id', - 'view_id', - 'original_path', - 'custom_path', - ]); - - const insertedCustomUrl = await ncMeta.metaInsert2( - RootScopes.ROOT, - RootScopes.ROOT, - MetaTable.CUSTOM_URLS, - insertData, - ); - - return insertedCustomUrl && new CustomUrl(insertedCustomUrl); + return {} as CustomUrl; } public static async list( params: Pick, ncMeta = Noco.ncMeta, ) { - const condition = extractProps(params, [ - 'fk_workspace_id', - 'base_id', - 'fk_model_id', - ]); - - const customUrlList = await ncMeta.metaList2( - RootScopes.ROOT, - RootScopes.ROOT, - MetaTable.CUSTOM_URLS, - { - condition, - }, - ); - - return customUrlList.map((customUrl) => new CustomUrl(customUrl)); + return [] as CustomUrl[]; } public static async update( id: string, customUrl: Partial, ncMeta = Noco.ncMeta, - ) { - const updateData = extractProps(customUrl, [ - 'original_path', - 'custom_path', - ]); - - return await ncMeta.metaUpdate( - RootScopes.ROOT, - RootScopes.ROOT, - MetaTable.CUSTOM_URLS, - updateData, - id, - ); - } + ) {} public static async checkAvailability( params: Pick, ncMeta = Noco.ncMeta, - ) { - const condition = extractProps(params, ['custom_path']); - - const customUrlList = await ncMeta.metaList2( - RootScopes.ROOT, - RootScopes.ROOT, - MetaTable.CUSTOM_URLS, - { - condition, - xcCondition: params.id - ? { - _not: { - id: { - neq: params.id, - }, - }, - } - : null, - }, - ); - - return !!customUrlList.length; - } + ) {} static async delete( customUrl: Pick, ncMeta = Noco.ncMeta, - ) { - const condition = extractProps(customUrl, ['id', 'view_id']); - - const res = await ncMeta.metaDelete( - RootScopes.ROOT, - RootScopes.ROOT, - MetaTable.CUSTOM_URLS, - condition, - ); - - return res; - } + ) {} } diff --git a/packages/nocodb/src/modules/noco.module.ts b/packages/nocodb/src/modules/noco.module.ts index fea94f19d6..fd0dde746e 100644 --- a/packages/nocodb/src/modules/noco.module.ts +++ b/packages/nocodb/src/modules/noco.module.ts @@ -16,8 +16,6 @@ import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; import { TelemetryService } from '~/services/telemetry.service'; import { AppHooksListenerService } from '~/services/app-hooks-listener.service'; import { HookHandlerService } from '~/services/hook-handler.service'; -import { CustomUrlsController } from '~/controllers/custom-urls.controller'; -import { CustomUrlsService } from '~/services/custom-urls.service'; /* User */ import { UsersController } from '~/controllers/users/users.controller'; @@ -147,8 +145,6 @@ export const nocoModuleMetadata = { controllers: [ ...(process.env.NC_WORKER_CONTAINER !== 'true' ? [ - CustomUrlsController, - /* Users */ UsersController, @@ -219,7 +215,6 @@ export const nocoModuleMetadata = { AppHooksListenerService, TelemetryService, HookHandlerService, - CustomUrlsService, /* Users */ UsersService, @@ -282,7 +277,6 @@ export const nocoModuleMetadata = { TelemetryService, HookHandlerService, JwtStrategy, - CustomUrlsService, /* Users */ UsersService, diff --git a/packages/nocodb/src/schema/swagger-v2.json b/packages/nocodb/src/schema/swagger-v2.json index 7a7660e65d..c4f943010e 100644 --- a/packages/nocodb/src/schema/swagger-v2.json +++ b/packages/nocodb/src/schema/swagger-v2.json @@ -12970,93 +12970,6 @@ "$ref": "#/components/parameters/xc-token" } ] - }, - "/api/v2/meta/custom-url/{customPath}": { - "get": { - "summary": "Get original path from custom url path", - "operationId": "get-original-path", - "description": "Get original path from custom url path", - "tags": [ - "CustomUrl", "Internal" - ], - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": {}, - "examples": { - "Example 1": { - "value": "nc/form/957b3e5b-c7fe-4805-bdb2-e4048e974f62" - } - } - } - } - }, - "400": { - "$ref": "#/components/responses/BadRequest" - } - } - }, - "parameters": [ - { - "schema": { - "type": "string" - }, - "name": "customPath", - "in": "path", - "required": true, - "description": "Custom url path" - }, - { - "$ref": "#/components/parameters/xc-token" - } - ] - }, - "/api/v2/meta/custom-url/check-path": { - "get": { - "summary": "Check custom url path availability", - "operationId": "check-availability", - "description": "Check custom url path availability", - "tags": [ - "CustomUrl", "Internal" - ], - "requestBody": { - "content": { - "application/json": { - "schema": { - "type": "object", - "properties": { - "id": { - "type": "string" - }, - "status": { - "custom_path": "string" - } - } - } - } - } - }, - "responses": { - "200": { - "description": "OK", - "content": { - "application/json": { - "schema": {}, - "examples": { - "Example 1": { - "value": true - } - } - } - } - }, - "400": { - "$ref": "#/components/responses/BadRequest" - } - } - } } }, "components": { diff --git a/packages/nocodb/src/services/custom-urls.service.ts b/packages/nocodb/src/services/custom-urls.service.ts deleted file mode 100644 index 02e55402f8..0000000000 --- a/packages/nocodb/src/services/custom-urls.service.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Injectable } from '@nestjs/common'; -import type { NcContext } from '~/interface/config'; -import { AppHooksService } from '~/services/app-hooks/app-hooks.service'; -import CustomUrl from 'src/models/CustomUrl'; - -@Injectable() -export class CustomUrlsService { - constructor(private readonly appHooksService: AppHooksService) {} - - async checkAvailability(params: Pick) { - return await CustomUrl.checkAvailability(params); - } - - async getOriginalPath(custom_path: string) { - return await CustomUrl.getOriginUrlByCustomPath(custom_path); - } -}