[extensions-web] extensions: Fix complex visibility



commit e9ccb943ec088f33b15ae6d517edbfbe6797d7b1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Mar 2 21:01:45 2012 -0500

    extensions: Fix complex visibility
    
    If we had an extension which had a visible version and a invisible
    version, it was possible that properties of the invisible version
    would be exposed on a query list. Use a subquery to solve this. Example:
    
     Extension Foo
       Visible Version 1
         Shell version 3.2
       Invisible Version 2
         Shell version 3.3.90
    
    Query for shell_version=3.3.90 would show Extension Foo, as it was
    a visible extension that matched.

 sweettooth/extensions/tests.py |   14 ++++++++++++++
 sweettooth/extensions/views.py |   10 +++++-----
 2 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/sweettooth/extensions/tests.py b/sweettooth/extensions/tests.py
index a2067e3..08c9757 100644
--- a/sweettooth/extensions/tests.py
+++ b/sweettooth/extensions/tests.py
@@ -399,3 +399,17 @@ class QueryExtensionsTest(BasicUserTestCase, TestCase):
         # Base version querying.
         uuids = self.gather_uuids(dict(shell_version="3.2.2"))
         self.assertEqual(uuids, [one.uuid])
+
+    def test_complex_visibility(self):
+        one = self.create_extension("one")
+
+        v = models.ExtensionVersion.objects.create(extension=one, status=models.STATUS_ACTIVE)
+        v.parse_metadata_json({"shell-version": ["3.2"]})
+
+        v = models.ExtensionVersion.objects.create(extension=one, status=models.STATUS_NEW)
+        v.parse_metadata_json({"shell-version": ["3.3.90"]})
+
+        # Make sure that we don't see one, here - the version that
+        # has this shell version is NEW.
+        uuids = self.gather_uuids(dict(shell_version="3.3.90"))
+        self.assertEqual(uuids, [])
diff --git a/sweettooth/extensions/views.py b/sweettooth/extensions/views.py
index 67b1817..a00f663 100644
--- a/sweettooth/extensions/views.py
+++ b/sweettooth/extensions/views.py
@@ -99,18 +99,18 @@ def get_versions_for_version_strings(version_strings):
             yield base_version
 
 def ajax_query_params_query(request):
-    query_params = {}
+    version_qs = models.ExtensionVersion.objects.visible()
 
     version_strings = request.GET.getlist('shell_version')
     if version_strings and version_strings != ['all']:
         versions = set(get_versions_for_version_strings(version_strings))
-        query_params['versions__shell_versions__in'] = versions
+        version_qs = version_qs.filter(shell_versions__in=versions)
+
+    queryset = models.Extension.objects.distinct().filter(versions__in=version_qs)
 
     uuids = request.GET.getlist('uuid')
     if uuids:
-        query_params['uuid__in'] = uuids
-
-    queryset = models.Extension.objects.visible().filter(**query_params)
+        queryset = queryset.filter(uuid__in=uuids)
 
     sort = request.GET.get('sort', 'popularity')
     sort = dict(recent='created').get(sort, sort)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]