Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add setting to map an ldap attribute to the user's voice extension #33598

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
---

Added a new setting to allow mapping LDAP attributes to the user's extension
pierre-lehnen-rc marked this conversation as resolved.
Show resolved Hide resolved
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).map((email) => email.trim());
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 | undefined>('LDAP_Extension_Field');
pierre-lehnen-rc marked this conversation as resolved.
Show resolved Hide resolved
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,
});
matheusbsilva137 marked this conversation as resolved.
Show resolved Hide resolved
});

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 @@ -3057,6 +3057,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
Loading