refactor(core): Use DI for LDAP code (no-changelog) (#8248)

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
Ricardo Espinoza
2024-01-15 09:01:48 -05:00
committed by GitHub
parent a6a5372b5f
commit 3c2a4000ae
11 changed files with 492 additions and 598 deletions

View File

@@ -1,32 +1,32 @@
import { Container } from 'typedi';
import { InternalHooks } from '@/InternalHooks';
import { LdapService } from '@/Ldap/ldap.service';
import {
createLdapUserOnLocalDb,
findAndAuthenticateLdapUser,
getLdapConfig,
getLdapUserRole,
getUserByEmail,
getAuthIdentityByLdapId,
isLdapDisabled,
isLdapEnabled,
mapLdapAttributesToUser,
createLdapAuthIdentity,
updateLdapUserOnLocalDb,
} from '@/Ldap/helpers';
import type { User } from '@db/entities/User';
import { Container } from 'typedi';
export const handleLdapLogin = async (
loginId: string,
password: string,
): Promise<User | undefined> => {
if (isLdapDisabled()) return undefined;
if (!isLdapEnabled()) return undefined;
const ldapConfig = await getLdapConfig();
const ldapService = Container.get(LdapService);
if (!ldapConfig.loginEnabled) return undefined;
if (!ldapService.config.loginEnabled) return undefined;
const { loginIdAttribute, userFilter } = ldapConfig;
const { loginIdAttribute, userFilter } = ldapService.config;
const ldapUser = await findAndAuthenticateLdapUser(
const ldapUser = await ldapService.findAndAuthenticateLdapUser(
loginId,
password,
loginIdAttribute,
@@ -35,7 +35,7 @@ export const handleLdapLogin = async (
if (!ldapUser) return undefined;
const [ldapId, ldapAttributesValues] = mapLdapAttributesToUser(ldapUser, ldapConfig);
const [ldapId, ldapAttributesValues] = mapLdapAttributesToUser(ldapUser, ldapService.config);
const { email: emailAttributeValue } = ldapAttributesValues;