refactor: remove Promise.await from LDAP files (#28527)

pull/28454/head^2
Pierre Lehnen 3 years ago committed by GitHub
parent 17ac357907
commit 2d4c2efa17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      apps/meteor/app/importer/server/classes/ImportDataConverter.ts
  2. 6
      apps/meteor/app/importer/server/classes/ImporterBase.js
  3. 4
      apps/meteor/app/importer/server/definitions/IConversionCallbacks.ts
  4. 4
      apps/meteor/ee/server/configuration/ldap.ts
  5. 6
      apps/meteor/ee/server/lib/ldap/Manager.ts
  6. 4
      apps/meteor/server/configuration/ldap.ts
  7. 4
      apps/meteor/server/lib/ldap/DataConverter.ts

@ -302,7 +302,7 @@ export class ImportDataConverter {
return ImportData.getAllUsers().toArray();
}
findExistingUser(data: IImportUser): IUser | undefined {
async findExistingUser(data: IImportUser): Promise<IUser | undefined> {
if (data.emails.length) {
const emailUser = Users.findOneByEmailAddress(data.emails[0], {});
@ -321,7 +321,7 @@ export class ImportDataConverter {
const users = (await this.getUsersToImport()) as IImportUserRecord[];
for await (const { data, _id } of users) {
try {
if (beforeImportFn && !beforeImportFn(data, 'user')) {
if (beforeImportFn && !(await beforeImportFn(data, 'user'))) {
await this.skipRecord(_id);
continue;
}
@ -333,7 +333,7 @@ export class ImportDataConverter {
throw new Error('importer-user-missing-email-and-username');
}
let existingUser = this.findExistingUser(data);
let existingUser = await this.findExistingUser(data);
if (existingUser && this._options.skipExistingUsers) {
await this.skipRecord(_id);
continue;
@ -367,7 +367,7 @@ export class ImportDataConverter {
}
if (afterImportFn) {
afterImportFn(data, 'user', isNewUser);
await afterImportFn(data, 'user', isNewUser);
}
} catch (e) {
this._logger.error(e);
@ -555,7 +555,7 @@ export class ImportDataConverter {
for await (const { data, _id } of messages) {
try {
if (beforeImportFn && !beforeImportFn(data, 'message')) {
if (beforeImportFn && !(await beforeImportFn(data, 'message'))) {
await this.skipRecord(_id);
continue;
}
@ -624,7 +624,7 @@ export class ImportDataConverter {
}
if (afterImportFn) {
afterImportFn(data, 'message', true);
await afterImportFn(data, 'message', true);
}
} catch (e) {
await this.saveError(_id, e instanceof Error ? e : new Error(String(e)));
@ -905,7 +905,7 @@ export class ImportDataConverter {
const channels = await this.getChannelsToImport();
for await (const { data, _id } of channels) {
try {
if (beforeImportFn && !beforeImportFn(data, 'channel')) {
if (beforeImportFn && !(await beforeImportFn(data, 'channel'))) {
await this.skipRecord(_id);
continue;
}
@ -934,7 +934,7 @@ export class ImportDataConverter {
}
if (afterImportFn) {
afterImportFn(data, 'channel', !existingRoom);
await afterImportFn(data, 'channel', !existingRoom);
}
} catch (e) {
await this.saveError(_id, e instanceof Error ? e : new Error(String(e)));

@ -168,7 +168,7 @@ export class Base {
const started = Date.now();
const startedByUserId = Meteor.userId();
const beforeImportFn = (data, type) => {
const beforeImportFn = async (data, type) => {
switch (type) {
case 'channel': {
const id = data.t === 'd' ? '__directMessages__' : data.importIds[0];
@ -195,8 +195,8 @@ export class Base {
return true;
};
const afterImportFn = () => {
Promise.await(this.addCountCompleted(1));
const afterImportFn = async () => {
return this.addCountCompleted(1);
};
process.nextTick(async () => {

@ -1,11 +1,11 @@
import type { IImportUser, IImportMessage, IImportChannel } from '@rocket.chat/core-typings';
type ImporterBeforeImportCallback = {
(data: IImportUser | IImportChannel | IImportMessage, type: string): boolean;
(data: IImportUser | IImportChannel | IImportMessage, type: string): Promise<boolean>;
};
export type ImporterAfterImportCallback = {
(data: IImportUser | IImportChannel | IImportMessage, type: string, isNewRecord: boolean): void;
(data: IImportUser | IImportChannel | IImportMessage, type: string, isNewRecord: boolean): Promise<void>;
};
export interface IConversionCallbacks {

@ -88,12 +88,12 @@ Meteor.startup(() =>
callbacks.add(
'onLDAPLogin',
({ user, ldapUser, isNewUser }: { user: IUser; ldapUser: ILDAPEntry; isNewUser: boolean }, ldap?: LDAPConnection) => {
async ({ user, ldapUser, isNewUser }: { user: IUser; ldapUser: ILDAPEntry; isNewUser: boolean }, ldap?: LDAPConnection) => {
if (!ldap) {
return;
}
Promise.await(LDAPEEManager.advancedSyncForUser(ldap, user, isNewUser, ldapUser.dn));
await LDAPEEManager.advancedSyncForUser(ldap, user, isNewUser, ldapUser.dn);
},
callbacks.priority.MEDIUM,
'advancedLDAPSync',

@ -40,8 +40,8 @@ export class LDAPEEManager extends LDAPManager {
}
await converter.convertUsers({
afterImportFn: ((data: IImportUser, _type: string, isNewRecord: boolean): void =>
Promise.await(this.advancedSync(ldap, data, converter, isNewRecord))) as ImporterAfterImportCallback,
afterImportFn: (async (data: IImportUser, _type: string, isNewRecord: boolean): Promise<void> =>
this.advancedSync(ldap, data, converter, isNewRecord)) as ImporterAfterImportCallback,
});
} catch (error) {
logger.error(error);
@ -126,7 +126,7 @@ export class LDAPEEManager extends LDAPManager {
converter: LDAPDataConverter,
isNewRecord: boolean,
): Promise<void> {
const user = converter.findExistingUser(importUser);
const user = await converter.findExistingUser(importUser);
if (!user?.username) {
return;
}

@ -5,12 +5,12 @@ import { callbacks } from '../../lib/callbacks';
import { settings } from '../../app/settings/server';
// Register ldap login handler
Accounts.registerLoginHandler('ldap', function (loginRequest: Record<string, any>) {
Accounts.registerLoginHandler('ldap', async function (loginRequest: Record<string, any>) {
if (!loginRequest.ldap || !loginRequest.ldapOptions) {
return undefined;
}
return Promise.await(LDAP.loginRequest(loginRequest.username, loginRequest.ldapPass));
return LDAP.loginRequest(loginRequest.username, loginRequest.ldapPass);
});
// Prevent password logins by LDAP users when LDAP is enabled

@ -18,9 +18,9 @@ export class LDAPDataConverter extends VirtualDataConverter {
this.mergeExistingUsers = settings.get<boolean>('LDAP_Merge_Existing_Users') ?? true;
}
findExistingUser(data: IImportUser): IUser | undefined {
async findExistingUser(data: IImportUser): Promise<IUser | undefined> {
if (data.services?.ldap?.id) {
const importedUser = Promise.await(Users.findOneByLDAPId(data.services.ldap.id, data.services.ldap.idAttribute));
const importedUser = await Users.findOneByLDAPId(data.services.ldap.id, data.services.ldap.idAttribute);
if (importedUser) {
return importedUser;
}

Loading…
Cancel
Save