The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/apps/meteor/server/lib/ldap/getLdapDynamicValue.ts

31 lines
1.1 KiB

import type { ILDAPEntry } from '@rocket.chat/core-typings';
import { getLdapString } from './getLdapString';
import { ldapKeyExists } from './ldapKeyExists';
export function getLdapDynamicValue(ldapUser: ILDAPEntry, attributeSetting: string | undefined): string | undefined {
if (!attributeSetting) {
return;
}
// If the attribute setting is a template, then convert the variables in it
if (attributeSetting.includes('#{')) {
return attributeSetting.replace(/#{(.+?)}/g, (_match, field) => {
const key = field.trim();
if (ldapKeyExists(ldapUser, key)) {
// We've already validated so it won't ever return undefined, but add a fallback to ensure it doesn't break if something gets changed
return getLdapString(ldapUser, key) || '';
}
return '';
});
}
// If it's not a template, then treat the setting as a CSV list of possible attribute names and return the first valid one.
const attributeList: string[] = attributeSetting.replace(/\s/g, '').split(',');
const key = attributeList.find((field) => ldapKeyExists(ldapUser, field));
if (key) {
return getLdapString(ldapUser, key);
}
}