[PATCH] 152 Removal of illegal options in association dialog:

Association dialogs were using non-existent options for find commands. It causes error when #2509 is implemented.

Now when creating a find command a check for options existence is performed. Option is not used if not present in metadata. It fixes the issue.

To be able to do the this check properly patch 151 is required.

[PATCH] 151 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
--
Petr Vobornik
From f8fb3dd8f477895bcbe4f4f733aadeb199ee24d0 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Wed, 30 May 2012 12:55:08 +0200
Subject: [PATCH] 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
---
 ipalib/frontend.py         |   21 ++++++++++++++++++++-
 ipalib/parameters.py       |   15 ++++++++++++++-
 ipalib/plugins/baseldap.py |    9 ++++++---
 3 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 7c63b27ddb41e751692e47ebc334cb699606a74e..c28fa54ae933fe58833579b3e3aee0e1ad50f198 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -1012,13 +1012,32 @@ class Command(HasParam):
 
     # list of attributes we want exported to JSON
     json_friendly_attributes = (
-        'name', 'takes_args', 'takes_options',
+        'name', 'takes_args',
     )
 
+    # list of options we want only to mention their presence and not to write
+    # their attributes
+    json_only_presence_options = (
+        'all', 'raw', 'attrs', 'addattr', 'delattr', 'setattr', 'version',
+    )
+
+    def get_json_options(self):
+        """
+        Get only options we want exported to JSON
+        """
+        for option in self.get_options():
+            if option.name not in self.json_only_presence_options:
+                yield option
+            else:
+                yield { 'name': option.name }
+
     def __json__(self):
         json_dict = dict(
             (a, getattr(self, a)) for a in self.json_friendly_attributes
         )
+
+        json_dict['takes_options'] = list(self.get_json_options())
+
         return json_dict
 
 class LocalOrRemote(Command):
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 83a86544d5b66154944b9b279c042b638d3c57a5..47a4879aa44feac7357dd8cf4859b05d3884f521 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -958,15 +958,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__
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 2851f0f270d9e2bdba4780cc7bf308a76e180fd2..94e5e206adcfa1fc7d300a3dbf1ce26fe274e59d 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -1083,13 +1083,14 @@ class LDAPCreate(BaseLDAPCommand, crud.Create):
 
     # list of attributes we want exported to JSON
     json_friendly_attributes = (
-        'takes_args', 'takes_options',
+        'takes_args',
     )
 
     def __json__(self):
         json_dict = dict(
             (a, getattr(self, a)) for a in self.json_friendly_attributes
         )
+        json_dict['takes_options'] = list(self.get_json_options())
         return json_dict
 
 class LDAPQuery(BaseLDAPCommand, crud.PKQuery):
@@ -1107,13 +1108,14 @@ class LDAPQuery(BaseLDAPCommand, crud.PKQuery):
 
     # list of attributes we want exported to JSON
     json_friendly_attributes = (
-        'takes_args', 'takes_options',
+        'takes_args',
     )
 
     def __json__(self):
         json_dict = dict(
             (a, getattr(self, a)) for a in self.json_friendly_attributes
         )
+        json_dict['takes_options'] = list(self.get_json_options())
         return json_dict
 
 class LDAPMultiQuery(LDAPQuery):
@@ -1886,13 +1888,14 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
 
     # list of attributes we want exported to JSON
     json_friendly_attributes = (
-        'takes_options',
+        'takes_args',
     )
 
     def __json__(self):
         json_dict = dict(
             (a, getattr(self, a)) for a in self.json_friendly_attributes
         )
+        json_dict['takes_options'] = list(self.get_json_options())
         return json_dict
 
 class LDAPModReverseMember(LDAPQuery):
-- 
1.7.7.6

From 6df40166b37a0d2242c593a82c7b3b3e9abe9071 Mon Sep 17 00:00:00 2001
From: Petr Vobornik <pvobo...@redhat.com>
Date: Mon, 4 Jun 2012 12:29:27 +0200
Subject: [PATCH] Removal of illegal options in association dialog

Association dialogs were using non-existent options for find commands. It causes error when #2509 is implemented.

Now when creating a find command a check for options existence is performend. Option is not used if not present in metadata. It fixes the issue.

https://fedorahosted.org/freeipa/ticket/2760
---
 install/ui/association.js |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/install/ui/association.js b/install/ui/association.js
index ab43518f68ee3e313e801ca695ca047fca953624..6a19780615aacb3cdc2480fdb57e0e77566f8fbb 100644
--- a/install/ui/association.js
+++ b/install/ui/association.js
@@ -201,7 +201,11 @@ IPA.association_adder_dialog = function(spec) {
         var relationship = relationships[other_attribute_member];
         if (relationship) {
             var param_name = relationship[2] + that.entity.name;
-            options[param_name] = that.pkey;
+            var cmd_opt = IPA.get_command_option(that.other_entity.name + '_find',
+                                                 param_name);
+            if (cmd_opt) {
+                options[param_name] = that.pkey;
+            }
         }
 
         IPA.command({
-- 
1.7.7.6

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to