1 (edited by buzzzo 2013-02-04 19:06:41)

Topic: Use of sn attribute in iredmail/iredadmin LDAP

Hi

I've seen when creating a user thet on the ldif entry the attribute "sn" takes the uid field.
So if the user's mail is foo@bar.com then:

the uid attribute is: foo
the sn attribute  is: foo

Additionaly the web gui (iredadmin pro) show a field "uid" which does not translates in modifying the "uid" attribute, but the employenumber.

So the questions are:

1) is it possibile to set the "sn" attribute to the "cn" (tipically: First Name Last Name)
2) is there a reason to set the "sn" to the uid ? is this required for some internal iredmail's component ?
3) why not updating uid field instead of "employenumber" via the iredadmin gui ?

Thx for help in advance

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Use of sn attribute in iredmail/iredadmin LDAP

buzzzo wrote:

1) is it possibile to set the "sn" attribute to the "cn" (tipically: First Name Last Name)
2) is there a reason to set the "sn" to the uid ? is this required for some internal iredmail's component ?
3) why not updating uid field instead of "employenumber" via the iredadmin gui ?

Upcoming release will let admin to manage First Name (givenName), Last Name (sn), Display Name (cn), User/Employee ID (employeenumber). Screenshot:

http://iredmail.org/images/iredadmin/user_profile_general.png

3

Re: Use of sn attribute in iredmail/iredadmin LDAP

Very cool.

Have you planned a release date ?

thx

4

Re: Use of sn attribute in iredmail/iredadmin LDAP

In one month (iRedMail, iRedAPD, iRedAdmin-Pro). Below is patch for iRedAdmin-Pro-LDAP-1.8.1 if you want to give it a try. WARNING: Please backup files which are going to be patched before applying patch.

diff -r 68511236e5d3 -r dc949701c440 libs/ldaplib/attrs.py
--- a/libs/ldaplib/attrs.py    Fri Jan 04 22:30:15 2013 +0800
+++ b/libs/ldaplib/attrs.py    Sat Jan 05 15:39:52 2013 +0800
@@ -49,7 +49,7 @@
                       'domainGlobalAdmin', 'enabledService',
                       'objectClass',
                      ]
-ADMIN_ATTRS_ALL = ADMIN_SEARCH_ATTRS
+ADMIN_ATTRS_ALL = ADMIN_SEARCH_ATTRS + ['sn', 'givenName']
 
 # ---------------------------------------------------------
 # Domain related.
