From 90a34f386555ca8352e38b6186136a6750517116 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Thu, 30 Aug 2007 15:10:48 -0700 Subject: Add auto-suggest for uid and email fields. --- ipa-server/ipa-gui/ipagui/controllers.py | 76 ++++++++++++++++++ ipa-server/ipa-gui/ipagui/templates/master.kid | 1 + .../ipa-gui/ipagui/templates/usereditform.kid | 56 +++++++------- .../ipa-gui/ipagui/templates/usernewform.kid | 89 +++++++++++++++------- ipa-server/ipa-gui/ipagui/templates/usershow.kid | 30 ++++---- 5 files changed, 181 insertions(+), 71 deletions(-) (limited to 'ipa-server') diff --git a/ipa-server/ipa-gui/ipagui/controllers.py b/ipa-server/ipa-gui/ipagui/controllers.py index d767f2686..5771ebe31 100644 --- a/ipa-server/ipa-gui/ipagui/controllers.py +++ b/ipa-server/ipa-gui/ipagui/controllers.py @@ -189,6 +189,82 @@ class Root(controllers.RootController): return password + @expose() + def suggest_uid(self, givenname, sn): + if (len(givenname) == 0) or (len(sn) == 0): + return "" + + uid = givenname[0] + sn[:7] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + uid = givenname[:7] + sn[0] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + uid = (givenname + sn)[:8] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + uid = sn[:8] + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + + suffix = 2 + template = givenname[0] + sn[:7] + while suffix < 20: + uid = template[:8 - len(str(suffix))] + str(suffix) + try: + client.get_user_by_uid(uid) + except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND): + return uid + suffix += 1 + + return "" + + @expose() + def suggest_email(self, givenname, sn): + if (len(givenname) == 0) or (len(sn) == 0): + return "" + + # TODO - get from config + domain = "freeipa.org" + + return "%s.%s@%s" % (givenname, sn, domain) + + + # TODO - mail is currently not indexed nor searchable. + # implement when it's done + # email = givenname + "." + sn + domain + # users = client.find_users(email, ['mail']) + # if len(filter(lambda u: u['mail'] == email, users[1:])) == 0: + # return email + + # email = self.suggest_uid(givenname, sn) + domain + # users = client.find_users(email, ['mail']) + # if len(filter(lambda u: u['mail'] == email, users[1:])) == 0: + # return email + + # suffix = 2 + # template = givenname + "." + sn + # while suffix < 20: + # email = template + str(suffix) + domain + # users = client.find_users(email, ['mail']) + # if len(filter(lambda u: u['mail'] == email, users[1:])) == 0: + # return email + # suffix += 1 + + # return "" + + ######### # Group # diff --git a/ipa-server/ipa-gui/ipagui/templates/master.kid b/ipa-server/ipa-gui/ipagui/templates/master.kid index 8e8d26551..2f39afc41 100644 --- a/ipa-server/ipa-gui/ipagui/templates/master.kid +++ b/ipa-server/ipa-gui/ipagui/templates/master.kid @@ -10,6 +10,7 @@ @import "${tg.url('/static/css/style.css')}"; + diff --git a/ipa-server/ipa-gui/ipagui/templates/usereditform.kid b/ipa-server/ipa-gui/ipagui/templates/usereditform.kid index 771d94d49..cef7f116d 100644 --- a/ipa-server/ipa-gui/ipagui/templates/usereditform.kid +++ b/ipa-server/ipa-gui/ipagui/templates/usereditform.kid @@ -7,6 +7,34 @@ py:replace="field.display(value_for(field), **params_for(field))" /> +
Identity Details
+ + + + + + + + + + +
+ + + + +
+ + + +
+
Account Details
@@ -85,34 +113,6 @@
-
Identity Details
- - - - - - - - - - -
- - - - -
- - - -
-
Contact Details
diff --git a/ipa-server/ipa-gui/ipagui/templates/usernewform.kid b/ipa-server/ipa-gui/ipagui/templates/usernewform.kid index df5fd55fc..c766327f0 100644 --- a/ipa-server/ipa-gui/ipagui/templates/usernewform.kid +++ b/ipa-server/ipa-gui/ipagui/templates/usernewform.kid @@ -2,6 +2,67 @@ class="simpleroster"> +
Identity Details
+
+ + + + + + + + + +
+ + + + +
+ + + + +
+
Account Details
@@ -63,34 +124,6 @@
-
Identity Details
- - - - - - - - - - -
- - - - -
- - - -
-
Contact Details
diff --git a/ipa-server/ipa-gui/ipagui/templates/usershow.kid b/ipa-server/ipa-gui/ipagui/templates/usershow.kid index c21ff12bb..2ffd1a4e9 100644 --- a/ipa-server/ipa-gui/ipagui/templates/usershow.kid +++ b/ipa-server/ipa-gui/ipagui/templates/usershow.kid @@ -8,41 +8,41 @@

View Person

-
Account Details
+
Identity Details
- + - + +
- ${user.get("uid")}${user.get("givenname")}
- ${user.get("uidnumber")}${user.get("sn")}
+ +
Account Details
+ - + -
- ${user.get("gidnumber")}${user.get("uid")}
- -
Identity Details
- - + - +
- ${user.get("givenname")}${user.get("uidnumber")}
- ${user.get("sn")}${user.get("gidnumber")}
-- cgit