From 86932966fc2594d6355b08a82c567aaab530c2e7 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: review changes
---
.../dlg/share-and-collaborate/SharePage.vue | 75 ++++++++++++-------
.../src/controllers/custom-urls.controller.ts | 12 +--
packages/nocodb/src/models/CustomUrl.ts | 15 ++--
packages/nocodb/src/models/View.ts | 12 +--
packages/nocodb/src/modules/noco.module.ts | 6 ++
.../src/services/custom-urls.service.ts | 11 +--
packages/nocodb/src/services/views.service.ts | 8 +-
7 files changed, 77 insertions(+), 62 deletions(-)
diff --git a/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue b/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue
index 51198ff83b..324731fb2e 100644
--- a/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue
+++ b/packages/nc-gui/components/dlg/share-and-collaborate/SharePage.vue
@@ -16,6 +16,8 @@ const workspaceStore = useWorkspace()
const isLocked = inject(IsLockedInj, ref(false))
+const { copy } = useCopy()
+
const isUpdating = ref({
public: false,
password: false,
@@ -104,16 +106,37 @@ const togglePasswordProtected = async () => {
const isOpenCustomUrlLocal = ref(false)
const isOpenCustomUrl = computed(() => {
- return !!activeView.value?.password || isOpenCustomUrlLocal.value
+ return !!activeView.value?.custom_url_path || isOpenCustomUrlLocal.value
})
-const customUrl = computed({
- get: () => (isOpenCustomUrl.value ? activeView.value?.custom_url_path ?? '' : ''),
- set: async (value) => {
- if (!activeView.value) return
+const customUrl = ref()
- activeView.value = { ...(activeView.value as any), custom_url_path: isOpenCustomUrl.value ? value : null }
- },
+// const customUrl = computed({
+// get: () => (isOpenCustomUrl.value ? activeView.value?.custom_url_path ?? '' : ''),
+// set: async (value) => {
+// if (!activeView.value) return
+
+// activeView.value = { ...(activeView.value as any), custom_url_path: isOpenCustomUrl.value ? value : null }
+// },
+// })
+
+const dashboardUrl1 = computed(() => {
+ // get base url for workspace
+ const baseUrl = getBaseUrl(workspaceStore.activeWorkspaceId)
+
+ if (baseUrl) {
+ return `${baseUrl}${appInfo.value?.dashboardPath}`
+ }
+
+ return dashboardUrl.value
+})
+
+const copyCustomUrl = () => {
+ copy(`${dashboardUrl1.value}}#/shared/${customUrl.value}`)
+}
+
+onMounted(() => {
+ customUrl.value = activeView.value?.custom_url_path
})
const toggleCustomUrl = async () => {
@@ -121,17 +144,17 @@ const toggleCustomUrl = async () => {
if (!activeView.value) return
if (isUpdating.value.customUrl) return
- isUpdating.value.password = true
+ isUpdating.value.customUrl = true
try {
- if (passwordProtected.value) {
- activeView.value = { ...(activeView.value as any), custom_url_path: null }
+ if (isOpenCustomUrl.value) {
+ customUrl.value = null
} else {
- activeView.value = { ...(activeView.value as any), custom_url_path: '' }
+ customUrl.value = null
}
await updateSharedView()
} finally {
- isUpdating.value.password = false
+ isUpdating.value.customUrl = false
}
}
@@ -251,17 +274,6 @@ function sharedViewUrl() {
}`
}
-const dashboardUrl1 = computed(() => {
- // get base url for workspace
- const baseUrl = getBaseUrl(workspaceStore.activeWorkspaceId)
-
- if (baseUrl) {
- return `${baseUrl}${appInfo.value?.dashboardPath}`
- }
-
- return dashboardUrl.value
-})
-
const toggleViewShare = async () => {
if (!activeView.value?.id) return
@@ -328,8 +340,9 @@ async function updateSharedView() {
await $api.dbViewShare.update(activeView.value.id!, {
meta,
password: activeView.value.password,
- custom_url_path: activeView.value?.custom_url_path ?? null,
+ custom_url_path: customUrl.value ?? null,
})
+ activeView.value.custom_url_path = customUrl.value ?? null
} catch (e: any) {
message.error(await extractSdkResponseErrorMsg(e))
}
@@ -396,10 +409,20 @@ async function savePreFilledMode() {
size="small"
:bordered="false"
autocomplete="off"
- @update:value="updateSharedViewWithDebounce"
/>
-
+
+
+
+
+ {{ $t('general.copy') }}
+
+
{{ $t('general.save') }}
diff --git a/packages/nocodb/src/controllers/custom-urls.controller.ts b/packages/nocodb/src/controllers/custom-urls.controller.ts
index eb23cc7bc5..e93295eec4 100644
--- a/packages/nocodb/src/controllers/custom-urls.controller.ts
+++ b/packages/nocodb/src/controllers/custom-urls.controller.ts
@@ -9,8 +9,6 @@ import {
} from '@nestjs/common';
import { GlobalGuard } from '~/guards/global/global.guard';
import { MetaApiLimiterGuard } from '~/guards/meta-api-limiter.guard';
-import { TenantContext } from '~/decorators/tenant-context.decorator';
-import { NcContext } from '~/interface/config';
import { CustomUrlsService } from 'src/services/custom-urls.service';
@Controller()
@@ -22,23 +20,19 @@ export class CustomUrlsController {
'/api/v1/db/meta/custom-url/:customPath',
'/api/v2/meta/custom-url/:customPath',
])
- async getOriginalPath(
- @TenantContext() context: NcContext,
- @Param('customPath') customPath: string,
- ) {
- await this.customUrlsService.getOriginalPath(context, 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(
- @TenantContext() context: NcContext,
@Body()
body: {
id?: string;
custom_path?: string;
},
) {
- await this.customUrlsService.checkAvailability(context, body);
+ return await this.customUrlsService.checkAvailability(body);
}
}
diff --git a/packages/nocodb/src/models/CustomUrl.ts b/packages/nocodb/src/models/CustomUrl.ts
index 40a0111b62..2906c12fc6 100644
--- a/packages/nocodb/src/models/CustomUrl.ts
+++ b/packages/nocodb/src/models/CustomUrl.ts
@@ -7,7 +7,7 @@ import {
RootScopes,
} from '~/utils/globals';
import NocoCache from '~/cache/NocoCache';
-import { NcContext } from 'src/interface/config';
+import { NcError } from 'src/helpers/catchError';
export default class CustomUrl {
id?: string;
@@ -23,7 +23,6 @@ export default class CustomUrl {
}
public static async get(
- _context: NcContext,
params: Pick,
ncMeta = Noco.ncMeta,
) {
@@ -40,7 +39,6 @@ export default class CustomUrl {
}
public static async getOriginUrlByCustomPath(
- _context: NcContext,
customPath: string,
ncMeta = Noco.ncMeta,
) {
@@ -64,13 +62,14 @@ export default class CustomUrl {
}
}
- console.log('custom url', customUrl);
+ if (!customUrl) {
+ NcError.notFound();
+ }
- return customUrl && new CustomUrl(customUrl);
+ return customUrl?.original_path;
}
public static async insert(
- _context: NcContext,
customUrl: Partial,
ncMeta = Noco.ncMeta,
) {
@@ -94,7 +93,6 @@ export default class CustomUrl {
}
public static async list(
- _context: NcContext,
params: Pick,
ncMeta = Noco.ncMeta,
) {
@@ -117,7 +115,6 @@ export default class CustomUrl {
}
public static async update(
- _context: NcContext,
id: string,
customUrl: Partial,
ncMeta = Noco.ncMeta,
@@ -137,7 +134,6 @@ export default class CustomUrl {
}
public static async checkAvailability(
- _context: NcContext,
params: Pick,
ncMeta = Noco.ncMeta,
) {
@@ -165,7 +161,6 @@ export default class CustomUrl {
}
static async delete(
- _context: NcContext,
customUrl: Pick,
ncMeta = Noco.ncMeta,
) {
diff --git a/packages/nocodb/src/models/View.ts b/packages/nocodb/src/models/View.ts
index cf50866d74..375fd6d769 100644
--- a/packages/nocodb/src/models/View.ts
+++ b/packages/nocodb/src/models/View.ts
@@ -131,7 +131,7 @@ export default class View implements ViewType {
view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) {
- const customUrl = await CustomUrl.get(context, {
+ const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@@ -181,7 +181,7 @@ export default class View implements ViewType {
if (view) {
if (view.fk_custom_url_id) {
- const customUrl = await CustomUrl.get(context, {
+ const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@@ -229,7 +229,7 @@ export default class View implements ViewType {
if (view) {
view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) {
- const customUrl = await CustomUrl.get(context, {
+ const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@@ -268,7 +268,7 @@ export default class View implements ViewType {
view.meta = parseMetaProp(view);
if (view.fk_custom_url_id) {
- const customUrl = await CustomUrl.get(context, {
+ const customUrl = await CustomUrl.get({
id: view.fk_custom_url_id,
});
@@ -1283,7 +1283,7 @@ export default class View implements ViewType {
viewId,
);
- await CustomUrl.delete(context, { view_id: viewId });
+ await CustomUrl.delete({ view_id: viewId });
await NocoCache.update(`${CacheScope.VIEW}:${viewId}`, {
uuid: null,
@@ -1448,7 +1448,7 @@ export default class View implements ViewType {
}
if (view.fk_custom_url_id) {
- await CustomUrl.delete(context, { id: view.fk_custom_url_id });
+ await CustomUrl.delete({ id: view.fk_custom_url_id });
}
// on update, delete any optimised single query cache
diff --git a/packages/nocodb/src/modules/noco.module.ts b/packages/nocodb/src/modules/noco.module.ts
index fd0dde746e..fea94f19d6 100644
--- a/packages/nocodb/src/modules/noco.module.ts
+++ b/packages/nocodb/src/modules/noco.module.ts
@@ -16,6 +16,8 @@ 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';
@@ -145,6 +147,8 @@ export const nocoModuleMetadata = {
controllers: [
...(process.env.NC_WORKER_CONTAINER !== 'true'
? [
+ CustomUrlsController,
+
/* Users */
UsersController,
@@ -215,6 +219,7 @@ export const nocoModuleMetadata = {
AppHooksListenerService,
TelemetryService,
HookHandlerService,
+ CustomUrlsService,
/* Users */
UsersService,
@@ -277,6 +282,7 @@ export const nocoModuleMetadata = {
TelemetryService,
HookHandlerService,
JwtStrategy,
+ CustomUrlsService,
/* Users */
UsersService,
diff --git a/packages/nocodb/src/services/custom-urls.service.ts b/packages/nocodb/src/services/custom-urls.service.ts
index b5c1338715..02e55402f8 100644
--- a/packages/nocodb/src/services/custom-urls.service.ts
+++ b/packages/nocodb/src/services/custom-urls.service.ts
@@ -7,14 +7,11 @@ import CustomUrl from 'src/models/CustomUrl';
export class CustomUrlsService {
constructor(private readonly appHooksService: AppHooksService) {}
- async checkAvailability(
- context: NcContext,
- params: Pick,
- ) {
- return await CustomUrl.checkAvailability(context, params);
+ async checkAvailability(params: Pick) {
+ return await CustomUrl.checkAvailability(params);
}
- async getOriginalPath(context: NcContext, custom_path: string) {
- return await CustomUrl.getOriginUrlByCustomPath(context, custom_path);
+ async getOriginalPath(custom_path: string) {
+ return await CustomUrl.getOriginUrlByCustomPath(custom_path);
}
}
diff --git a/packages/nocodb/src/services/views.service.ts b/packages/nocodb/src/services/views.service.ts
index 1fd3cbce5b..4a4fd42ec1 100644
--- a/packages/nocodb/src/services/views.service.ts
+++ b/packages/nocodb/src/services/views.service.ts
@@ -273,22 +273,22 @@ export class ViewsService {
NcError.viewNotFound(param.viewId);
}
- let customUrl: CustomUrl | undefined = await CustomUrl.get(context, {
+ let customUrl: CustomUrl | undefined = await CustomUrl.get({
view_id: view.id,
id: view.fk_custom_url_id,
});
if (customUrl?.id) {
if (param.sharedView.custom_url_path) {
- await CustomUrl.update(context, view.fk_custom_url_id, {
+ await CustomUrl.update(view.fk_custom_url_id, {
custom_path: param.sharedView.custom_url_path,
});
} else {
- await CustomUrl.delete(context, { id: view.fk_custom_url_id });
+ await CustomUrl.delete({ id: view.fk_custom_url_id });
customUrl = undefined;
}
} else {
- customUrl = await CustomUrl.insert(context, {
+ customUrl = await CustomUrl.insert({
fk_workspace_id: view.fk_workspace_id,
base_id: view.base_id,
fk_model_id: view.fk_model_id,