Browse Source

fix: delete org user (#8742)

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/8744/head
Mert E 2 weeks 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();
}
/***
* 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
* @param workspace_id - Workspace id

15
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<BaseUser[]> {
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(

17
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();
}
}

6
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);

Loading…
Cancel
Save