Skip to content

Commit

Permalink
feat: add setting to map an ldap attribute to the user's voice extens…
Browse files Browse the repository at this point in the history
…ion (#33598)
  • Loading branch information
pierre-lehnen-rc authored and abhinavkrin committed Oct 25, 2024
1 parent c718ebd commit a1bbdbf
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/shiny-falcons-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@rocket.chat/core-typings': minor
'@rocket.chat/i18n': minor
'@rocket.chat/meteor': minor
---

Adds a new setting to allow mapping LDAP attributes to the user's extension
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ export class UserConverter extends RecordConverter<IImportUserRecord, UserConver
...(userData.importIds?.length && { importIds: userData.importIds }),
...(!!userData.customFields && { customFields: userData.customFields }),
...(userData.deleted !== undefined && { active: !userData.deleted }),
...(userData.voipExtension !== undefined && { freeSwitchExtension: userData.voipExtension }),
};
}

Expand Down
11 changes: 11 additions & 0 deletions apps/meteor/server/lib/ldap/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,15 @@ export class LDAPManager {
const username = this.slugifyUsername(ldapUser, usedUsername || id || '') || undefined;
const emails = this.getLdapEmails(ldapUser, username);
const name = this.getLdapName(ldapUser) || undefined;
const voipExtension = this.getLdapExtension(ldapUser);

const userData: IImportUser = {
type: 'user',
emails,
importIds: [ldapUser.dn],
username,
name,
voipExtension,
services: {
ldap: {
idAttribute,
Expand Down Expand Up @@ -438,6 +440,15 @@ export class LDAPManager {
return this.getLdapDynamicValue(ldapUser, nameAttributes);
}

private static getLdapExtension(ldapUser: ILDAPEntry): string | undefined {
const extensionAttribute = settings.get<string>('LDAP_Extension_Field');
if (!extensionAttribute) {
return;
}

return this.getLdapString(ldapUser, extensionAttribute);
}

private static getLdapEmails(ldapUser: ILDAPEntry, username?: string): string[] {
const emailAttributes = getLDAPConditionalSetting<string>('LDAP_Email_Field');
if (emailAttributes) {
Expand Down
5 changes: 5 additions & 0 deletions apps/meteor/server/settings/ldap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ export const createLdapSettings = () =>
enableQuery,
displayQuery: ldapOnly,
});

await this.add('LDAP_Extension_Field', '', {
type: 'string',
enableQuery,
});
});

await this.section('LDAP_DataSync_Avatar', async function () {
Expand Down
1 change: 1 addition & 0 deletions packages/core-typings/src/import/IImportUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface IImportUser {
customFields?: Record<string, any>;

password?: string;
voipExtension?: string;
}
1 change: 1 addition & 0 deletions packages/i18n/src/locales/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -3037,6 +3037,7 @@
"LDAP_Server_Type_Other": "Other",
"LDAP_Name_Field": "Name Field",
"LDAP_Email_Field": "Email Field",
"LDAP_Extension_Field": "Extension Field",
"LDAP_Update_Data_On_Login": "Update User Data on Login",
"LDAP_Update_Data_On_OAuth_Login": "Update User Data on Login with OAuth services",
"LDAP_Advanced_Sync": "Advanced Sync",
Expand Down

0 comments on commit a1bbdbf

Please sign in to comment.