Browse Source

feat: hide CreatedBy & LastModifiedBy system fields by default

pull/7373/head
mertmit 12 months ago
parent
commit
b6829c4866
  1. 9
      packages/nc-gui/composables/useViewColumns.ts
  2. 4
      packages/nocodb-sdk/src/lib/sqlUi/MssqlUi.ts
  3. 4
      packages/nocodb-sdk/src/lib/sqlUi/MysqlUi.ts
  4. 4
      packages/nocodb-sdk/src/lib/sqlUi/PgUi.ts
  5. 4
      packages/nocodb-sdk/src/lib/sqlUi/SnowflakeUi.ts
  6. 4
      packages/nocodb-sdk/src/lib/sqlUi/SqliteUi.ts
  7. 5
      packages/nocodb/src/helpers/getAst.ts
  8. 4
      packages/nocodb/src/services/columns.service.ts
  9. 4
      packages/nocodb/src/services/tables.service.ts
  10. 4
      packages/nocodb/src/version-upgrader/ncXcdbCreatedAndUpdatedByUpgrader.ts
  11. 55
      packages/nocodb/tests/unit/rest/tests/columnTypeSpecific.test.ts

9
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 {

4
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)',

4
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)',

4
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)',

4
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)',

4
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',

5
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 =

4
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;
}

4
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;
}

4
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,
)),

55
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);
});
});
});

Loading…
Cancel
Save