The UI team had asked that we provide some group info (GID, description) when showing users. This ads a special call to group_find to get this information. It is returned as a list of dicts.

ticket 107

rob
>From 1aa0f8cd7915bc277a96a46045158949ee84ff33 Mon Sep 17 00:00:00 2001
From: Rob Crittenden <rcrit...@redhat.com>
Date: Fri, 13 May 2011 16:03:56 -0400
Subject: [PATCH] Add option to obtain group information when showing a user.

The UI would like to include details on the group when showing
a user. This patch adds a groupinfo attribute which contains
a list of dict entries representing each group. --all must be
used for this to work, it isn't a default attribute.

The CLI will display some basic output when this is used but it
is really designed for the UI.

ticket 107
---
 API.txt                |    3 ++-
 ipalib/cli.py          |   18 ++++++++++++------
 ipalib/plugins/user.py |   11 +++++++++++
 3 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/API.txt b/API.txt
index cd37b67..16084d3 100644
--- a/API.txt
+++ b/API.txt
@@ -2661,9 +2661,10 @@ output: Output('summary', (<type 'unicode'>, <type 'NoneType'>), 'User-friendly
 output: Entry('result', <type 'dict'>, Gettext('A dictionary representing an LDAP entry', domain='ipa', localedir=None))
 output: Output('value', <type 'unicode'>, "The primary_key value of the entry, e.g. 'jdoe' for a user")
 command: user_show
-args: 1,4,3
+args: 1,5,3
 arg: Str('uid', attribute=True, cli_name='login', default_from=DefaultFrom(<lambda>, 'givenname', 'sn'), label=Gettext('User login', domain='ipa', localedir=None), maxlength=255, multivalue=False, normalizer=<lambda>, pattern='^[a-zA-Z0-9_.][a-zA-Z0-9_.-]{0,252}[a-zA-Z0-9_.$-]?$', pattern_errmsg='may only include letters, numbers, _, -, . and $', primary_key=True, query=True, required=True)
 option: Flag('rights', autofill=True, default=False, label=Gettext('Rights', domain='ipa', localedir=None))
+option: Flag('groupinfo', autofill=True, default=False, label=Gettext('Group Information', domain='ipa', localedir=None))
 option: Flag('all', autofill=True, cli_name='all', default=False, exclude='webui', flags=['no_output'])
 option: Flag('raw', autofill=True, cli_name='raw', default=False, exclude='webui', flags=['no_output'])
 option: Str('version?', exclude='webui', flags=['no_option', 'no_output'])
diff --git a/ipalib/cli.py b/ipalib/cli.py
index 99f236b..c172a04 100644
--- a/ipalib/cli.py
+++ b/ipalib/cli.py
@@ -290,7 +290,10 @@ class textui(backend.Backend):
                         self.print_indented(format % (attr, self.encode_binary(text)), indent)
                     return
                 else:
-                    if len(value) > 0:
+                    if type(value) in (tuple, list) and isinstance(value[0], dict):
+                        self.print_entries(value, None, {}, spacing=False)
+                        return
+                    elif len(value) > 0:
                         text = ', '.join(value)
                     else:
                         return
@@ -337,11 +340,11 @@ class textui(backend.Backend):
         for attr in sorted(entry):
             print_attr(attr)
 
-    def print_entries(self, entries, order=None, labels=None, flags=None, print_all=True, format='%s: %s', indent=1):
+    def print_entries(self, entries, order=None, labels=None, flags=None, print_all=True, format='%s: %s', indent=1, spacing=True):
         assert isinstance(entries, (list, tuple))
         first = True
         for entry in entries:
-            if not first:
+            if not first and spacing:
                 print ''
             first = False
             self.print_entry(entry, order, labels, flags, print_all, format, indent)
@@ -382,9 +385,12 @@ class textui(backend.Backend):
         if print_all:
             for key in sorted(entry):
                 label = labels.get(key, key)
-                self.print_attribute(
-                    key, entry[key], format, indent, one_value_per_line
-                )
+                if type(entry[key]) in (tuple, list) and isinstance(entry[key][0], dict):
+                    self.print_entries(entry[key], order, {}, flags, print_all, format, indent=indent, spacing=False)
+                else:
+                    self.print_attribute(
+                        key, entry[key], format, indent, one_value_per_line
+                    )
 
     def print_dashed(self, string, above=True, below=True, indent=0, dash='-'):
         """
diff --git a/ipalib/plugins/user.py b/ipalib/plugins/user.py
index a058ff7..e9828a3 100644
--- a/ipalib/plugins/user.py
+++ b/ipalib/plugins/user.py
@@ -440,7 +440,18 @@ class user_show(LDAPRetrieve):
     """
     Display information about a user.
     """
+
+    takes_options = LDAPRetrieve.takes_options + (
+        Flag('groupinfo',
+            label=_('Group Information'),
+            doc=_('Display detailed group information, must be used with --all'),
+        ),
+    )
+
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
+        if options.get('groupinfo', False):
+            groups = self.api.Command['group_find'](None, user=keys[0])
+            entry_attrs['groupinfo'] = groups['result']
         if not 'nsaccountlock' in entry_attrs:
             entry_attrs['nsaccountlock'] = [u'False']
         self.obj._convert_manager(entry_attrs, **options)
-- 
1.7.4

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to