So far the only way to enforce asking for parameter in interactive mode was 
the alwaysask attribute, which is not sufficient any more. This patch adds the 
ability to control during which actions the atrribute shall be asked for.

Jan
From 96a8b94e877f6f6bc2d5cbd274d46aa66df85b88 Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jzel...@redhat.com>
Date: Tue, 25 Jan 2011 09:06:19 -0500
Subject: [PATCH] Add flags to enforce asking for object attribute

So far the only flag to enforce asking in interactive mode was the
alwaysask attribute, which is not sufficient any more. This patch adds
the ability to control for which actions the atrribute shall be asked
for.
---
 ipalib/crud.py               |   23 ++++++++++++++++++++---
 ipalib/plugins/permission.py |   12 ++++++------
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/ipalib/crud.py b/ipalib/crud.py
index 76d57daef68128bafab923ce00c7afe0e290966d..b7a665361804b853da4f00de5ab2b2030c9de86c 100644
--- a/ipalib/crud.py
+++ b/ipalib/crud.py
@@ -141,7 +141,13 @@ class Create(Method):
         for option in self.obj.params_minus(self.args):
             if 'no_create' in option.flags:
                 continue
-            yield option.clone(attribute=True)
+            if 'ask_create' in option.flags:
+                yield option.clone(
+                    attribute=True, query=True, required=False,
+                    autofill=False, alwaysask=True
+                )
+            else:
+                yield option.clone(attribute=True)
         if not self.extra_options_first:
             for option in super(Create, self).get_options():
                 yield option
@@ -179,7 +185,13 @@ class Update(PKQuery):
         for option in self.obj.params_minus_pk():
             if 'no_update' in option.flags:
                 continue
-            yield option.clone(attribute=True, required=False, autofill=False)
+            if 'ask_update' in option.flags:
+                yield option.clone(
+                    attribute=True, query=True, required=False,
+                    autofill=False, alwaysask=True
+                )
+            else:
+                yield option.clone(attribute=True, required=False, autofill=False)
         if not self.extra_options_first:
             for option in super(Update, self).get_options():
                 yield option
@@ -210,7 +222,12 @@ class Search(Method):
         for option in self.obj.params_minus(self.args):
             if 'no_search' in option.flags:
                 continue
-            if isinstance(option, parameters.Flag):
+            if 'ask_search' in option.flags:
+                yield option.clone(
+                    attribute=True, query=True, required=False,
+                    autofill=False, alwaysask=True
+                )
+            elif isinstance(option, parameters.Flag):
                 yield option.clone_retype(
                     option.name, parameters.Bool,
                     attribute=True, query=True, required=False, autofill=False
diff --git a/ipalib/plugins/permission.py b/ipalib/plugins/permission.py
index e97174abfaa855a36552dcfdc55049c58cb5c312..14d7b96569cc9e228bebaac37d67d6709039e164 100644
--- a/ipalib/plugins/permission.py
+++ b/ipalib/plugins/permission.py
@@ -116,38 +116,38 @@ class permission(LDAPObject):
             label=_('Attributes'),
             doc=_('Comma-separated list of attributes'),
             normalizer=lambda value: value.lower(),
-            alwaysask=True,
+            flags=('ask_create', 'ask_update'),
         ),
         StrEnum('type?',
             cli_name='type',
             label=_('Type'),
             doc=_('Type of IPA object (user, group, host, hostgroup, service, netgroup, dns)'),
             values=(u'user', u'group', u'host', u'service', u'hostgroup', u'netgroup', u'dns',),
-            alwaysask=True,
+            flags=('ask_create', 'ask_update'),
         ),
         Str('memberof?',
             cli_name='memberof',
             label=_('Member of group'),  # FIXME: Does this label make sense?
             doc=_('Target members of a group'),
-            alwaysask=True,
+            flags=('ask_create', 'ask_update'),
         ),
         Str('filter?',
             cli_name='filter',
             label=_('Filter'),
             doc=_('Legal LDAP filter (e.g. ou=Engineering)'),
-            alwaysask=True,
+            flags=('ask_create', 'ask_update'),
         ),
         Str('subtree?',
             cli_name='subtree',
             label=_('Subtree'),
             doc=_('Subtree to apply permissions to'),
-            alwaysask=True,
+            flags=('ask_create', 'ask_update'),
         ),
         Str('targetgroup?',
             cli_name='targetgroup',
             label=_('Target group'),
             doc=_('User group to apply permissions to'),
-            alwaysask=True,
+            flags=('ask_create', 'ask_update'),
         ),
     )
 
-- 
1.7.3.4

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

Reply via email to