@@ -114,6 +114,7 @@
 ]
 
 USER_ATTRS_ALL = USER_SEARCH_ATTRS + [
+    'sn', 'givenName',
     'mobile', 'telephoneNumber', 'preferredLanguage', 'memberOfGroup',
     'userRecipientBccAddress', 'userSenderBccAddress',
     'mailForwardingAddress', 'mtaTransport',
diff -r 68511236e5d3 -r dc949701c440 templates/default/ldap/admin/profile.html
--- a/templates/default/ldap/admin/profile.html    Fri Jan 04 22:30:15 2013 +0800
+++ b/templates/default/ldap/admin/profile.html    Sat Jan 05 15:39:52 2013 +0800
@@ -25,8 +25,11 @@
 
 {% set entry = profile[0][1] %}
 {% set cn = entry.get('cn', [''])[0].decode('utf-8') %}
+{% set first_name = entry.get('givenName', [''])[0].decode('utf-8') |e %}
+{% set last_name = entry.get('sn', [''])[0].decode('utf-8') |e %}
 {% set accountStatus = entry.get('accountStatus', ['disabled'])[0] %}
 
+
 {% block breadcrumb %}
     {% set crumbs = [
             (ctx.homepath + '/admins', _('All admins'),),
@@ -66,7 +69,11 @@
                                     <div class="bt-space0">&nbsp;</div>
                                 {% endif %}
 
-                                {{ display_input_cn(cn=cn, accountType='admin') }}
+                                {{ display_input_cn(cn,
+                                                    tooltip=_('Full name'),
+                                                    show_first_last_name=true,
+                                                    first_name=first_name,
+                                                    last_name=last_name) }}
                                 {{ display_preferred_language(value=entry.get('preferredLanguage', ['en_US'])[0], languagemaps=languagemaps) }}
                             </div>
 
diff -r 68511236e5d3 -r dc949701c440 templates/default/ldap/user/profile.html
--- a/templates/default/ldap/user/profile.html    Fri Jan 04 22:30:15 2013 +0800
+++ b/templates/default/ldap/user/profile.html    Sat Jan 05 15:39:52 2013 +0800
@@ -60,13 +60,14 @@
 {% endif %}
 
 {% if profile_type == 'general' %}
+    {% set first_name = entries.get('givenName', [''])[0].decode('utf-8') |e %}
+    {% set last_name = entries.get('sn', [''])[0].decode('utf-8') |e %}
     {% set jobtitle = entries.get('title', [''])[0].decode('utf-8') |e %}
     {% set mobile = entries.get('mobile', [''])[0] |e %}
     {% set telephoneNumber = entries.get('telephoneNumber', []) %}
     {% set mailQuota = '%d' % (entries.get('mailQuota', [0])[0] |int /1024/1024) %}
     {% set usedQuota = accountUsedQuota.get(mail, {}).get('bytes', 0) %}
 
-    {#-- Member of Groups --#}
     {% set memberOfGroup = entries.get('memberOfGroup', []) %}
 
 {% elif profile_type == 'forwarding' %}
@@ -155,7 +156,11 @@
                 {{ display_in_global_address_book(enabledService=enabledService) }}
 
                 <div class="bt-space10"></div>
-                {{ display_input_cn(cn) }}
+                {{ display_input_cn(cn,
+                                    tooltip=_('Full name'),
+                                    show_first_last_name=true,
+                                    first_name=first_name,
+                                    last_name=last_name) }}
                 {{ display_preferred_language(value=entries.get('preferredLanguage', ['en_US'])[0], languagemaps=languagemaps) }}
                 {{ display_quota(value=mailQuota, show_value_in_input=true, used_quota=usedQuota, show_used_quota=true) }}
 
diff -r 68511236e5d3 -r dc949701c440 templates/default/macros/general.html
--- a/templates/default/macros/general.html    Fri Jan 04 22:30:15 2013 +0800
+++ b/templates/default/macros/general.html    Sat Jan 05 15:39:52 2013 +0800
@@ -81,7 +81,7 @@
         });
 
         {# tooltip #}
-        $("a[title], img[title], span[title]").tooltip({
+        $("a[title], img[title], span[title], input[title]").tooltip({
             position: "top center",
             offset: [-5, 0],
             predelay: 300,
@@ -90,14 +90,6 @@
             opacity: 1
         });
 
-        $("input[title]").tooltip({
-            position: "center right",
-            offset: [-2, 10],
-            delay: 100,
-            effect: "fade",
-            opacity: 1
-        });
-
         {% if 'tablesorter' in plugins %}
             $(".tablesorter").tablesorter(
                 {% if nonSortedCols |length > 0 %}
@@ -631,7 +623,7 @@
 {%- endmacro %}
 
 
-{% macro display_input_cn(cn='', name='cn', accountType='user', tooltip='', size="size-250") -%}
+{% macro display_input_cn(cn='', name='cn', accountType='user', tooltip='', size="size-250", show_first_last_name=false, first_name='', last_name='') -%}
     {% if cn is sameas none %}
         {% set cn = '' %}
     {% endif %}
@@ -647,6 +639,16 @@
             <input type="text" name="{{ name |e }}" value="{{ cn |e }}" size="35" class="text" {% if tooltip != '' %}title="{{ tooltip |e }}"{% endif %} />
         </span>
     </div>
+
+    {% if show_first_last_name is sameas true %}
+    <div class="form-field clear">
+        <h4 class="size-250 fl-space">&nbsp;</h4>
+        <span class="clean-padding bt-space20">
+            <input type="text" name="first_name" value="{{ first_name |e }}" size="15" class="text" title="{{ _('First name') }}" />
+            <input type="text" name="last_name" value="{{ last_name |e }}" size="15" class="text" title="{{ _('Last name') }}"/>
+        </span>
+    </div>
+    {% endif %}
 {%- endmacro %}

5

Re: Use of sn attribute in iredmail/iredadmin LDAP

Ive patched and receive some hunks, but seems to be applied successfully.
The gui shows the "first name" and "last name" fields, but when i save nothing happens: the modification are not applied to the ldap entry.

thx

6

Re: Use of sn attribute in iredmail/iredadmin LDAP

Oops, my mistake, i forgot another patch. So sorry about this.

Again, backup files which will be patched before applying this patch.

diff -r dc949701c440 -r 094b12353beb libs/ldaplib/admin.py
--- a/libs/ldaplib/admin.py    Sat Jan 05 15:39:52 2013 +0800
+++ b/libs/ldaplib/admin.py    Sun Jan 06 17:34:11 2013 +0800
@@ -103,6 +103,7 @@
     def update(self, profile_type, mail, data):
         self.profile_type = web.safestr(profile_type)
         self.mail = web.safestr(mail)
+        self.username, self.domain = self.mail.split('@', 1)
 
         if session.get('domainGlobalAdmin') is not True and session.get('username') != self.mail:
             # Don't allow to view/update other admins' profile.
@@ -118,7 +119,19 @@
 
             # Get cn.
             cn = data.get('cn', None)
-            mod_attrs += ldaputils.getSingleModAttr(attr='cn', value=cn, default=self.mail.split('@')[0],)
+            mod_attrs += ldaputils.getSingleModAttr(attr='cn',
+                                                    value=cn,
+                                                    default=self.username)
+
+            first_name = data.get('first_name', '')
+            mod_attrs += ldaputils.getSingleModAttr(attr='givenName',
+                                                    value=first_name,
+                                                    default=self.username)
+
+            last_name = data.get('last_name', '')
+            mod_attrs += ldaputils.getSingleModAttr(attr='sn',
+                                                    value=last_name,
+                                                    default=self.username)
 
             # Get accountStatus.
             if 'accountStatus' in data.keys():
diff -r dc949701c440 -r 094b12353beb libs/ldaplib/user.py
--- a/libs/ldaplib/user.py    Sat Jan 05 15:39:52 2013 +0800
+++ b/libs/ldaplib/user.py    Sun Jan 06 17:34:11 2013 +0800
@@ -435,7 +435,7 @@
     def update(self, profile_type, mail, data):
         self.profile_type = web.safestr(profile_type)
         self.mail = str(mail).lower()
-        self.domain = self.mail.split('@', 1)[-1]
+        self.username, self.domain = self.mail.split('@', 1)
 
         domainAccountSetting = {}
 
@@ -480,7 +480,19 @@
 
             # Get display name.
             cn = data.get('cn', None)
-            mod_attrs += ldaputils.getSingleModAttr(attr='cn', value=cn, default=self.mail.split('@')[0])
+            mod_attrs += ldaputils.getSingleModAttr(attr='cn',
+                                                    value=cn,
+                                                    default=self.username)
+
+            first_name = data.get('first_name', '')
+            mod_attrs += ldaputils.getSingleModAttr(attr='givenName',
+                                                    value=first_name,
+                                                    default=self.username)
+
+            last_name = data.get('last_name', '')
+            mod_attrs += ldaputils.getSingleModAttr(attr='sn',
+                                                    value=last_name,
+                                                    default=self.username)
 
             # Get preferred language: short lang code. e.g. en_US, de_DE.
             preferred_lang = web.safestr(data.get('preferredLanguage', 'en_US'))
diff -r dc949701c440 -r 094b12353beb templates/default/macros/general.html
--- a/templates/default/macros/general.html    Sat Jan 05 15:39:52 2013 +0800
+++ b/templates/default/macros/general.html    Sun Jan 06 17:34:11 2013 +0800
@@ -644,7 +644,7 @@
     <div class="form-field clear">
         <h4 class="size-250 fl-space">&nbsp;</h4>
         <span class="clean-padding bt-space20">
-            <input type="text" name="first_name" value="{{ first_name |e }}" size="15" class="text" title="{{ _('First name') }}" />
+            <input type="text" name="first_name" value="{{ first_name |e }}" size="14" class="text" title="{{ _('First name') }}" />
             <input type="text" name="last_name" value="{{ last_name |e }}" size="15" class="text" title="{{ _('Last name') }}"/>
         </span>
     </div>

7 (edited by buzzzo 2013-02-08 04:12:16)

Re: Use of sn attribute in iredmail/iredadmin LDAP

Thx ZhangHuangbin

Works perfectly

have fun.