Mapping LDAP Conditionals for Customer Backend

Moderator: crythias

Locked
bogentu
Znuny newbie
Posts: 17
Joined: 14 Feb 2011, 17:33
Znuny Version: 3.0.5

Mapping LDAP Conditionals for Customer Backend

Post by bogentu »

I am trying to find a way to do a conditional mapping of my LDAP customer data so I can do more informal salutations (so Bob instead of Robert). Our LDAP has fields for givenName (ie. Robert) and displayName (ie. Bob). The users can set their displayName themselves and some do, but sometimes the field is blank. I want the displayName to be used for salutations if it exists, but use the givenName if it doesn't.

I have added a custom tag called UserPrefName that is assigned by displayName in the LDAP mapping in Config.pm:

Code: Select all

 [ 'UserPrefName', 'Preferred Name', 'displayName', 1, 0, 'var', '', 0 ]. 
This works great if something is in displayName. However I have a problem when there is nothing in the displayName field - it is left blank in my salutations.

I found a reference to a conditional mapping on an OTRS forum thread (http://forums.otrs.org/viewtopic.php?f= ... nal#p22701) but it is in German. But after using google translate, it appears this is a way to assign a Mr or Mrs based on a value in an LDAP field. The solution given is:

Code: Select all

[ 'UserSalutation', 'Salutation', 'IF(geslacht = 1, "heer", "mevrouw") AS aanhef', 1, 0, 'var', '', 0 ],
Does the syntax of "IF(geslacht = 1, "heer", "mevrouw") AS aanhef'" look like something that LDAP would understand? I want to assign UserPrefName to displayName if it exists, but to use givenName if it doesn't.
crythias
Moderator
Posts: 10170
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: Mapping LDAP Conditionals for Customer Backend

Post by crythias »

That looks like something MySQL (SQL) would understand.

HOWEVER, if you PROMISE that one is always null, you can (might?) be able to concatenate them :)

But on the other hand, you could hardcode it in a custom LDAP method.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
bogentu
Znuny newbie
Posts: 17
Joined: 14 Feb 2011, 17:33
Znuny Version: 3.0.5

Re: Mapping LDAP Conditionals for Customer Backend

Post by bogentu »

Unfortunately, the displayName could be empty or not...depends on whether the use has updated their profile. I was tempted to get my hands really dirty and play with code, but would rather do something like this with the mapping command so that the configuration would survive an update with further modifications.
bogentu
Znuny newbie
Posts: 17
Joined: 14 Feb 2011, 17:33
Znuny Version: 3.0.5

Re: Mapping LDAP Conditionals for Customer Backend

Post by bogentu »

Any german speakers out there who could help translate the topic linked above?
bogentu
Znuny newbie
Posts: 17
Joined: 14 Feb 2011, 17:33
Znuny Version: 3.0.5

Re: Mapping LDAP Conditionals for Customer Backend

Post by bogentu »

crythias wrote: But on the other hand, you could hardcode it in a custom LDAP method.
I have been unable to figure out how to do this. I think what I need to do is modify Kernel/System/CustomerAuth/LDAP.pm so that when the map in Config.pm is used to query the ldap server, the conditional should be done. But I can't quite figure out how the OTRS variables are assigned from the LDAP query.

So what I need is: to set UserFirstname, check if displayName is defined. If so, assign it to UserFirstname. If not, use the default givenName.

I have some perl knowledge, but this is a bit beyond my skill set. Please, can anyone help?
bogentu
Znuny newbie
Posts: 17
Joined: 14 Feb 2011, 17:33
Znuny Version: 3.0.5

Re: Mapping LDAP Conditionals for Customer Backend

Post by bogentu »

I have finally figured out how to do this. I added the following to Kernel/System/CustomerUser/LDAP.pm around line 627:

Code: Select all

$Data{'UserFirstname'} = $Data{'UserPrefName'} if $Data{'UserPrefName'};
This sets the hash value to the user preferred name if it is not blank...seems to work great. Now I just have to remember to do this mod on future updates.
Locked