mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Change json serialization to serialize useful data
json_metadata command creates and sends metadata needed by Web UI. It uses __json__ method for serialization of commands, options, objects... . A lot of data sent was useless for Web UI and some usefull information were missing. We * mostly CLI specific option attribues are not send. * attributes evaluated to false or None are not send * options which are send are not got from takes_aptions attribute but by get_options() method. It finally sends usefull option collection for commands part of metadata. In the end the raw amount of data send is aproximately the same. This patch is needed for Web UI to determine which option it can use in which commands. https://fedorahosted.org/freeipa/ticket/2760
This commit is contained in:
@@ -961,15 +961,28 @@ class Param(ReadOnly):
|
||||
pass
|
||||
return self.default
|
||||
|
||||
json_exclude_attrs = (
|
||||
'alwaysask', 'autofill', 'cli_name', 'cli_short_name', 'csv',
|
||||
'csv_separator', 'csv_skipspace', 'sortorder', 'falsehoods', 'truths',
|
||||
'version',
|
||||
)
|
||||
|
||||
def __json__(self):
|
||||
json_dict = {}
|
||||
for (a, k, d) in self.kwargs:
|
||||
if a in self.json_exclude_attrs:
|
||||
continue
|
||||
if k in (callable, DefaultFrom):
|
||||
continue
|
||||
elif isinstance(getattr(self, a), frozenset):
|
||||
json_dict[a] = [k for k in getattr(self, a, [])]
|
||||
else:
|
||||
json_dict[a] = getattr(self, a, '')
|
||||
val = getattr(self, a, '')
|
||||
if val is None or not val:
|
||||
# ignore false and not set because lack of their presence is
|
||||
# the information itself
|
||||
continue;
|
||||
json_dict[a] = val
|
||||
json_dict['class'] = self.__class__.__name__
|
||||
json_dict['name'] = self.name
|
||||
json_dict['type'] = self.type.__name__
|
||||
|
||||
Reference in New Issue
Block a user