changeset 5675:c25191aadf92

db: fix Ui.get_by_key to also filter on section Key alone is not enough to identify a Ui row.
author Søren Løvborg <sorenl@unity3d.com>
date Tue, 05 Jan 2016 14:48:03 +0100
parents f88ca6d06e6c
children 21f07c4b510f
files kallithea/controllers/admin/settings.py kallithea/controllers/forks.py kallithea/lib/base.py kallithea/model/db.py kallithea/model/repo_group.py kallithea/tests/functional/test_admin_settings.py
diffstat 6 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/controllers/admin/settings.py	Tue Jan 05 18:53:09 2016 +0100
+++ b/kallithea/controllers/admin/settings.py	Tue Jan 05 14:48:03 2016 +0100
@@ -104,24 +104,24 @@
                      force_defaults=False)
 
             try:
-                sett = Ui.get_by_key('push_ssl')
+                sett = Ui.get_by_key('web', 'push_ssl')
                 sett.ui_value = form_result['web_push_ssl']
 
                 if c.visual.allow_repo_location_change:
-                    sett = Ui.get_by_key('/')
+                    sett = Ui.get_by_key('paths', '/')
                     sett.ui_value = form_result['paths_root_path']
 
                 #HOOKS
-                sett = Ui.get_by_key(Ui.HOOK_UPDATE)
+                sett = Ui.get_by_key('hooks', Ui.HOOK_UPDATE)
                 sett.ui_active = form_result['hooks_changegroup_update']
 
-                sett = Ui.get_by_key(Ui.HOOK_REPO_SIZE)
+                sett = Ui.get_by_key('hooks', Ui.HOOK_REPO_SIZE)
                 sett.ui_active = form_result['hooks_changegroup_repo_size']
 
-                sett = Ui.get_by_key(Ui.HOOK_PUSH)
+                sett = Ui.get_by_key('hooks', Ui.HOOK_PUSH)
                 sett.ui_active = form_result['hooks_changegroup_push_logger']
 
-                sett = Ui.get_by_key(Ui.HOOK_PULL)
+                sett = Ui.get_by_key('hooks', Ui.HOOK_PULL)
                 sett.ui_active = form_result['hooks_outgoing_pull_logger']
 
                 ## EXTENSIONS
--- a/kallithea/controllers/forks.py	Tue Jan 05 18:53:09 2016 +0100
+++ b/kallithea/controllers/forks.py	Tue Jan 05 14:48:03 2016 +0100
@@ -62,7 +62,7 @@
 
         c.landing_revs_choices, c.landing_revs = ScmModel().get_repo_landing_revs()
 
-        c.can_update = Ui.get_by_key(Ui.HOOK_UPDATE).ui_active
+        c.can_update = Ui.get_by_key('hooks', Ui.HOOK_UPDATE).ui_active
 
     def __load_data(self, repo_name=None):
         """
@@ -164,7 +164,7 @@
             form_result = _form.to_python(dict(request.POST))
 
             # an approximation that is better than nothing
-            if not Ui.get_by_key(Ui.HOOK_UPDATE).ui_active:
+            if not Ui.get_by_key('hooks', Ui.HOOK_UPDATE).ui_active:
                 form_result['update_after_clone'] = False
 
             # create fork is done sometimes async on celery, db transaction
--- a/kallithea/lib/base.py	Tue Jan 05 18:53:09 2016 +0100
+++ b/kallithea/lib/base.py	Tue Jan 05 14:48:03 2016 +0100
@@ -255,7 +255,7 @@
         and required True otherwise
         """
         #check if we have SSL required  ! if not it's a bad request !
-        if str2bool(Ui.get_by_key('push_ssl').ui_value):
+        if str2bool(Ui.get_by_key('web', 'push_ssl').ui_value):
             org_proto = environ.get('wsgi._org_proto', environ['wsgi.url_scheme'])
             if org_proto != 'https':
                 log.debug('proto is %s and SSL is required BAD REQUEST !',
--- a/kallithea/model/db.py	Tue Jan 05 18:53:09 2016 +0100
+++ b/kallithea/model/db.py	Tue Jan 05 14:48:03 2016 +0100
@@ -351,14 +351,14 @@
     ui_active = Column(Boolean(), nullable=False, default=True)
 
     @classmethod
-    def get_by_key(cls, key):
+    def get_by_key(cls, section, key):
         """ Return specified Ui object, or None if not found. """
-        return cls.query().filter(cls.ui_key == key).scalar()
+        return cls.query().filter_by(ui_section=section, ui_key=key).scalar()
 
     @classmethod
     def get_or_create(cls, section, key):
         """ Return specified Ui object, creating it if necessary. """
-        setting = cls.get_by_key(key)
+        setting = cls.get_by_key(section, key)
         if setting is None:
             setting = cls(ui_section=section, ui_key=key)
             Session().add(setting)
@@ -370,6 +370,7 @@
         q = q.filter(cls.ui_key.in_([cls.HOOK_UPDATE, cls.HOOK_REPO_SIZE,
                                      cls.HOOK_PUSH, cls.HOOK_PRE_PUSH,
                                      cls.HOOK_PULL, cls.HOOK_PRE_PULL]))
+        q = q.filter(cls.ui_section == 'hooks')
         return q.all()
 
     @classmethod
@@ -383,7 +384,7 @@
 
     @classmethod
     def get_repos_location(cls):
-        return cls.get_by_key('/').ui_value
+        return cls.get_by_key('paths', '/').ui_value
 
     @classmethod
     def create_or_update_hook(cls, key, val):
--- a/kallithea/model/repo_group.py	Tue Jan 05 18:53:09 2016 +0100
+++ b/kallithea/model/repo_group.py	Tue Jan 05 14:48:03 2016 +0100
@@ -59,7 +59,7 @@
         Gets the repositories root path from database
         """
 
-        q = Ui.get_by_key('/')
+        q = Ui.get_by_key('paths', '/')
         return q.ui_value
 
     def _create_default_perms(self, new_group):
--- a/kallithea/tests/functional/test_admin_settings.py	Tue Jan 05 18:53:09 2016 +0100
+++ b/kallithea/tests/functional/test_admin_settings.py	Tue Jan 05 14:48:03 2016 +0100
@@ -55,7 +55,7 @@
         response.mustcontain('test_hooks_2')
         response.mustcontain('cd /tmp2')
 
-        hook_id = Ui.get_by_key('test_hooks_2').ui_id
+        hook_id = Ui.get_by_key('hooks', 'test_hooks_2').ui_id
         ## delete
         self.app.post(url('admin_settings_hooks'),
                         params=dict(hook_id=hook_id, _authentication_token=self.authentication_token()))