summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/selfservice.py
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2012-02-02 21:28:15 +0100
committerMartin Kosek <mkosek@redhat.com>2012-02-03 17:04:51 +0100
commitcf12f3106a7f55fbdb03d64588e8201f14470fe8 (patch)
tree2ac3a5941caca7bd85fe50712684712f315a117c /ipalib/plugins/selfservice.py
parent2e860f6d070db3b2fe8799891c3e568ac48a1fac (diff)
downloadfreeipa-cf12f3106a7f55fbdb03d64588e8201f14470fe8.tar.gz
freeipa-cf12f3106a7f55fbdb03d64588e8201f14470fe8.tar.xz
freeipa-cf12f3106a7f55fbdb03d64588e8201f14470fe8.zip
Fix raw format for ACI commands
ACI plugins (permission, selfservice and delegation) were not prepared to serve ACIs in a raw format, i.e. raw "aci" attribute taken from LDAP. This patch fixes all these plugins and their commands to provide provide this format. Few ACI raw format unit tests were added for all these plugins. https://fedorahosted.org/freeipa/ticket/2010 https://fedorahosted.org/freeipa/ticket/2223 https://fedorahosted.org/freeipa/ticket/2228 https://fedorahosted.org/freeipa/ticket/2232
Diffstat (limited to 'ipalib/plugins/selfservice.py')
-rw-r--r--ipalib/plugins/selfservice.py46
1 files changed, 23 insertions, 23 deletions
diff --git a/ipalib/plugins/selfservice.py b/ipalib/plugins/selfservice.py
index 2db376479..6f843d469 100644
--- a/ipalib/plugins/selfservice.py
+++ b/ipalib/plugins/selfservice.py
@@ -54,17 +54,11 @@ EXAMPLES:
ACI_PREFIX=u"selfservice"
-def is_selfservice(aciname):
- """
- Determine if the ACI is a Self-service ACI and raise an exception if it
- isn't.
-
- Return the result if it is a self-service ACI.
- """
- result = api.Command['aci_show'](aciname, aciprefix=ACI_PREFIX)['result']
- if 'selfaci' not in result or result['selfaci'] == False:
- raise errors.NotFound(reason=_('Self-service permission \'%(permission)s\' not found') % dict(permission=aciname))
- return result
+output_params = (
+ Str('aci',
+ label=_('ACI'),
+ ),
+)
class selfservice(Object):
"""
@@ -112,6 +106,13 @@ class selfservice(Object):
json_dict['methods'] = [m for m in self.methods]
return json_dict
+ def postprocess_result(self, result):
+ try:
+ # do not include prefix in result
+ del result['aciprefix']
+ except KeyError:
+ pass
+
api.register(selfservice)
@@ -119,6 +120,7 @@ class selfservice_add(crud.Create):
__doc__ = _('Add a new self-service permission.')
msg_summary = _('Added selfservice "%(value)s"')
+ has_output_params = output_params
def execute(self, aciname, **kw):
if not 'permissions' in kw:
@@ -126,7 +128,7 @@ class selfservice_add(crud.Create):
kw['selfaci'] = True
kw['aciprefix'] = ACI_PREFIX
result = api.Command['aci_add'](aciname, **kw)['result']
- del result['aciprefix'] # do not include prefix in result
+ self.obj.postprocess_result(result)
return dict(
result=result,
@@ -143,9 +145,9 @@ class selfservice_del(crud.Delete):
msg_summary = _('Deleted selfservice "%(value)s"')
def execute(self, aciname, **kw):
- is_selfservice(aciname)
kw['aciprefix'] = ACI_PREFIX
result = api.Command['aci_del'](aciname, **kw)
+ self.obj.postprocess_result(result)
return dict(
result=True,
@@ -159,15 +161,16 @@ class selfservice_mod(crud.Update):
__doc__ = _('Modify a self-service permission.')
msg_summary = _('Modified selfservice "%(value)s"')
+ has_output_params = output_params
def execute(self, aciname, **kw):
- is_selfservice(aciname)
if 'attrs' in kw and kw['attrs'] is None:
raise errors.RequirementError(name='attrs')
kw['aciprefix'] = ACI_PREFIX
result = api.Command['aci_mod'](aciname, **kw)['result']
- del result['aciprefix'] # do not include prefix in result
+ self.obj.postprocess_result(result)
+
return dict(
result=result,
value=aciname,
@@ -184,6 +187,7 @@ class selfservice_find(crud.Search):
)
takes_options = (gen_pkey_only_option("name"),)
+ has_output_params = output_params
def execute(self, term, **kw):
kw['selfaci'] = True
@@ -191,7 +195,7 @@ class selfservice_find(crud.Search):
result = api.Command['aci_find'](term, **kw)['result']
for aci in result:
- del aci['aciprefix'] # do not include prefix in result
+ self.obj.postprocess_result(aci)
return dict(
result=result,
@@ -205,15 +209,11 @@ api.register(selfservice_find)
class selfservice_show(crud.Retrieve):
__doc__ = _('Display information about a self-service permission.')
- has_output_params = (
- Str('aci',
- label=_('ACI'),
- ),
- )
+ has_output_params = output_params
def execute(self, aciname, **kw):
- result = is_selfservice(aciname)
- del result['aciprefix'] # do not include prefix in result
+ result = api.Command['aci_show'](aciname, aciprefix=ACI_PREFIX, **kw)['result']
+ self.obj.postprocess_result(result)
return dict(
result=result,
value=aciname,