summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-29 00:38:16 -0700
committerRob Crittenden <rcritten@redhat.com>2009-02-03 15:29:05 -0500
commit92a150b4f11e18f29c9eb7719b9ff8a0d7759717 (patch)
tree46ac46d2580c377e6bdebca539a44863d22071ae /ipalib
parent0211c76cd0ce614b9c7510315dbadf5336667410 (diff)
downloadfreeipa-92a150b4f11e18f29c9eb7719b9ff8a0d7759717.tar.gz
freeipa-92a150b4f11e18f29c9eb7719b9ff8a0d7759717.tar.xz
freeipa-92a150b4f11e18f29c9eb7719b9ff8a0d7759717.zip
Some tweaks in user plugins, ported to new crud base classes
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/crud.py29
-rw-r--r--ipalib/frontend.py21
-rw-r--r--ipalib/plugins/f_user.py17
3 files changed, 50 insertions, 17 deletions
diff --git a/ipalib/crud.py b/ipalib/crud.py
index 5faa69ef3..a522ad84e 100644
--- a/ipalib/crud.py
+++ b/ipalib/crud.py
@@ -21,8 +21,7 @@
Base classes for standard CRUD operations.
"""
-import backend, frontend, errors
-
+import backend, frontend
class Add(frontend.Method):
def get_args(self):
@@ -78,6 +77,19 @@ class Create(frontend.Method):
Create a new entry.
"""
+ def get_args(self):
+ yield self.obj.primary_key
+
+ def get_options(self):
+ if self.extra_options_first:
+ for option in super(Create, self).get_options():
+ yield option
+ for option in self.obj.params_minus(self.args):
+ yield option
+ if not self.extra_options_first:
+ for option in super(Create, self).get_options():
+ yield option
+
class PKQuery(frontend.Method):
"""
@@ -88,6 +100,7 @@ class PKQuery(frontend.Method):
yield self.obj.primary_key.clone(query=True)
+
class Retrieve(PKQuery):
"""
Retrieve an entry by its primary key.
@@ -121,6 +134,18 @@ class Search(frontend.Method):
Retrieve all entries that match a given search criteria.
"""
+ takes_args = 'criteria?'
+
+ def get_options(self):
+ if self.extra_options_first:
+ for option in super(Search, self).get_options():
+ yield option
+ for option in self.obj.params_minus(self.args):
+ yield option.clone(query=True, required=False)
+ if not self.extra_options_first:
+ for option in super(Search, self).get_options():
+ yield option
+
class CrudBackend(backend.Connectible):
"""
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index fc436a7a9..54f7c87a0 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -345,6 +345,14 @@ class Command(plugable.Plugin):
)
super(Command, self).finalize()
+ def _get_takes(self, name):
+ attr = getattr(self, name)
+ if isinstance(attr, (Param, str)):
+ return (attr,)
+ if callable(attr):
+ return attr()
+ return attr
+
def get_args(self):
"""
Iterate through parameters for ``Command.args`` namespace.
@@ -353,11 +361,7 @@ class Command(plugable.Plugin):
are determined. For an example of why this can be useful,
see `ipalib.crud.Mod`.
"""
- if callable(self.takes_args):
- args = self.takes_args()
- else:
- args = self.takes_args
- for arg in args:
+ for arg in self._get_takes('takes_args'):
yield arg
def get_options(self):
@@ -368,11 +372,7 @@ class Command(plugable.Plugin):
are determined. For an example of why this can be useful,
see `ipalib.crud.Mod`.
"""
- if callable(self.takes_options):
- options = self.takes_options()
- else:
- options = self.takes_options
- for option in options:
+ for option in self._get_takes('takes_options'):
yield option
def __create_args(self):
@@ -437,6 +437,7 @@ class Object(plugable.Plugin):
'params',
'primary_key',
'params_minus_pk',
+ 'params_minus',
'get_dn',
))
backend = None
diff --git a/ipalib/plugins/f_user.py b/ipalib/plugins/f_user.py
index ce880b24e..04e0edb42 100644
--- a/ipalib/plugins/f_user.py
+++ b/ipalib/plugins/f_user.py
@@ -61,6 +61,7 @@ class user(Object):
),
Str('uid',
cli_name='user',
+ doc="User's login name",
primary_key=True,
default_from=lambda givenname, sn: givenname[0] + sn,
normalizer=lambda value: value.lower(),
@@ -107,8 +108,10 @@ class user(Object):
api.register(user)
-class user_add(crud.Add):
- 'Add a new user.'
+class user_add(crud.Create):
+ """
+ Add a new user.
+ """
def execute(self, uid, **kw):
"""
@@ -251,11 +254,15 @@ class user_mod(crud.Update):
api.register(user_mod)
-class user_find(crud.Find):
- 'Search the users.'
+class user_find(crud.Search):
+ """
+ Search for users.
+ """
+
takes_options = (
Flag('all', doc='Retrieve all user attributes'),
)
+
def execute(self, term, **kw):
ldap = self.api.Backend.ldap
@@ -301,7 +308,7 @@ class user_find(crud.Find):
api.register(user_find)
-class user_show(crud.Get):
+class user_show(crud.Retrieve):
'Examine an existing user.'
takes_options = (
Flag('all', doc='Retrieve all user attributes'),