#98 Convert stored Condition config options back to booleans
Merged 7 years ago by puiterwijk. Opened 7 years ago by merlinthp.
merlinthp/ipsilon master  into  master

file modified
+1 -1
@@ -169,7 +169,7 @@ 

      def get_tree(self, site):

          self.fpc = FasProxyClient(base_url=self.fas_url,

                                    useragent=self.user_agent,

-                                   insecure=(self.insecure == 'YES'))

+                                   insecure=self.insecure)

          self.page = FAS(site, self, 'login/fas')

          return self.page

  

file modified
+7 -3
@@ -431,8 +431,8 @@ 

  

      def __init__(self, name, description, default_value=False,

                   readonly=False):

-         # The db stores 1/0. Convert the passed-in value if

-         # necessary

+         # We're not too picky about what data we get, but we make sure it's a

+         # boolean by the time we're done with it

          if default_value in [u'1', 'True', True]:

              default_value = True

          else:
@@ -442,7 +442,11 @@ 

                                          readonly=readonly)

  

      def import_value(self, value):

-         self._assigned_value = value

+         # Convert the text string stored in the database back to a boolean

+         if value == 'True':

+             self._assigned_value = True

+         elif value == 'False':

+             self._assigned_value = False

  

  

  class ConfigHelper(Log):

All options types are stored as strings in the backend database. The
Condition config option type is a subclass of the Pick option that has
only the Python True and False values as valid values. When a specific
value for the option is stored into the database, this is rendered into the
text strings 'True' or 'False'. When the option is loaded back from the
database, it remains a string. This causes the issue that any "it option"
style checks will always evaluate to true. This manifests in the plugin
configuration pages, where the checkboxes for Condition options are always
checked, even if the value is set to false in the database.

This patch adds code to the Condition import_value function to coerce the
strings into Python bools.

The authfas plugin has a Condition option that it tries to use the value of
as a string, so convert that to a boolean operation.

Signed-off-by: Howard Johnson merlin@merlinthp.org

Reproducer:
* Log in
* Admin console
* Identity providers
* Configure SAML2
* Untick "allow self registration"
* Save

"Allow self registration" is ticked again. Check the backend database and see that it's set to false:

$ sqlite3 qrun/adminconfig.sqlite .dump | fgrep regist
INSERT INTO "provider_config" VALUES('saml2','allow self registration','False');

this should probably be an "elif value == 'False'", so that we still get the default behaviour if an option is unspecified.

rebased

7 years ago

Pull-Request has been merged by puiterwijk

7 years ago

Commit 0e29d12c fixes this pull-request