diff --git a/packages/nc-gui/composables/useViewColumns.ts b/packages/nc-gui/composables/useViewColumns.ts index b1c3f76203..e471dec42a 100644 --- a/packages/nc-gui/composables/useViewColumns.ts +++ b/packages/nc-gui/composables/useViewColumns.ts @@ -1,4 +1,4 @@ -import { ViewTypes, isSystemColumn } from 'nocodb-sdk' +import { ViewTypes, isCreatedOrLastModifiedByCol, isSystemColumn } from 'nocodb-sdk' import type { ColumnType, GridColumnReqType, GridColumnType, MapType, TableType, ViewType } from 'nocodb-sdk' import type { ComputedRef, Ref } from 'vue' import { computed, ref, storeToRefs, useBase, useNuxtApp, useRoles, useUndoRedo, watch } from '#imports' @@ -70,7 +70,12 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState( }, {}) fields.value = meta.value?.columns - ?.map((column: ColumnType) => { + ?.filter((column: ColumnType) => { + // filter created by and last modified by system columns + if (isCreatedOrLastModifiedByCol(column) && column.system) return false + return true + }) + .map((column: ColumnType) => { const currentColumnField = fieldById[column.id!] || {} return { diff --git a/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts index ca5d2409ee..687f39c82f 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts @@ -137,7 +137,7 @@ export class MssqlUi { }, { column_name: 'created_by', - title: 'CreatedBy', + title: 'nc_created_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', @@ -160,7 +160,7 @@ export class MssqlUi { }, { column_name: 'updated_by', - title: 'UpdatedBy', + title: 'nc_updated_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', diff --git a/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts index 020a794af1..618b5f17a0 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts @@ -141,7 +141,7 @@ export class MysqlUi { }, { column_name: 'created_by', - title: 'CreatedBy', + title: 'nc_created_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', @@ -164,7 +164,7 @@ export class MysqlUi { }, { column_name: 'updated_by', - title: 'UpdatedBy', + title: 'nc_updated_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', diff --git a/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts index 6f7e32dc4c..9fab6e673a 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts @@ -199,7 +199,7 @@ export class PgUi { }, { column_name: 'created_by', - title: 'CreatedBy', + title: 'nc_created_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', @@ -222,7 +222,7 @@ export class PgUi { }, { column_name: 'updated_by', - title: 'UpdatedBy', + title: 'nc_updated_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', diff --git a/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts index 0da9a90cc4..2071ebfa69 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts @@ -135,7 +135,7 @@ export class SnowflakeUi { }, { column_name: 'created_by', - title: 'CreatedBy', + title: 'nc_created_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', @@ -158,7 +158,7 @@ export class SnowflakeUi { }, { column_name: 'updated_by', - title: 'UpdatedBy', + title: 'nc_updated_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar(45)', diff --git a/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts b/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts index de58243db6..47db6ee098 100644 --- a/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts +++ b/packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts @@ -123,7 +123,7 @@ export class SqliteUi { }, { column_name: 'created_by', - title: 'CreatedBy', + title: 'nc_created_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar', @@ -146,7 +146,7 @@ export class SqliteUi { }, { column_name: 'updated_by', - title: 'UpdatedBy', + title: 'nc_updated_by', dt: 'varchar', dtx: 'specificType', ct: 'varchar', diff --git a/packages/nocodb/src/helpers/getAst.ts b/packages/nocodb/src/helpers/getAst.ts index 6d05a36d66..4b046fbbf8 100644 --- a/packages/nocodb/src/helpers/getAst.ts +++ b/packages/nocodb/src/helpers/getAst.ts @@ -153,11 +153,12 @@ const getAst = async ({ } let isRequested; - if (getHiddenColumn) { + if (isCreatedOrLastModifiedByCol(col) && col.system) { + isRequested = false; + } else if (getHiddenColumn) { isRequested = !isSystemColumn(col) || (isCreatedOrLastModifiedTimeCol(col) && col.system) || - (isCreatedOrLastModifiedByCol(col) && col.system) || col.pk; } else if (allowedCols && (!includePkByDefault || !col.pk)) { isRequested = diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index 328e430cb7..83f3e7382c 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -1720,11 +1720,11 @@ export class ColumnsService { break; case UITypes.CreatedBy: columnName = 'created_by'; - columnTitle = 'CreatedBy'; + columnTitle = 'nc_created_by'; break; case UITypes.LastModifiedBy: columnName = 'updated_by'; - columnTitle = 'UpdatedBy'; + columnTitle = 'nc_updated_by'; break; } diff --git a/packages/nocodb/src/services/tables.service.ts b/packages/nocodb/src/services/tables.service.ts index e073bd1958..2aa4eeda57 100644 --- a/packages/nocodb/src/services/tables.service.ts +++ b/packages/nocodb/src/services/tables.service.ts @@ -410,11 +410,11 @@ export class TablesService { break; case UITypes.CreatedBy: columnName = 'created_by'; - columnTitle = 'CreatedBy'; + columnTitle = 'nc_created_by'; break; case UITypes.LastModifiedBy: columnName = 'updated_by'; - columnTitle = 'UpdatedBy'; + columnTitle = 'nc_updated_by'; break; } diff --git a/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedByUpgrader.ts b/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedByUpgrader.ts index d3d8e5d216..a4407fd1c3 100644 --- a/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedByUpgrader.ts +++ b/packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedByUpgrader.ts @@ -45,7 +45,7 @@ async function upgradeModels({ { uidt: UITypes.CreatedBy, column_name: getUniqueColumnName(columns, 'created_by'), - title: getUniqueColumnAliasName(columns, 'CreatedBy'), + title: getUniqueColumnAliasName(columns, 'nc_created_by'), }, source, )), @@ -59,7 +59,7 @@ async function upgradeModels({ { uidt: UITypes.LastModifiedBy, column_name: getUniqueColumnName(columns, 'updated_by'), - title: getUniqueColumnAliasName(columns, 'UpdatedBy'), + title: getUniqueColumnAliasName(columns, 'nc_updated_by'), }, source, )), diff --git a/packages/nocodb/tests/unit/rest/tests/columnTypeSpecific.test.ts b/packages/nocodb/tests/unit/rest/tests/columnTypeSpecific.test.ts index 79ca1592e2..34a76906e6 100644 --- a/packages/nocodb/tests/unit/rest/tests/columnTypeSpecific.test.ts +++ b/packages/nocodb/tests/unit/rest/tests/columnTypeSpecific.test.ts @@ -52,16 +52,6 @@ function columnTypeSpecificTests() { uidt: UITypes.LastModifiedTime, system: true, }, - { - title: 'CreatedBy', - uidt: UITypes.CreatedBy, - system: true, - }, - { - title: 'UpdatedBy', - uidt: UITypes.LastModifiedBy, - system: true, - }, ]; describe('Qr Code Column', () => { @@ -222,13 +212,6 @@ function columnTypeSpecificTests() { expect(unfilteredRecords[0].CreatedAt).to.not.equal(null); expect(unfilteredRecords[0].UpdatedAt).to.equal(null); - - expect(unfilteredRecords[0].CreatedBy).to.not.equal(null); - expect(unfilteredRecords[0].CreatedBy.email).to.equal( - context.user.email, - ); - expect(unfilteredRecords[0].CreatedBy.display_name).to.equal(null); - expect(unfilteredRecords[0].UpdatedBy).to.equal(null); }); it('Modify record: verify last-modified-at & modified-by is updated', async () => { @@ -380,19 +363,19 @@ function columnTypeSpecificTests() { .expect(400); }); - it('Add field: CreatedBy, ModifiedBy verify contents of both fields are same & new field is RO', async () => { + it('Add field: CreatedBy, LastModifiedBy verify contents of both fields are proper & new field is RO', async () => { // add another CreatedBy field await createColumn(context, table, { - title: 'CreatedBy2', + title: 'CreatedBy', uidt: UITypes.CreatedBy, - column_name: 'CreatedBy2', + column_name: 'CreatedBy', }); // add another ModifiedBy field await createColumn(context, table, { - title: 'ModifiedBy2', + title: 'LastModifiedBy', uidt: UITypes.LastModifiedBy, - column_name: 'ModifiedBy2', + column_name: 'LastModifiedBy', }); // get all columns @@ -403,7 +386,7 @@ function columnTypeSpecificTests() { // verify contents of both fields are same expect(columns.columns[defaultTableColumns.length].title).to.equal( - 'CreatedBy2', + 'CreatedBy', ); expect(columns.columns[defaultTableColumns.length].uidt).to.equal( UITypes.CreatedBy, @@ -411,10 +394,14 @@ function columnTypeSpecificTests() { expect(columns.columns[defaultTableColumns.length].system).to.equal( false, ); - expect(records[0].CreatedBy).to.deep.equal(records[0].CreatedBy2); + expect(records[0].CreatedBy).to.deep.equal({ + id: context.user.id, + email: context.user.email, + display_name: context.user.display_name, + }); expect(columns.columns[defaultTableColumns.length + 1].title).to.equal( - 'ModifiedBy2', + 'LastModifiedBy', ); expect(columns.columns[defaultTableColumns.length + 1].uidt).to.equal( UITypes.LastModifiedBy, @@ -422,7 +409,7 @@ function columnTypeSpecificTests() { expect(columns.columns[defaultTableColumns.length + 1].system).to.equal( false, ); - expect(records[0].UpdatedBy).to.deep.equal(records[0].ModifiedBy2); + expect(records[0].UpdatedBy).to.deep.equal(null); // update record should fail await request(context.app) @@ -431,7 +418,7 @@ function columnTypeSpecificTests() { .send([ { Id: unfilteredRecords[0].Id, - CreatedBy2: 'user@example.com', + CreatedBy: 'user@example.com', }, ]) .expect(400); @@ -442,7 +429,7 @@ function columnTypeSpecificTests() { .send([ { Id: unfilteredRecords[0].Id, - ModifiedBy2: 'user@example.com', + LastModifiedBy: 'user@example.com', }, ]) .expect(400); @@ -491,9 +478,9 @@ function columnTypeSpecificTests() { it('Delete & add field: (CreatedBy) verify contents of both fields are same', async () => { // add another CreatedBy field await createColumn(context, table, { - title: 'CreatedBy2', + title: 'CreatedBy', uidt: UITypes.CreatedBy, - column_name: 'CreatedBy2', + column_name: 'CreatedBy', }); // get all columns let columns = await getColumnsByAPI(context, base, table); @@ -501,9 +488,9 @@ function columnTypeSpecificTests() { await deleteColumn(context, { table, column: columns.columns[6] }); // create column again await createColumn(context, table, { - title: 'CreatedBy2', + title: 'CreatedBy', uidt: UITypes.CreatedBy, - column_name: 'CreatedBy2', + column_name: 'CreatedBy', }); // get all columns columns = await getColumnsByAPI(context, base, table); @@ -513,7 +500,7 @@ function columnTypeSpecificTests() { // verify contents of both fields are same expect(columns.columns[defaultTableColumns.length].title).to.equal( - 'CreatedBy2', + 'CreatedBy', ); expect(columns.columns[defaultTableColumns.length].uidt).to.equal( UITypes.CreatedBy, @@ -521,7 +508,7 @@ function columnTypeSpecificTests() { expect(columns.columns[defaultTableColumns.length].system).to.equal( false, ); - expect(records[0].CreatedBy).to.deep.equal(records[0].CreatedBy2); + expect(records[0].CreatedBy).to.deep.equal(records[0].CreatedBy); }); }); });