mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2024-12-26 17:01:14 -06:00
Finish the email autosuggest.
For now I've added a new API call. The field-specific searching is a ways off.
This commit is contained in:
parent
f018c2123c
commit
5e651a6496
@ -98,6 +98,13 @@ class IPAClient:
|
||||
result = self.transport.get_user_by_principal(principal,sattrs)
|
||||
return user.User(result)
|
||||
|
||||
def get_user_by_email(self,email,sattrs=None):
|
||||
"""Get a specific user's entry. Return as a dict of values.
|
||||
Multi-valued fields are represented as lists.
|
||||
"""
|
||||
result = self.transport.get_user_by_email(email,sattrs)
|
||||
return user.User(result)
|
||||
|
||||
def get_users_by_manager(self,manager_dn,sattrs=None):
|
||||
"""Gets the users the report to a particular manager.
|
||||
If sattrs is not None then only those
|
||||
|
@ -165,7 +165,23 @@ class RPCClient:
|
||||
raise xmlrpclib.Fault(value, msg)
|
||||
|
||||
return ipautil.unwrap_binary_data(result)
|
||||
|
||||
|
||||
def get_user_by_email(self,email,sattrs=None):
|
||||
"""Get a specific user's entry. Return as a dict of values.
|
||||
Multi-valued fields are represented as lists.
|
||||
"""
|
||||
server = self.setup_server()
|
||||
if sattrs is None:
|
||||
sattrs = "__NONE__"
|
||||
try:
|
||||
result = server.get_user_by_email(email, sattrs)
|
||||
except xmlrpclib.Fault, fault:
|
||||
raise ipaerror.gen_exception(fault.faultCode, fault.faultString)
|
||||
except socket.error, (value, msg):
|
||||
raise xmlrpclib.Fault(value, msg)
|
||||
|
||||
return ipautil.unwrap_binary_data(result)
|
||||
|
||||
def get_users_by_manager(self,manager_dn,sattrs=None):
|
||||
"""Gets the users that report to a manager.
|
||||
If sattrs is not None then only those
|
||||
|
@ -17,6 +17,7 @@ import ipa.user
|
||||
from ipa.entity import utf8_encode_values
|
||||
from ipa import ipaerror
|
||||
import ipagui.forms.user
|
||||
import ipa.config
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -27,6 +28,8 @@ user_edit_form = ipagui.forms.user.UserEditForm()
|
||||
|
||||
user_fields = ['*', 'nsAccountLock']
|
||||
|
||||
email_domain = ipa.config.config.default_realm.lower()
|
||||
|
||||
class UserController(IPAController):
|
||||
|
||||
@expose()
|
||||
@ -518,31 +521,16 @@ class UserController(IPAController):
|
||||
givenname = givenname.lower()
|
||||
sn = sn.lower()
|
||||
|
||||
# TODO - get from config
|
||||
domain = "freeipa.org"
|
||||
email = "%s.%s@%s" % (givenname, sn, email_domain)
|
||||
try:
|
||||
client.get_user_by_email(email)
|
||||
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
|
||||
return email
|
||||
|
||||
return "%s.%s@%s" % (givenname, sn, domain)
|
||||
email = "%s@%s" % (self.suggest_uid(givenname, sn), email_domain)
|
||||
try:
|
||||
client.get_user_by_email(email)
|
||||
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
|
||||
return email
|
||||
|
||||
|
||||
# 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 ""
|
||||
return ""
|
||||
|
@ -377,7 +377,16 @@ class IPAServer:
|
||||
|
||||
filter = "(krbPrincipalName="+self.__safe_filter(principal)+")"
|
||||
return self.__get_sub_entry(self.basedn, filter, sattrs, opts)
|
||||
|
||||
|
||||
def get_user_by_email (self, email, sattrs=None, opts=None):
|
||||
"""Get a specific user's entry. Return as a dict of values.
|
||||
Multi-valued fields are represented as lists.
|
||||
"""
|
||||
|
||||
email = self.__safe_filter(email)
|
||||
filter = "(mail=" + email + ")"
|
||||
return self.__get_sub_entry(self.basedn, filter, sattrs, opts)
|
||||
|
||||
def get_users_by_manager (self, manager_dn, sattrs=None, opts=None):
|
||||
"""Gets the users that report to a particular manager.
|
||||
"""
|
||||
|
@ -323,6 +323,7 @@ def handler(req, profiling=False):
|
||||
h.register_function(f.update_entry)
|
||||
h.register_function(f.get_user_by_uid)
|
||||
h.register_function(f.get_user_by_principal)
|
||||
h.register_function(f.get_user_by_email)
|
||||
h.register_function(f.get_users_by_manager)
|
||||
h.register_function(f.add_user)
|
||||
h.register_function(f.get_add_schema)
|
||||
|
Loading…
Reference in New Issue
Block a user