From 83d20e70cb343a3c191b7be8ddc610f3d98265e4 Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 17 Feb 2023 10:09:02 +0300 Subject: [PATCH 01/76] fix: sql client type calls Signed-off-by: mertmit --- packages/nocodb/src/lib/meta/api/tableApis.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/meta/api/tableApis.ts b/packages/nocodb/src/lib/meta/api/tableApis.ts index 8eb3d6a10e..8e02d5aca8 100644 --- a/packages/nocodb/src/lib/meta/api/tableApis.ts +++ b/packages/nocodb/src/lib/meta/api/tableApis.ts @@ -151,7 +151,7 @@ export async function tableCreate(req: Request, res) { const sqlClient = await NcConnectionMgrv2.getSqlClient(base); let tableNameLengthLimit = 255; - const sqlClientType = sqlClient.clientType; + const sqlClientType = sqlClient.knex.clientType(); if (sqlClientType === 'mysql2' || sqlClientType === 'mysql') { tableNameLengthLimit = 64; } else if (sqlClientType === 'pg') { @@ -298,7 +298,7 @@ export async function tableUpdate(req: Request, res) { const sqlClient = await NcConnectionMgrv2.getSqlClient(base); let tableNameLengthLimit = 255; - const sqlClientType = sqlClient.clientType; + const sqlClientType = sqlClient.knex.clientType(); if (sqlClientType === 'mysql2' || sqlClientType === 'mysql') { tableNameLengthLimit = 64; } else if (sqlClientType === 'pg') { From ad0832ec15ae7f6c3c94baa06425b5b7302a99f3 Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 17 Feb 2023 11:02:04 +0300 Subject: [PATCH 02/76] fix: ts types for sql clients Signed-off-by: mertmit --- .../src/lib/db/sql-client/lib/oracle/OracleClient.ts | 2 +- packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts | 10 +++++++++- packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2.ts | 2 +- packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts | 2 +- .../src/lib/db/sql-migrator/lib/KnexMigratorv2.ts | 7 ++++--- .../src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts | 9 ++++++++- packages/nocodb/src/lib/meta/NcMetaMgr.ts | 2 +- packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts | 2 +- .../nocodb/src/lib/utils/common/NcConnectionMgr.ts | 2 +- .../nocodb/src/lib/utils/common/NcConnectionMgrv2.ts | 2 +- 10 files changed, 28 insertions(+), 12 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts index 34779ebbe8..4f01353ba0 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/oracle/OracleClient.ts @@ -1913,7 +1913,7 @@ class OracleClient extends KnexClient { * @returns {Number} code * @returns {String} message */ - async totalRecords(_args: any = {}) { + async totalRecords(_args: any = {}): Promise { // @ts-ignore const func = this.totalRecords.name; throw new Error('Function not supported for oracle yet'); diff --git a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts index 9bbd2fa238..02b5c4e343 100644 --- a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts +++ b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts @@ -17,6 +17,14 @@ import NcConnectionMgr from '../../utils/common/NcConnectionMgr'; import { customAlphabet } from 'nanoid'; import Debug from '../util/Debug'; import Result from '../util/Result'; + +import type MssqlClient from '../sql-client/lib/mssql/MssqlClient'; +import type MysqlClient from '../sql-client/lib/mysql/MysqlClient'; +import type OracleClient from '../sql-client/lib/oracle/OracleClient'; +import type PGClient from '../sql-client/lib/pg/PgClient'; +import type SnowflakeClient from '../sql-client/lib/snowflake/SnowflakeClient'; +import type SqliteClient from '../sql-client/lib/sqlite/SqliteClient'; + const randomID = customAlphabet('1234567890abcdefghijklmnopqrstuvwxyz_', 20); const log = new Debug('SqlMgr'); @@ -337,7 +345,7 @@ export default class SqlMgr { * @returns * @memberof SqlMgr */ - public async projectGetSqlClient(args) { + public async projectGetSqlClient(args): Promise { const func = this.projectGetSqlClient.name; log.api(`${func}:args:`, args); diff --git a/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2.ts b/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2.ts index 89ee530036..8c7d189461 100644 --- a/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2.ts +++ b/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2.ts @@ -118,7 +118,7 @@ export default class SqlMgrv2 { return sqlMigrationStatements; } - protected async getSqlClient(base: Base): Promise { + protected async getSqlClient(base: Base) { return NcConnectionMgrv2.getSqlClient(base); } } diff --git a/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts b/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts index a5def5c184..82852fed52 100644 --- a/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts +++ b/packages/nocodb/src/lib/db/sql-mgr/v2/SqlMgrv2Trans.ts @@ -52,7 +52,7 @@ export default class SqlMgrv2Trans extends SqlMgrv2 { } } - protected async getSqlClient(base: Base): Promise { + protected async getSqlClient(base: Base) { return NcConnectionMgrv2.getSqlClient(base, this.trx); } diff --git a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts index cc1ad02a34..cdf4d8f1f1 100644 --- a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts +++ b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts @@ -1,6 +1,7 @@ import fs from 'fs'; import path from 'path'; import { promisify } from 'util'; +import { Knex } from 'knex'; import glob from 'glob'; import SqlClientFactory from '../../sql-client/lib/SqlClientFactory'; @@ -428,7 +429,7 @@ export default class KnexMigratorv2 { // } } - protected async getSqlClient(base: Base): Promise { + protected async getSqlClient(base: Base) { return NcConnectionMgrv2.getSqlClient(base); } @@ -753,7 +754,7 @@ export default class KnexMigratorv2 { const vm = this; const trx = sqlClient.knex.isTransaction - ? sqlClient.knex + ? sqlClient.knex as Knex.Transaction : await sqlClient.knex.transaction(); try { for (const query of upStatements) { @@ -920,7 +921,7 @@ export default class KnexMigratorv2 { const vm = this; const trx = sqlClient.knex.isTransaction - ? sqlClient.knex + ? sqlClient.knex as Knex.Transaction : await sqlClient.knex.transaction(); try { for (const query of downStatements) { diff --git a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts index 7bfe6a2bdc..037cf6d559 100644 --- a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts +++ b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts @@ -11,6 +11,13 @@ import Noco from '../../../Noco'; import { XKnex } from '../../sql-data-mapper'; import NcMetaIO from '../../../meta/NcMetaIO'; +import type MssqlClient from '../../sql-client/lib/mssql/MssqlClient'; +import type MysqlClient from '../../sql-client/lib/mysql/MysqlClient'; +import type OracleClient from '../../sql-client/lib/oracle/OracleClient'; +import type PGClient from '../../sql-client/lib/pg/PgClient'; +import type SnowflakeClient from '../../sql-client/lib/snowflake/SnowflakeClient'; +import type SqliteClient from '../../sql-client/lib/sqlite/SqliteClient'; + export default class KnexMigratorv2Tans extends KnexMigratorv2 { protected sqlClient: any; protected ncMeta: NcMetaIO; @@ -24,7 +31,7 @@ export default class KnexMigratorv2Tans extends KnexMigratorv2 { protected get metaDb(): XKnex { return this.ncMeta.knex || Noco.ncMeta.knex; } - protected async getSqlClient(base: Base): Promise { + protected async getSqlClient(base: Base): Promise { return this.sqlClient || NcConnectionMgrv2.getSqlClient(base); } } diff --git a/packages/nocodb/src/lib/meta/NcMetaMgr.ts b/packages/nocodb/src/lib/meta/NcMetaMgr.ts index 02b2d7b607..aecaff7189 100644 --- a/packages/nocodb/src/lib/meta/NcMetaMgr.ts +++ b/packages/nocodb/src/lib/meta/NcMetaMgr.ts @@ -2909,7 +2909,7 @@ export default class NcMetaMgr { } } - protected async projectGetSqlClient(args): Promise { + protected async projectGetSqlClient(args) { const builder = this.getBuilder(args); return builder?.getSqlClient(); } diff --git a/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts b/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts index 210eb61a32..69294bdfc3 100644 --- a/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts +++ b/packages/nocodb/src/lib/utils/common/BaseApiBuilder.ts @@ -187,7 +187,7 @@ export default abstract class BaseApiBuilder return this.connectionConfig?.meta?.dbAlias; } - public async getSqlClient(): Promise { + public async getSqlClient() { return NcConnectionMgr.getSqlClient({ dbAlias: this.dbAlias, env: this.config.env, diff --git a/packages/nocodb/src/lib/utils/common/NcConnectionMgr.ts b/packages/nocodb/src/lib/utils/common/NcConnectionMgr.ts index 9c9c4c55a0..ca7f4fe53d 100644 --- a/packages/nocodb/src/lib/utils/common/NcConnectionMgr.ts +++ b/packages/nocodb/src/lib/utils/common/NcConnectionMgr.ts @@ -149,7 +149,7 @@ export default class NcConnectionMgr { env: string; config: NcConfig; projectId: string; - }): Promise { + }) { const knex = this.get({ dbAlias, env, diff --git a/packages/nocodb/src/lib/utils/common/NcConnectionMgrv2.ts b/packages/nocodb/src/lib/utils/common/NcConnectionMgrv2.ts index 06386e3391..bb55673cf6 100644 --- a/packages/nocodb/src/lib/utils/common/NcConnectionMgrv2.ts +++ b/packages/nocodb/src/lib/utils/common/NcConnectionMgrv2.ts @@ -149,7 +149,7 @@ export default class NcConnectionMgrv2 { // return config?.envs?.[env]?.db?.find(db => db?.meta?.dbAlias === dbAlias); // } - public static async getSqlClient(base: Base, _knex = null): Promise { + public static async getSqlClient(base: Base, _knex = null) { const knex = _knex || this.get(base); return SqlClientFactory.create({ knex, From e54462d9de36a2f2feeecc0148af9eef487a96d3 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Feb 2023 18:12:15 +0800 Subject: [PATCH 03/76] docs: add NC_DISABLE_AUDIT --- .../getting-started/environment-variables.md | 103 +++++++++--------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/packages/noco-docs/content/en/getting-started/environment-variables.md b/packages/noco-docs/content/en/getting-started/environment-variables.md index 19cf938fe2..5ce104419c 100644 --- a/packages/noco-docs/content/en/getting-started/environment-variables.md +++ b/packages/noco-docs/content/en/getting-started/environment-variables.md @@ -13,54 +13,55 @@ For production usecases, it is **recommended** to configure - `NC_PUBLIC_URL`, - `NC_REDIS_URL` -| Variable | Comments | If absent | | -|------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|---| -| NC_DB | See our database URLs | A local SQLite will be created in root folder if `NC_DB` is not provided | | -| NC_DB_JSON | Can be used instead of `NC_DB` and value should be valid knex connection JSON | | | -| NC_DB_JSON_FILE | Can be used instead of `NC_DB` and value should be a valid path to knex connection JSON | | | -| DATABASE_URL | JDBC URL Format. Can be used instead of NC_DB. | | | -| DATABASE_URL_FILE | Can be used instead of DATABASE_URL: path to file containing JDBC URL Format. | | | -| NC_AUTH_JWT_SECRET | JWT secret used for auth and storing other secrets | A random secret will be generated | | -| PORT | For setting app running port | `8080` | | -| DB_QUERY_LIMIT_DEFAULT | Default pagination limit | 25 | | -| DB_QUERY_LIMIT_MAX | Maximum allowed pagination limit | 1000 | | -| DB_QUERY_LIMIT_MIN | Minimum allowed pagination limit | 1 | | -| NC_TOOL_DIR | App directory to keep metadata and app related files | Defaults to current working directory. In docker maps to `/usr/app/data/` for mounting volume. | | -| NC_PUBLIC_URL | Used for sending Email invitations | Best guess from http request params | | -| NC_JWT_EXPIRES_IN | JWT token expiry time | `10h` | | -| NC_CONNECT_TO_EXTERNAL_DB_DISABLED | Disable Project creation with external database | | | -| NC_INVITE_ONLY_SIGNUP | Removed since version 0.99.0 and now it's recommended to use [super admin settings menu](/setup-and-usages/account-settings#enable--disable-signup). Allow users to signup only via invite url, value should be any non-empty string. | | | -| NUXT_PUBLIC_NC_BACKEND_URL | Custom Backend URL | ``http://localhost:8080`` will be used | | -| NC_REQUEST_BODY_SIZE | Request body size [limit](https://expressjs.com/en/resources/middleware/body-parser.html#limit) | `1048576` | | -| NC_EXPORT_MAX_TIMEOUT | After NC_EXPORT_MAX_TIMEOUT csv gets downloaded in batches | Default value 5000(in millisecond) will be used | | -| NC_DISABLE_TELE | Disable telemetry | | | -| NC_DASHBOARD_URL | Custom dashboard url path | `/dashboard` | | -| NC_GOOGLE_CLIENT_ID | Google client id to enable google authentication | | | -| NC_GOOGLE_CLIENT_SECRET | Google client secret to enable google authentication | | | -| NC_MIGRATIONS_DISABLED | Disable NocoDB migration | | | -| NC_MIN | If set to any non-empty string the default splash screen(initial welcome animation) and matrix screensaver will disable | | | -| NC_SENTRY_DSN | For Sentry monitoring | | | -| NC_REDIS_URL | Custom Redis URL. Example: `redis://:authpassword@127.0.0.1:6380/4` | Meta data will be stored in memory | | -| NC_DISABLE_ERR_REPORT | Disable error reporting | | | -| NC_DISABLE_CACHE | To be used only while debugging. On setting this to `true` - meta data be fetched from db instead of redis/cache. | `false` | | -| NC_BASEURL_INTERNAL | Used as base url for internal(server) API calls | Default value in docker will be `http://localhost:$PORT` and in all other case it's populated from request object | | -| AWS_ACCESS_KEY_ID | For Litestream - S3 access key id | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | -| AWS_SECRET_ACCESS_KEY | For Litestream - S3 secret access key | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | -| AWS_BUCKET | For Litestream - S3 bucket | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | -| AWS_BUCKET_PATH | For Litestream - S3 bucket path (like folder within S3 bucket) | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | -| NC_SMTP_FROM | For SMTP plugin - Email sender address | | | -| NC_SMTP_HOST | For SMTP plugin - SMTP host value | | | -| NC_SMTP_PORT | For SMTP plugin - SMTP port value | | | -| NC_SMTP_USERNAME | For SMTP plugin (Optional) - SMTP username value for authentication | | | -| NC_SMTP_PASSWORD | For SMTP plugin (Optional) - SMTP password value for authentication | | | -| NC_SMTP_SECURE | For SMTP plugin (Optional) - To enable secure set value as `true` any other value treated as false | | | -| NC_SMTP_IGNORE_TLS | For SMTP plugin (Optional) - To ignore tls set value as `true` any other value treated as false. For more info visit https://nodemailer.com/smtp/ | | | -| NC_S3_BUCKET_NAME | For S3 storage plugin - AWS S3 bucket name | | | -| NC_S3_REGION | For S3 storage plugin - AWS S3 region | | | -| NC_S3_ACCESS_KEY | For S3 storage plugin - AWS access key credential for accessing resource | | | -| NC_S3_ACCESS_SECRET | For S3 storage plugin - AWS access secret credential for accessing resource | | | -| NC_ADMIN_EMAIL | For updating/creating super admin with provided email and password | | | -| NC_ATTACHMENT_FIELD_SIZE | For setting the attachment field size(in Bytes) | Defaults to 20MB | | -| NC_ADMIN_PASSWORD | For updating/creating super admin with provided email and password. Your password should have at least 8 letters with one uppercase, one number and one special letter(Allowed special chars $&+,:;=?@#\|'.^*()%!_-" ) | | | -| NODE_OPTIONS | For passing Node.js [options](https://nodejs.org/api/cli.html#node_optionsoptions) to instance | | | -| NC_MINIMAL_DBS | Create a new SQLite file for each project. All the db files are stored in `nc_minimal_dbs` folder in current working directory. (This option restricts project creation on external sources) | | | +| Variable | Comments | If absent | | +|---|---|---|---| +| NC_DB | See our database URLs | A local SQLite will be created in root folder if `NC_DB` is not provided | | +| NC_DB_JSON | Can be used instead of `NC_DB` and value should be valid knex connection JSON | | | +| NC_DB_JSON_FILE | Can be used instead of `NC_DB` and value should be a valid path to knex connection JSON | | | +| DATABASE_URL | JDBC URL Format. Can be used instead of NC_DB. | | | +| DATABASE_URL_FILE | Can be used instead of DATABASE_URL: path to file containing JDBC URL Format. | | | +| NC_AUTH_JWT_SECRET | JWT secret used for auth and storing other secrets | A random secret will be generated | | +| PORT | For setting app running port | `8080` | | +| DB_QUERY_LIMIT_DEFAULT | Default pagination limit | 25 | | +| DB_QUERY_LIMIT_MAX | Maximum allowed pagination limit | 1000 | | +| DB_QUERY_LIMIT_MIN | Minimum allowed pagination limit | 1 | | +| NC_TOOL_DIR | App directory to keep metadata and app related files | Defaults to current working directory. In docker maps to `/usr/app/data/` for mounting volume. | | +| NC_PUBLIC_URL | Used for sending Email invitations | Best guess from http request params | | +| NC_JWT_EXPIRES_IN | JWT token expiry time | `10h` | | +| NC_CONNECT_TO_EXTERNAL_DB_DISABLED | Disable Project creation with external database | | | +| NC_INVITE_ONLY_SIGNUP | Removed since version 0.99.0 and now it's recommended to use [super admin settings menu](/setup-and-usages/account-settings#enable--disable-signup). Allow users to signup only via invite url, value should be any non-empty string. | | | +| NUXT_PUBLIC_NC_BACKEND_URL | Custom Backend URL | ``http://localhost:8080`` will be used | | +| NC_REQUEST_BODY_SIZE | Request body size [limit](https://expressjs.com/en/resources/middleware/body-parser.html#limit) | `1048576` | | +| NC_EXPORT_MAX_TIMEOUT | After NC_EXPORT_MAX_TIMEOUT csv gets downloaded in batches | Default value 5000(in millisecond) will be used | | +| NC_DISABLE_TELE | Disable telemetry | | | +| NC_DASHBOARD_URL | Custom dashboard url path | `/dashboard` | | +| NC_GOOGLE_CLIENT_ID | Google client id to enable google authentication | | | +| NC_GOOGLE_CLIENT_SECRET | Google client secret to enable google authentication | | | +| NC_MIGRATIONS_DISABLED | Disable NocoDB migration | | | +| NC_MIN | If set to any non-empty string the default splash screen(initial welcome animation) and matrix screensaver will disable | | | +| NC_SENTRY_DSN | For Sentry monitoring | | | +| NC_REDIS_URL | Custom Redis URL. Example: `redis://:authpassword@127.0.0.1:6380/4` | Meta data will be stored in memory | | +| NC_DISABLE_ERR_REPORT | Disable error reporting | | | +| NC_DISABLE_CACHE | To be used only while debugging. On setting this to `true` - meta data be fetched from db instead of redis/cache. | `false` | | +| NC_BASEURL_INTERNAL | Used as base url for internal(server) API calls | Default value in docker will be `http://localhost:$PORT` and in all other case it's populated from request object | | +| AWS_ACCESS_KEY_ID | For Litestream - S3 access key id | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | +| AWS_SECRET_ACCESS_KEY | For Litestream - S3 secret access key | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | +| AWS_BUCKET | For Litestream - S3 bucket | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | +| AWS_BUCKET_PATH | For Litestream - S3 bucket path (like folder within S3 bucket) | If Litestream is configured and `NC_DB` is not present. SQLite gets backed up to S3 | | +| NC_SMTP_FROM | For SMTP plugin - Email sender address | | | +| NC_SMTP_HOST | For SMTP plugin - SMTP host value | | | +| NC_SMTP_PORT | For SMTP plugin - SMTP port value | | | +| NC_SMTP_USERNAME | For SMTP plugin (Optional) - SMTP username value for authentication | | | +| NC_SMTP_PASSWORD | For SMTP plugin (Optional) - SMTP password value for authentication | | | +| NC_SMTP_SECURE | For SMTP plugin (Optional) - To enable secure set value as `true` any other value treated as false | | | +| NC_SMTP_IGNORE_TLS | For SMTP plugin (Optional) - To ignore tls set value as `true` any other value treated as false. For more info visit https://nodemailer.com/smtp/ | | | +| NC_S3_BUCKET_NAME | For S3 storage plugin - AWS S3 bucket name | | | +| NC_S3_REGION | For S3 storage plugin - AWS S3 region | | | +| NC_S3_ACCESS_KEY | For S3 storage plugin - AWS access key credential for accessing resource | | | +| NC_S3_ACCESS_SECRET | For S3 storage plugin - AWS access secret credential for accessing resource | | | +| NC_ADMIN_EMAIL | For updating/creating super admin with provided email and password | | | +| NC_ATTACHMENT_FIELD_SIZE | For setting the attachment field size(in Bytes) | Defaults to 20MB | | +| NC_ADMIN_PASSWORD | For updating/creating super admin with provided email and password. Your password should have at least 8 letters with one uppercase, one number and one special letter(Allowed special chars $&+,:;=?@#\|'.^*()%!_-" ) | | | +| NODE_OPTIONS | For passing Node.js [options](https://nodejs.org/api/cli.html#node_optionsoptions) to instance | | | +| NC_MINIMAL_DBS | Create a new SQLite file for each project. All the db files are stored in `nc_minimal_dbs` folder in current working directory. (This option restricts project creation on external sources) | | | +| NC_DISABLE_AUDIT | Disable Audit Log | `false` | | \ No newline at end of file From 2ec82f0972525e4e531619546ebc135749ee2211 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Feb 2023 18:12:32 +0800 Subject: [PATCH 04/76] feat(nc-gui): add auditEnabled in global --- packages/nc-gui/composables/useGlobal/state.ts | 1 + packages/nc-gui/composables/useGlobal/types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/nc-gui/composables/useGlobal/state.ts b/packages/nc-gui/composables/useGlobal/state.ts index 2b1f7bc036..df6e886e85 100644 --- a/packages/nc-gui/composables/useGlobal/state.ts +++ b/packages/nc-gui/composables/useGlobal/state.ts @@ -94,6 +94,7 @@ export function useGlobalState(storageKey = 'nocodb-gui-v2'): State { oneClick: false, projectHasAdmin: false, teleEnabled: true, + auditEnabled: true, type: 'nocodb', version: '0.0.0', ncAttachmentFieldSize: 20, diff --git a/packages/nc-gui/composables/useGlobal/types.ts b/packages/nc-gui/composables/useGlobal/types.ts index 9ef6ab3ddb..584b2ca9ec 100644 --- a/packages/nc-gui/composables/useGlobal/types.ts +++ b/packages/nc-gui/composables/useGlobal/types.ts @@ -16,6 +16,7 @@ export interface AppInfo { oneClick: boolean projectHasAdmin: boolean teleEnabled: boolean + auditEnabled: boolean type: string version: string ee?: boolean From c22e8fff5af062a9bb6770fb8978122d2abcfa8f Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Feb 2023 18:12:56 +0800 Subject: [PATCH 05/76] feat(nocodb): add auditEnabled in appInfo --- packages/nocodb/src/lib/meta/api/utilApis.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nocodb/src/lib/meta/api/utilApis.ts b/packages/nocodb/src/lib/meta/api/utilApis.ts index b7a9f0d601..1ae19d2640 100644 --- a/packages/nocodb/src/lib/meta/api/utilApis.ts +++ b/packages/nocodb/src/lib/meta/api/utilApis.ts @@ -54,6 +54,7 @@ export async function appInfo(req: Request, res: Response) { timezone: defaultConnectionConfig.timezone, ncMin: !!process.env.NC_MIN, teleEnabled: !process.env.NC_DISABLE_TELE, + auditEnabled: !process.env.NC_DISABLE_AUDIT, ncSiteUrl: (req as any).ncSiteUrl, ee: Noco.isEE(), ncAttachmentFieldSize: NC_ATTACHMENT_FIELD_SIZE, From b9000163fcf8ba0d0ba77613a686184e2e36e0d7 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Feb 2023 18:43:21 +0800 Subject: [PATCH 06/76] docs: add content to show how to disable audit logs --- packages/noco-docs/content/en/setup-and-usages/audit.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/noco-docs/content/en/setup-and-usages/audit.md b/packages/noco-docs/content/en/setup-and-usages/audit.md index 23b3c0e96e..191b5e7d9d 100644 --- a/packages/noco-docs/content/en/setup-and-usages/audit.md +++ b/packages/noco-docs/content/en/setup-and-usages/audit.md @@ -10,6 +10,10 @@ menuTitle: 'Team & Settings > Audit' We are keeping all the user operation logs under Audit. To access it, click the down arrow button next to Project Name on the top left side, then select `Team & Settings`. + +We can disable audit logs by setting `NC_DISABLE_AUDIT` to `true`. + + image Then, under SETTINGS, click `Audit`. From 84e1bfc1829999c98294cfbf08f1b7635b985457 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Fri, 17 Feb 2023 18:43:39 +0800 Subject: [PATCH 07/76] feat(nc-gui): show the audit log disabled message --- .../nc-gui/components/dashboard/settings/AuditTab.vue | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/components/dashboard/settings/AuditTab.vue b/packages/nc-gui/components/dashboard/settings/AuditTab.vue index 389b5e02f6..124716685f 100644 --- a/packages/nc-gui/components/dashboard/settings/AuditTab.vue +++ b/packages/nc-gui/components/dashboard/settings/AuditTab.vue @@ -1,7 +1,7 @@ + From 746398bb7e2dffdd97b2f2cebf11b2356b0a57e8 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 20 Feb 2023 21:13:04 +0800 Subject: [PATCH 71/76] fix(nocodb): add missing id --- packages/nocodb/src/lib/models/SelectOption.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/nocodb/src/lib/models/SelectOption.ts b/packages/nocodb/src/lib/models/SelectOption.ts index baf25e2672..fa24d06e50 100644 --- a/packages/nocodb/src/lib/models/SelectOption.ts +++ b/packages/nocodb/src/lib/models/SelectOption.ts @@ -17,12 +17,8 @@ export default class SelectOption { data: Partial, ncMeta = Noco.ncMeta ) { - // title: string; - // fk_column_id: string; - // color: string; - // order: number; - const insertObj = extractProps(data, [ + 'id', 'title', 'fk_column_id', 'color', From 2bee197f29c1396ec56c965541839575fbe3cd1c Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 20 Feb 2023 22:13:26 +0800 Subject: [PATCH 72/76] fix(nocodb): apply !!insertObj.mm even undefined --- packages/nocodb/src/lib/models/Model.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/nocodb/src/lib/models/Model.ts b/packages/nocodb/src/lib/models/Model.ts index 4e937d14b6..2412d6259d 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -114,9 +114,7 @@ export default class Model implements TableType { 'id', ]); - if (insertObj.mm) { - insertObj.mm = !!insertObj.mm; - } + insertObj.mm = !!insertObj.mm; if (!insertObj.order) { insertObj.order = await ncMeta.metaGetNextOrder( From 0141c5024ed632929692d6187cfa4114031a66c4 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 20 Feb 2023 23:42:20 +0800 Subject: [PATCH 73/76] fix(nocodb): add missing meta in extractProps --- packages/nocodb/src/lib/models/FormView.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/nocodb/src/lib/models/FormView.ts b/packages/nocodb/src/lib/models/FormView.ts index 5f10ce1803..ad155f4434 100644 --- a/packages/nocodb/src/lib/models/FormView.ts +++ b/packages/nocodb/src/lib/models/FormView.ts @@ -68,6 +68,7 @@ export default class FormView implements FormType { 'logo_url', 'submit_another_form', 'show_blank_form', + 'meta', ]); if (insertObj.meta) { insertObj.meta = serializeJSON(insertObj.meta); @@ -103,6 +104,7 @@ export default class FormView implements FormType { 'show_blank_form', 'meta', ]); + if (o) { o = { ...o, ...updateObj }; // set cache From 360631e2aab2064b94c33b6e0f2bbb1e4ddd1f9f Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 20 Feb 2023 23:45:28 +0800 Subject: [PATCH 74/76] refactor(nocodb): stringify if input is object --- packages/nocodb/src/lib/models/KanbanView.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/nocodb/src/lib/models/KanbanView.ts b/packages/nocodb/src/lib/models/KanbanView.ts index d72a1b46f8..6ac1b65d09 100644 --- a/packages/nocodb/src/lib/models/KanbanView.ts +++ b/packages/nocodb/src/lib/models/KanbanView.ts @@ -108,11 +108,8 @@ export default class KanbanView implements KanbanType { 'meta', ]); - if (updateObj.meta) { - updateObj.meta = - typeof updateObj.meta === 'string' - ? updateObj.meta - : JSON.stringify(updateObj.meta ?? {}); + if (updateObj.meta && typeof updateObj.meta === 'object') { + updateObj.meta = JSON.stringify(updateObj.meta ?? {}); } if (o) { From fc4ac7a157b02ed526c7776e216dc6bbdf524bf5 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 20 Feb 2023 23:46:53 +0800 Subject: [PATCH 75/76] fix(nocodb): add missing type props --- packages/nocodb/src/lib/models/Model.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/nocodb/src/lib/models/Model.ts b/packages/nocodb/src/lib/models/Model.ts index 2412d6259d..43b5c7a77f 100644 --- a/packages/nocodb/src/lib/models/Model.ts +++ b/packages/nocodb/src/lib/models/Model.ts @@ -109,6 +109,7 @@ export default class Model implements TableType { 'title', 'mm', 'order', + 'type', 'created_at', 'updated_at', 'id', From 9c6d2af45a71d43f142386607bfa12d66b3a6a24 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Tue, 21 Feb 2023 11:31:27 +0530 Subject: [PATCH 76/76] chore: lint Signed-off-by: Pranav C --- .../components/virtual-cell/components/ListItems.vue | 1 - packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts | 11 ++++++++++- .../src/lib/db/sql-migrator/lib/KnexMigratorv2.ts | 6 +++--- .../src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts | 11 ++++++++++- .../nocodb/src/lib/meta/api/helpers/populateMeta.ts | 2 +- .../src/lib/meta/helpers/mapDefaultDisplayValue.ts | 8 ++++---- .../lib/version-upgrader/ncStickyColumnUpgrader.ts | 10 +++++----- 7 files changed, 33 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui/components/virtual-cell/components/ListItems.vue b/packages/nc-gui/components/virtual-cell/components/ListItems.vue index 6122bf9357..2df6f5702d 100644 --- a/packages/nc-gui/components/virtual-cell/components/ListItems.vue +++ b/packages/nc-gui/components/virtual-cell/components/ListItems.vue @@ -252,7 +252,6 @@ watch(vModel, (nextVal) => { - diff --git a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts index 02b5c4e343..3f6a85b9c2 100644 --- a/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts +++ b/packages/nocodb/src/lib/db/sql-mgr/SqlMgr.ts @@ -345,7 +345,16 @@ export default class SqlMgr { * @returns * @memberof SqlMgr */ - public async projectGetSqlClient(args): Promise { + public async projectGetSqlClient( + args + ): Promise< + | SnowflakeClient + | MysqlClient + | SqliteClient + | MssqlClient + | OracleClient + | PGClient + > { const func = this.projectGetSqlClient.name; log.api(`${func}:args:`, args); diff --git a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts index cdf4d8f1f1..d32a40d1d0 100644 --- a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts +++ b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2.ts @@ -1,7 +1,7 @@ import fs from 'fs'; import path from 'path'; import { promisify } from 'util'; -import { Knex } from 'knex'; +import { Knex } from 'knex'; import glob from 'glob'; import SqlClientFactory from '../../sql-client/lib/SqlClientFactory'; @@ -754,7 +754,7 @@ export default class KnexMigratorv2 { const vm = this; const trx = sqlClient.knex.isTransaction - ? sqlClient.knex as Knex.Transaction + ? (sqlClient.knex as Knex.Transaction) : await sqlClient.knex.transaction(); try { for (const query of upStatements) { @@ -921,7 +921,7 @@ export default class KnexMigratorv2 { const vm = this; const trx = sqlClient.knex.isTransaction - ? sqlClient.knex as Knex.Transaction + ? (sqlClient.knex as Knex.Transaction) : await sqlClient.knex.transaction(); try { for (const query of downStatements) { diff --git a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts index 037cf6d559..87204964a0 100644 --- a/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts +++ b/packages/nocodb/src/lib/db/sql-migrator/lib/KnexMigratorv2Tans.ts @@ -31,7 +31,16 @@ export default class KnexMigratorv2Tans extends KnexMigratorv2 { protected get metaDb(): XKnex { return this.ncMeta.knex || Noco.ncMeta.knex; } - protected async getSqlClient(base: Base): Promise { + protected async getSqlClient( + base: Base + ): Promise< + | SnowflakeClient + | MysqlClient + | SqliteClient + | MssqlClient + | OracleClient + | PGClient + > { return this.sqlClient || NcConnectionMgrv2.getSqlClient(base); } } diff --git a/packages/nocodb/src/lib/meta/api/helpers/populateMeta.ts b/packages/nocodb/src/lib/meta/api/helpers/populateMeta.ts index 4fe72f70ac..ffe246a131 100644 --- a/packages/nocodb/src/lib/meta/api/helpers/populateMeta.ts +++ b/packages/nocodb/src/lib/meta/api/helpers/populateMeta.ts @@ -228,7 +228,7 @@ export async function populateMeta(base: Base, project: Project): Promise { return async () => { const columns = (await sqlClient.columnList({ tn: table.table_name })) ?.data?.list; - + mapDefaultDisplayValue(columns); /* create nc_models and its rows if it doesn't exists */ diff --git a/packages/nocodb/src/lib/meta/helpers/mapDefaultDisplayValue.ts b/packages/nocodb/src/lib/meta/helpers/mapDefaultDisplayValue.ts index 3fe911f447..a661f21818 100644 --- a/packages/nocodb/src/lib/meta/helpers/mapDefaultDisplayValue.ts +++ b/packages/nocodb/src/lib/meta/helpers/mapDefaultDisplayValue.ts @@ -4,7 +4,7 @@ export default function mapDefaultDisplayValue( columnsArr: Array ): void | T { if (!columnsArr.some((column) => column.pv)) { - const pkIndex = columnsArr.findIndex((column) => column.pk) + const pkIndex = columnsArr.findIndex((column) => column.pk); // if PK is at the end of table if (pkIndex === columnsArr.length - 1) { @@ -15,11 +15,11 @@ export default function mapDefaultDisplayValue( columnsArr[0].pv = true; return columnsArr[0]; } - // pk is not at the end of table - } else if (pkIndex > -1) { + // pk is not at the end of table + } else if (pkIndex > -1) { columnsArr[pkIndex + 1].pv = true; return columnsArr[pkIndex + 1]; - // no pk at all + // no pk at all } else { if (columnsArr.length > 0) { columnsArr[0].pv = true; diff --git a/packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts b/packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts index 0a6e16c21e..1fa222cd17 100644 --- a/packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts +++ b/packages/nocodb/src/lib/version-upgrader/ncStickyColumnUpgrader.ts @@ -40,8 +40,8 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { // if no display value column is set if (!view_columns_meta.some((column) => column.pv)) { - const pkIndex = view_columns_meta.findIndex((column) => column.pk) - + const pkIndex = view_columns_meta.findIndex((column) => column.pk); + // if PK is at the end of table if (pkIndex === view_columns_meta.length - 1) { if (pkIndex > 0) { @@ -61,8 +61,8 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { view_columns_meta[0].id ); } - // pk is not at the end of table - } else if (pkIndex > -1) { + // pk is not at the end of table + } else if (pkIndex > -1) { await ncMeta.metaUpdate( null, null, @@ -70,7 +70,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { { pv: true }, view_columns_meta[pkIndex + 1].id ); - // no pk at all + // no pk at all } else if (view_columns_meta.length > 0) { await ncMeta.metaUpdate( null,