Browse Source

fix: delete org user (#8742)

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/8744/head
Mert E 6 months ago committed by GitHub
parent
commit
aa7b9a156f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 29
      packages/nocodb/src/meta/meta.service.ts
  2. 15
      packages/nocodb/src/models/BaseUser.ts
  3. 17
      packages/nocodb/src/models/SyncSource.ts
  4. 6
      packages/nocodb/src/services/org-users.service.ts

29
packages/nocodb/src/meta/meta.service.ts

@ -326,35 +326,6 @@ export class MetaService {
return query.del(); 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<void> {
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 * Get meta data
* @param workspace_id - Workspace id * @param workspace_id - Workspace id

15
packages/nocodb/src/models/BaseUser.ts

@ -8,12 +8,12 @@ import {
CacheGetType, CacheGetType,
CacheScope, CacheScope,
MetaTable, MetaTable,
RootScopes,
} from '~/utils/globals'; } from '~/utils/globals';
import Noco from '~/Noco'; import Noco from '~/Noco';
import NocoCache from '~/cache/NocoCache'; import NocoCache from '~/cache/NocoCache';
import { extractProps } from '~/helpers/extractProps'; import { extractProps } from '~/helpers/extractProps';
import { parseMetaProp } from '~/utils/modelUtils'; import { parseMetaProp } from '~/utils/modelUtils';
import { NcError } from '~/helpers/catchError';
export default class BaseUser { export default class BaseUser {
fk_workspace_id?: string; fk_workspace_id?: string;
@ -359,14 +359,11 @@ export default class BaseUser {
userId: string, userId: string,
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
): Promise<BaseUser[]> { ): Promise<BaseUser[]> {
return await ncMeta.metaList2( if (!userId) NcError.badRequest('User Id is required');
RootScopes.BASE,
RootScopes.BASE, return await ncMeta.knex(MetaTable.PROJECT_USERS).where({
MetaTable.PROJECT_USERS, fk_user_id: userId,
{ });
condition: { fk_user_id: userId },
},
);
} }
static async getProjectsList( static async getProjectsList(

17
packages/nocodb/src/models/SyncSource.ts

@ -150,17 +150,14 @@ export default class SyncSource {
); );
} }
static async deleteByUserId( static async deleteByUserId(userId: string, ncMeta = Noco.ncMeta) {
context: NcContext,
userId: string,
ncMeta = Noco.ncMeta,
) {
throw new Error('Method not implemented.');
if (!userId) NcError.badRequest('User Id is required'); if (!userId) NcError.badRequest('User Id is required');
return await ncMeta.metaDeleteAll(MetaTable.SYNC_SOURCE, { return await ncMeta
fk_user_id: userId, .knex(MetaTable.SYNC_SOURCE)
}); .where({
fk_user_id: userId,
})
.del();
} }
} }

6
packages/nocodb/src/services/org-users.service.ts

@ -16,7 +16,7 @@ import { validatePayload } from '~/helpers';
import { NcError } from '~/helpers/catchError'; import { NcError } from '~/helpers/catchError';
import { extractProps } from '~/helpers/extractProps'; import { extractProps } from '~/helpers/extractProps';
import { randomTokenString } from '~/helpers/stringHelpers'; import { randomTokenString } from '~/helpers/stringHelpers';
import { BaseUser, Store, User } from '~/models'; import { BaseUser, Store, SyncSource, User } from '~/models';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { MetaTable, RootScopes } from '~/utils/globals'; import { MetaTable, RootScopes } from '~/utils/globals';
@ -65,7 +65,6 @@ export class OrgUsersService {
} }
// delete base user entry and assign to super admin // delete base user entry and assign to super admin
// TODO-TENANT: scope this to org
const baseUsers = await BaseUser.getProjectsIdList(param.userId, ncMeta); const baseUsers = await BaseUser.getProjectsIdList(param.userId, ncMeta);
// todo: clear cache // todo: clear cache
@ -84,8 +83,7 @@ export class OrgUsersService {
} }
// delete sync source entry // delete sync source entry
// TODO-TENANT: ENABLE THIS & CONFIRM SCOPE await SyncSource.deleteByUserId(param.userId, ncMeta);
// await SyncSource.deleteByUserId(param.userId, ncMeta);
// delete user // delete user
await User.delete(param.userId, ncMeta); await User.delete(param.userId, ncMeta);

Loading…
Cancel
Save