diff --git a/packages/nocodb/src/meta/meta.service.ts b/packages/nocodb/src/meta/meta.service.ts index bf9fa2bcc5..7eba9a7215 100644 --- a/packages/nocodb/src/meta/meta.service.ts +++ b/packages/nocodb/src/meta/meta.service.ts @@ -326,35 +326,6 @@ export class MetaService { return query.del(); } - /*** - * Delete meta data with condition (USE WITH CAUTION) - * @param target - Table name - * @param idOrCondition - If string, will delete the record with the given id. If object, will delete the record with the given condition. - * @param xcCondition - Additional nested or complex condition to be added to the query. - */ - public async metaDeleteAll( - target: string, - idOrCondition: string | { [p: string]: any }, - xcCondition?: Condition, - ): Promise { - const query = this.knexConnection(target); - - if (typeof idOrCondition !== 'object') { - query.where('id', idOrCondition); - } else if (idOrCondition) { - query.where(idOrCondition); - } - - if (xcCondition) { - query.condition(xcCondition, {}); - } - - // Check if a condition is present in the query builder and throw an error if not. - this.checkConditionPresent(query, 'delete'); - - return query.del(); - } - /*** * Get meta data * @param workspace_id - Workspace id diff --git a/packages/nocodb/src/models/BaseUser.ts b/packages/nocodb/src/models/BaseUser.ts index c6dac92b30..a313d792c7 100644 --- a/packages/nocodb/src/models/BaseUser.ts +++ b/packages/nocodb/src/models/BaseUser.ts @@ -8,12 +8,12 @@ import { CacheGetType, CacheScope, MetaTable, - RootScopes, } from '~/utils/globals'; import Noco from '~/Noco'; import NocoCache from '~/cache/NocoCache'; import { extractProps } from '~/helpers/extractProps'; import { parseMetaProp } from '~/utils/modelUtils'; +import { NcError } from '~/helpers/catchError'; export default class BaseUser { fk_workspace_id?: string; @@ -359,14 +359,11 @@ export default class BaseUser { userId: string, ncMeta = Noco.ncMeta, ): Promise { - return await ncMeta.metaList2( - RootScopes.BASE, - RootScopes.BASE, - MetaTable.PROJECT_USERS, - { - condition: { fk_user_id: userId }, - }, - ); + if (!userId) NcError.badRequest('User Id is required'); + + return await ncMeta.knex(MetaTable.PROJECT_USERS).where({ + fk_user_id: userId, + }); } static async getProjectsList( diff --git a/packages/nocodb/src/models/SyncSource.ts b/packages/nocodb/src/models/SyncSource.ts index 2c3e42e698..93d5e3293a 100644 --- a/packages/nocodb/src/models/SyncSource.ts +++ b/packages/nocodb/src/models/SyncSource.ts @@ -150,17 +150,14 @@ export default class SyncSource { ); } - static async deleteByUserId( - context: NcContext, - userId: string, - ncMeta = Noco.ncMeta, - ) { - throw new Error('Method not implemented.'); - + static async deleteByUserId(userId: string, ncMeta = Noco.ncMeta) { if (!userId) NcError.badRequest('User Id is required'); - return await ncMeta.metaDeleteAll(MetaTable.SYNC_SOURCE, { - fk_user_id: userId, - }); + return await ncMeta + .knex(MetaTable.SYNC_SOURCE) + .where({ + fk_user_id: userId, + }) + .del(); } } diff --git a/packages/nocodb/src/services/org-users.service.ts b/packages/nocodb/src/services/org-users.service.ts index e0aae4fabd..d3a386aa13 100644 --- a/packages/nocodb/src/services/org-users.service.ts +++ b/packages/nocodb/src/services/org-users.service.ts @@ -16,7 +16,7 @@ import { validatePayload } from '~/helpers'; import { NcError } from '~/helpers/catchError'; import { extractProps } from '~/helpers/extractProps'; import { randomTokenString } from '~/helpers/stringHelpers'; -import { BaseUser, Store, User } from '~/models'; +import { BaseUser, Store, SyncSource, User } from '~/models'; import Noco from '~/Noco'; import { MetaTable, RootScopes } from '~/utils/globals'; @@ -65,7 +65,6 @@ export class OrgUsersService { } // delete base user entry and assign to super admin - // TODO-TENANT: scope this to org const baseUsers = await BaseUser.getProjectsIdList(param.userId, ncMeta); // todo: clear cache @@ -84,8 +83,7 @@ export class OrgUsersService { } // delete sync source entry - // TODO-TENANT: ENABLE THIS & CONFIRM SCOPE - // await SyncSource.deleteByUserId(param.userId, ncMeta); + await SyncSource.deleteByUserId(param.userId, ncMeta); // delete user await User.delete(param.userId, ncMeta);