summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Vobornik <pvoborni@redhat.com>2012-09-05 14:35:44 +0200
committerPetr Vobornik <pvoborni@redhat.com>2012-09-06 10:27:10 +0200
commit07cae43484911ddf87b87d7d3399f7b09378f8fe (patch)
tree699208a7a584a7bc03b6a6fc2f7389a43d8243c7
parent6a8d6d3fde0ede2e0b976cd5af67a57c0691b1f8 (diff)
downloadfreeipa-07cae43484911ddf87b87d7d3399f7b09378f8fe.tar.gz
freeipa-07cae43484911ddf87b87d7d3399f7b09378f8fe.tar.xz
freeipa-07cae43484911ddf87b87d7d3399f7b09378f8fe.zip
Fixed metadata serialization of Numbers and DNs
There were following problems: 1. DNs and Decimals weren't properly serialized. Serialization output was object with empty __base64__ attribute. It was fixed by converting them to string. 2. numberical values equal to 0 were excluded from metadata. It broke many of minvalue checks in Web UI. Now excluding only None and False values as initally intended. https://fedorahosted.org/freeipa/ticket/3052
-rw-r--r--ipalib/parameters.py7
-rw-r--r--ipalib/plugins/baseldap.py2
-rw-r--r--ipalib/util.py3
3 files changed, 8 insertions, 4 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index de0d14faf..e839a0e75 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -112,6 +112,7 @@ from errors import ConversionError, RequirementError, ValidationError
from errors import PasswordMismatch, Base64DecodeError
from constants import NULLS, TYPE_ERROR, CALLABLE_ERROR
from text import Gettext, FixMe
+from util import json_serialize
from ipapython.dn import DN
class DefaultFrom(ReadOnly):
@@ -978,11 +979,11 @@ class Param(ReadOnly):
json_dict[a] = [k for k in getattr(self, a, [])]
else:
val = getattr(self, a, '')
- if val is None or not val:
- # ignore false and not set because lack of their presence is
+ if val is None or val is False:
+ # ignore False and not set because lack of their presence is
# the information itself
continue;
- json_dict[a] = val
+ json_dict[a] = json_serialize(val)
json_dict['class'] = self.__class__.__name__
json_dict['name'] = self.name
json_dict['type'] = self.type.__name__
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 3dcb2d39f..6a054ffd8 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -628,7 +628,7 @@ class LDAPObject(Object):
def __json__(self):
ldap = self.backend
json_dict = dict(
- (a, getattr(self, a)) for a in self.json_friendly_attributes
+ (a, json_serialize(getattr(self, a))) for a in self.json_friendly_attributes
)
if self.primary_key:
json_dict['primary_key'] = self.primary_key.name
diff --git a/ipalib/util.py b/ipalib/util.py
index 44f08e7f6..155d93294 100644
--- a/ipalib/util.py
+++ b/ipalib/util.py
@@ -26,6 +26,7 @@ import imp
import time
import socket
import re
+import decimal
from types import NoneType
from weakref import WeakKeyDictionary
from dns import resolver, rdatatype
@@ -46,6 +47,8 @@ def json_serialize(obj):
return obj
if isinstance(obj, str):
return obj.decode('utf-8')
+ if isinstance(obj, (decimal.Decimal, DN)):
+ return str(obj)
if not callable(getattr(obj, '__json__', None)):
# raise TypeError('%r is not JSON serializable')
return ''