This patch adds a proper summary text to HBAC command which is
then printed out in CLI. Now, HBAC plugin output is consistent
with other plugins.

https://fedorahosted.org/freeipa/ticket/596

>From f4eb55df4a54bfcf24e3357b6484f0916fe204e5 Mon Sep 17 00:00:00 2001
From: Martin Kosek <mko...@redhat.com>
Date: Fri, 4 Feb 2011 14:03:30 +0100
Subject: [PATCH] HBAC plugin inconsistent output

This patch adds a proper summary text to HBAC command which is
then printed out in CLI. Now, HBAC plugin output is consistent
with other plugins.

https://fedorahosted.org/freeipa/ticket/596
---
 ipalib/plugins/hbacrule.py |   37 +++++++++++++++++++++++++++----------
 ipalib/plugins/hbacsvc.py  |   10 ++++++++--
 2 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/ipalib/plugins/hbacrule.py b/ipalib/plugins/hbacrule.py
index b834a141061a6a5b64dba97b24a32f77824ef0a4..b2d0e92c8b35cdbf10189b20a4e47f2a96435231 100644
--- a/ipalib/plugins/hbacrule.py
+++ b/ipalib/plugins/hbacrule.py
@@ -211,6 +211,9 @@ class hbacrule_add(LDAPCreate):
     """
     Create a new HBAC rule.
     """
+
+    msg_summary = _('Added HBAC rule "%(value)s"')
+
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
         # HBAC rules are enabled by default
         entry_attrs['ipaenabledflag'] = 'TRUE'
@@ -224,6 +227,8 @@ class hbacrule_del(LDAPDelete):
     Delete an HBAC rule.
     """
 
+    msg_summary = _('Deleted HBAC rule "%(value)s"')
+
 api.register(hbacrule_del)
 
 
@@ -232,6 +237,8 @@ class hbacrule_mod(LDAPUpdate):
     Modify an HBAC rule.
     """
 
+    msg_summary = _('Modified HBAC rule "%(value)s"')
+
     def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
         try:
             (dn, entry_attrs) = ldap.get_entry(dn, attrs_list)
@@ -256,6 +263,10 @@ class hbacrule_find(LDAPSearch):
     Search for HBAC rules.
     """
 
+    msg_summary = ngettext(
+        '%(count)d rule matched', '%(count)d rules matched', 0
+    )
+
 api.register(hbacrule_find)
 
 
@@ -271,6 +282,10 @@ class hbacrule_enable(LDAPQuery):
     """
     Enable an HBAC rule.
     """
+
+    msg_summary = _('Enabled HBAC rule "%(value)s"')
+    has_output = output.standard_value
+
     def execute(self, cn):
         ldap = self.obj.backend
 
@@ -284,11 +299,10 @@ class hbacrule_enable(LDAPQuery):
         except errors.NotFound:
             self.obj.handle_not_found(cn)
 
-        return dict(result=True)
-
-    def output_for_cli(self, textui, result, cn):
-        textui.print_name(self.name)
-        textui.print_dashed('Enabled HBAC rule "%s".' % cn)
+        return dict(
+            result=True,
+            value=cn,
+        )
 
 api.register(hbacrule_enable)
 
@@ -297,6 +311,10 @@ class hbacrule_disable(LDAPQuery):
     """
     Disable an HBAC rule.
     """
+
+    msg_summary = _('Disabled HBAC rule "%(value)s"')
+    has_output = output.standard_value
+
     def execute(self, cn):
         ldap = self.obj.backend
 
@@ -310,11 +328,10 @@ class hbacrule_disable(LDAPQuery):
         except errors.NotFound:
             self.obj.handle_not_found(cn)
 
-        return dict(result=True)
-
-    def output_for_cli(self, textui, result, cn):
-        textui.print_name(self.name)
-        textui.print_dashed('Disabled HBAC rule "%s".' % cn)
+        return dict(
+            result=True,
+            value=cn,
+        )
 
 api.register(hbacrule_disable)
 
diff --git a/ipalib/plugins/hbacsvc.py b/ipalib/plugins/hbacsvc.py
index 282f927ca573432d96025c3d07a3561cc15b362f..6bb55497354d0120a4b70c76294f327f699be034 100644
--- a/ipalib/plugins/hbacsvc.py
+++ b/ipalib/plugins/hbacsvc.py
@@ -82,7 +82,7 @@ class hbacsvc_add(LDAPCreate):
     """
     Add a new HBAC service.
     """
-    msg_summary = _('Added service "%(value)s"')
+    msg_summary = _('Added HBAC service "%(value)s"')
 
 api.register(hbacsvc_add)
 
@@ -91,7 +91,7 @@ class hbacsvc_del(LDAPDelete):
     """
     Delete an existing HBAC service.
     """
-    msg_summary = _('Deleted service "%(value)s"')
+    msg_summary = _('Deleted HBAC service "%(value)s"')
 
 api.register(hbacsvc_del)
 
@@ -101,6 +101,8 @@ class hbacsvc_mod(LDAPUpdate):
     Modify an HBAC service.
     """
 
+    msg_summary = _('Modified HBAC service "%(value)s"')
+
 api.register(hbacsvc_mod)
 
 
@@ -109,6 +111,10 @@ class hbacsvc_find(LDAPSearch):
     Search for HBAC services.
     """
 
+    msg_summary = ngettext(
+        '%(count)d service matched', '%(count)d services matched', 0
+    )
+
 api.register(hbacsvc_find)
 
 
-- 
1.7.4

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

Reply via email to