Some tweaks in user plugins, ported to new crud base classes
This commit is contained in:
1 parent
0211c76cd0
commit
92a150b4f1
3 files changed
+50
-17
No files matched your search
+27
-2
@@ -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):
|
||||
"""
|
||||
|
||||
+11
-10
@@ -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
|
||||
|
||||
@@ -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'),
|
||||
|
||||
Reference in new issue
Block a user