Adds manager and direct reports to usershow page.

Fixes a bug with the group by member where is wasn't trapping not found errors.
This commit is contained in:
Kevin McCarthy 2007-09-25 15:44:49 -07:00
parent 765279d82b
commit fa7759684f
6 changed files with 71 additions and 3 deletions

View File

@ -68,6 +68,15 @@ class IPAClient:
result = self.transport.get_user_by_dn(dn,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
attributes will be returned, otherwise all available
attributes are returned. The result is a list of groups."""
results = self.transport.get_users_by_manager(manager_dn, sattrs)
return map(lambda result: user.User(result), results)
def add_user(self,user,user_container=None):
"""Add a user. user is a ipa.user.User object"""

View File

@ -101,6 +101,23 @@ class RPCClient:
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
attributes will be returned, otherwise all available
attributes are returned. The result is a list of dicts."""
server = self.setup_server()
if sattrs is None:
sattrs = "__NONE__"
try:
result = server.get_users_by_manager(manager_dn, 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 add_user(self,user,user_container=None):
"""Add a new user. Takes as input a dict where the key is the
attribute name and the value is either a string or in the case

View File

@ -252,8 +252,20 @@ class Root(controllers.RootController):
try:
user = client.get_user_by_uid(uid, user_fields)
user_groups = client.get_groups_by_member(user.dn, ['cn'])
user_reports = client.get_users_by_manager(user.dn,
['givenname', 'sn', 'uid'])
user_manager = None
try:
if user.manager:
user_manager = client.get_user_by_dn(user.manager,
['givenname', 'sn', 'uid'])
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
pass
return dict(user=user.toDict(), fields=forms.user.UserFields(),
user_groups=user_groups)
user_groups=user_groups, user_reports=user_reports,
user_manager=user_manager)
except ipaerror.IPAError, e:
turbogears.flash("User show failed: " + str(e))
raise turbogears.redirect("/")

View File

@ -78,6 +78,15 @@ else:
</th>
<td>${user.get("telephonenumber")}</td>
</tr>
<tr py:if='user_manager'>
<th>
Manager:
</th>
<td>
<a href="${tg.url('/usershow', uid=user_manager.uid)}"
>${user_manager.givenname} ${user_manager.sn}</a>
</td>
</tr>
</table>
<div class="formsection">Account Status</div>
@ -90,6 +99,12 @@ else:
</tr>
</table>
<div class="formsection" py:if='len(user_reports) &gt; 0'>Direct Reports</div>
<div py:for="report in user_reports">
<a href="${tg.url('/usershow', uid=report.uid)}"
>${report.givenname} ${report.sn}</a>
</div>
<div class="formsection">Groups</div>
<div py:for="group in user_groups">
<a href="${tg.url('/groupshow', cn=group.cn)}">${group.cn}</a>

View File

@ -308,7 +308,18 @@ class IPAServer:
filter = "(objectClass=*)"
return self.__get_entry(dn, filter, sattrs, opts)
def get_users_by_manager (self, manager_dn, sattrs=None, opts=None):
"""Gets the users that report to a particular manager.
"""
filter = "(&(objectClass=person)(manager=%s))" % manager_dn
try:
return self.__get_list(self.basedn, filter, sattrs, opts)
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
return []
def add_user (self, user, user_container=None, opts=None):
"""Add a user in LDAP. Takes as input a dict where the key is the
attribute name and the value is either a string or in the case
@ -601,7 +612,10 @@ class IPAServer:
filter = "(&(objectClass=posixGroup)(uniqueMember=%s))" % member_dn
return self.__get_list(self.basedn, filter, sattrs, opts)
try:
return self.__get_list(self.basedn, filter, sattrs, opts)
except ipaerror.exception_for(ipaerror.LDAP_NOT_FOUND):
return []
def add_group (self, group, group_container=None, opts=None):
"""Add a group in LDAP. Takes as input a dict where the key is the

View File

@ -316,6 +316,7 @@ def handler(req, profiling=False):
h = ModXMLRPCRequestHandler()
h.register_function(f.get_user_by_uid)
h.register_function(f.get_user_by_dn)
h.register_function(f.get_users_by_manager)
h.register_function(f.add_user)
h.register_function(f.get_add_schema)
h.register_function(f.get_all_users)