From 3d232572b6eeb8cc58b3cf4d614a7a0f55a24893 Mon Sep 17 00:00:00 2001 From: mertmit Date: Thu, 31 Mar 2022 13:19:24 +0300 Subject: [PATCH 1/4] fix: hotfix reverting breaking changes -changed variable name to _ignoreWebhook -if _ignoreWebhook not present fire the webhook as intended --- packages/nc-gui/plugins/ncApis/gqlApi.js | 2 +- packages/nc-gui/plugins/ncApis/restApi.js | 2 +- packages/nocodb/src/lib/noco/common/BaseModel.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/plugins/ncApis/gqlApi.js b/packages/nc-gui/plugins/ncApis/gqlApi.js index 3fa0fe28f5..66ebafeb06 100644 --- a/packages/nc-gui/plugins/ncApis/gqlApi.js +++ b/packages/nc-gui/plugins/ncApis/gqlApi.js @@ -184,7 +184,7 @@ export default class GqlApi { variables: { id, data }, - _cellSaved: cellSaved + _ignoreWebhook: !cellSaved }) const colName = Object.keys(data)[0] diff --git a/packages/nc-gui/plugins/ncApis/restApi.js b/packages/nc-gui/plugins/ncApis/restApi.js index 92efb64579..0d6dc09981 100644 --- a/packages/nc-gui/plugins/ncApis/restApi.js +++ b/packages/nc-gui/plugins/ncApis/restApi.js @@ -65,7 +65,7 @@ export default class RestApi { } async update(id, data, oldData, cellSaved = false) { - data._cellSaved = cellSaved + data._ignoreWebhook = !cellSaved const res = await this.$axios({ method: 'put', url: `/nc/${this.$ctx.projectId}/api/v1/${this.table}/${encodeURIComponent(id)}`, diff --git a/packages/nocodb/src/lib/noco/common/BaseModel.ts b/packages/nocodb/src/lib/noco/common/BaseModel.ts index d093843e6a..7ce7e5736a 100644 --- a/packages/nocodb/src/lib/noco/common/BaseModel.ts +++ b/packages/nocodb/src/lib/noco/common/BaseModel.ts @@ -49,7 +49,7 @@ class BaseModel> extends BaseModelSql { public async beforeUpdate(data: any, _trx: any, req): Promise { req = req || {}; req['oldData'] = await this.readByPk(req['params'].id); - if(req.body?._cellSaved) await this.handleHooks('before.update', data, req); + if(!req.body?._ignoreWebhook) await this.handleHooks('before.update', data, req); } public async afterUpdate(data: any, _trx: any, req): Promise { @@ -74,7 +74,7 @@ class BaseModel> extends BaseModelSql { user: req.user?.email } ) - if(req.body?._cellSaved) await this.handleHooks('after.update', data, req); + if(!req.body?._ignoreWebhook) await this.handleHooks('after.update', data, req); } private _updateAuditDescription(id, oldData: any, data: any) { From 1e71931f47fce9043e4c53d30f6054a3fea0111d Mon Sep 17 00:00:00 2001 From: mertmit Date: Fri, 1 Apr 2022 19:13:30 +0300 Subject: [PATCH 2/4] fix: carried ignoreWebhook from body to query --- .../components/project/spreadsheet/rowsXcDataTable.vue | 2 +- packages/nc-gui/plugins/ncApis/gqlApi.js | 6 ++++-- packages/nc-gui/plugins/ncApis/restApi.js | 5 ++--- packages/nocodb/src/lib/noco/common/BaseModel.ts | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue index 4700ddfdec..fa71bb30aa 100644 --- a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue +++ b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue @@ -1097,7 +1097,7 @@ export default { return } // return if there is no change - if (oldRow[column._cn] === rowObj[column._cn] && ((lastSave || null) === rowObj[column._cn])) { + if (oldRow[column._cn] === rowObj[column._cn] && ((lastSave || rowObj[column._cn]) == rowObj[column._cn])) { return } if(saved) this.$set(this.data[row], 'lastSave', oldRow[column._cn]); diff --git a/packages/nc-gui/plugins/ncApis/gqlApi.js b/packages/nc-gui/plugins/ncApis/gqlApi.js index 66ebafeb06..9da22b1f8d 100644 --- a/packages/nc-gui/plugins/ncApis/gqlApi.js +++ b/packages/nc-gui/plugins/ncApis/gqlApi.js @@ -183,8 +183,10 @@ export default class GqlApi { }`, variables: { id, data - }, - _ignoreWebhook: !cellSaved + } + }, + { + params: { ignoreWebhook: !cellSaved } }) const colName = Object.keys(data)[0] diff --git a/packages/nc-gui/plugins/ncApis/restApi.js b/packages/nc-gui/plugins/ncApis/restApi.js index 0d6dc09981..3bd81f5708 100644 --- a/packages/nc-gui/plugins/ncApis/restApi.js +++ b/packages/nc-gui/plugins/ncApis/restApi.js @@ -65,13 +65,12 @@ export default class RestApi { } async update(id, data, oldData, cellSaved = false) { - data._ignoreWebhook = !cellSaved const res = await this.$axios({ method: 'put', url: `/nc/${this.$ctx.projectId}/api/v1/${this.table}/${encodeURIComponent(id)}`, - data + data, + params: { ignoreWebhook: !cellSaved } }) - return res.data } diff --git a/packages/nocodb/src/lib/noco/common/BaseModel.ts b/packages/nocodb/src/lib/noco/common/BaseModel.ts index 7ce7e5736a..abb87fc9e7 100644 --- a/packages/nocodb/src/lib/noco/common/BaseModel.ts +++ b/packages/nocodb/src/lib/noco/common/BaseModel.ts @@ -49,7 +49,7 @@ class BaseModel> extends BaseModelSql { public async beforeUpdate(data: any, _trx: any, req): Promise { req = req || {}; req['oldData'] = await this.readByPk(req['params'].id); - if(!req.body?._ignoreWebhook) await this.handleHooks('before.update', data, req); + if(req.query?.ignoreWebhook === undefined || req.query?.ignoreWebhook == 'false') await this.handleHooks('before.update', data, req); } public async afterUpdate(data: any, _trx: any, req): Promise { @@ -74,7 +74,7 @@ class BaseModel> extends BaseModelSql { user: req.user?.email } ) - if(!req.body?._ignoreWebhook) await this.handleHooks('after.update', data, req); + if(req.query?.ignoreWebhook === undefined || req.query?.ignoreWebhook == 'false') await this.handleHooks('after.update', data, req); } private _updateAuditDescription(id, oldData: any, data: any) { From ebdc8cb021a252d7ec9b1228006c6ac62be07393 Mon Sep 17 00:00:00 2001 From: Mert Ersoy Date: Sat, 2 Apr 2022 10:40:29 +0300 Subject: [PATCH 3/4] fix: changed default value for cellSaved to true for intended default behaviour --- packages/nc-gui/plugins/ncApis/gqlApi.js | 2 +- packages/nc-gui/plugins/ncApis/restApi.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/plugins/ncApis/gqlApi.js b/packages/nc-gui/plugins/ncApis/gqlApi.js index 9da22b1f8d..1009142a07 100644 --- a/packages/nc-gui/plugins/ncApis/gqlApi.js +++ b/packages/nc-gui/plugins/ncApis/gqlApi.js @@ -176,7 +176,7 @@ export default class GqlApi { return { list, count } } - async update(id, data, oldData, cellSaved = false, params = {}) { + async update(id, data, oldData, cellSaved = true, params = {}) { const data1 = await this.post(`/nc/${this.$ctx.projectId}/v1/graphql`, { query: `mutation update($id:String!, $data:${this.tableCamelized}Input){ ${this.gqlMutationUpdateName}(id: $id, data: $data){${this.gqlReqBody}${await this.gqlRelationReqBody(params)}} diff --git a/packages/nc-gui/plugins/ncApis/restApi.js b/packages/nc-gui/plugins/ncApis/restApi.js index 3bd81f5708..eafd0df84c 100644 --- a/packages/nc-gui/plugins/ncApis/restApi.js +++ b/packages/nc-gui/plugins/ncApis/restApi.js @@ -64,7 +64,7 @@ export default class RestApi { return { list, count } } - async update(id, data, oldData, cellSaved = false) { + async update(id, data, oldData, cellSaved = true) { const res = await this.$axios({ method: 'put', url: `/nc/${this.$ctx.projectId}/api/v1/${this.table}/${encodeURIComponent(id)}`, From e6f2a32f5ca6fe7c62480ad7e2e52d070fd8c431 Mon Sep 17 00:00:00 2001 From: Mert Ersoy Date: Sun, 3 Apr 2022 08:52:48 +0300 Subject: [PATCH 4/4] fix: refactored code as requested in review Signed-off-by: Mert Ersoy --- .../project/spreadsheet/rowsXcDataTable.vue | 2 +- .../nocodb/src/lib/noco/common/BaseModel.ts | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue index fa71bb30aa..8bd3be2d80 100644 --- a/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue +++ b/packages/nc-gui/components/project/spreadsheet/rowsXcDataTable.vue @@ -1097,7 +1097,7 @@ export default { return } // return if there is no change - if (oldRow[column._cn] === rowObj[column._cn] && ((lastSave || rowObj[column._cn]) == rowObj[column._cn])) { + if (oldRow[column._cn] === rowObj[column._cn] && ((lastSave || rowObj[column._cn]) === rowObj[column._cn])) { return } if(saved) this.$set(this.data[row], 'lastSave', oldRow[column._cn]); diff --git a/packages/nocodb/src/lib/noco/common/BaseModel.ts b/packages/nocodb/src/lib/noco/common/BaseModel.ts index abb87fc9e7..938b66b4e8 100644 --- a/packages/nocodb/src/lib/noco/common/BaseModel.ts +++ b/packages/nocodb/src/lib/noco/common/BaseModel.ts @@ -49,7 +49,15 @@ class BaseModel> extends BaseModelSql { public async beforeUpdate(data: any, _trx: any, req): Promise { req = req || {}; req['oldData'] = await this.readByPk(req['params'].id); - if(req.query?.ignoreWebhook === undefined || req.query?.ignoreWebhook == 'false') await this.handleHooks('before.update', data, req); + const ignoreWebhook = req.query?.ignoreWebhook; + if (ignoreWebhook) { + if (ignoreWebhook != 'true' && ignoreWebhook != 'false') { + throw new Error('ignoreWebhook value can be either true or false'); + } + } + if (ignoreWebhook === undefined || ignoreWebhook === 'false') { + await this.handleHooks('before.update', data, req); + } } public async afterUpdate(data: any, _trx: any, req): Promise { @@ -74,7 +82,15 @@ class BaseModel> extends BaseModelSql { user: req.user?.email } ) - if(req.query?.ignoreWebhook === undefined || req.query?.ignoreWebhook == 'false') await this.handleHooks('after.update', data, req); + const ignoreWebhook = req.query?.ignoreWebhook; + if (ignoreWebhook) { + if (ignoreWebhook != 'true' && ignoreWebhook != 'false') { + throw new Error('ignoreWebhook value can be either true or false'); + } + } + if (ignoreWebhook === undefined || ignoreWebhook === 'false') { + await this.handleHooks('after.update', data, req); + } } private _updateAuditDescription(id, oldData: any, data: any) {