← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:bugfix-private-snap-filter into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:bugfix-private-snap-filter into launchpad:master.

Commit message:
Fixing regression: use COALESCE instead of CASE to check snap's private/information_type column

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/399366
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:bugfix-private-snap-filter into launchpad:master.
diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
index 6b9af0a..a96eace 100644
--- a/lib/lp/snappy/model/snap.py
+++ b/lib/lp/snappy/model/snap.py
@@ -1647,10 +1647,8 @@ def get_snap_privacy_filter(user):
     # XXX pappacena 2021-02-12: Once we do the migration to back fill
     # information_type, we should be able to change this.
     private_snap = SQL(
-        "CASE information_type"
-        "    WHEN NULL THEN private"
-        "    ELSE information_type NOT IN ?"
-        "END", params=[tuple(i.value for i in PUBLIC_INFORMATION_TYPES)])
+        "COALESCE(information_type NOT IN ?, private)",
+        params=[tuple(i.value for i in PUBLIC_INFORMATION_TYPES)])
     if user is None:
         return private_snap == False
 
diff --git a/lib/lp/snappy/tests/test_snap.py b/lib/lp/snappy/tests/test_snap.py
index e8ea61e..88f2040 100644
--- a/lib/lp/snappy/tests/test_snap.py
+++ b/lib/lp/snappy/tests/test_snap.py
@@ -1655,6 +1655,12 @@ class TestSnapSet(TestCaseWithFactory):
         shared_snaps = [self.factory.makeSnap(**snap_data) for _ in range(2)]
         snap_data["private"] = False
         public_snaps = [self.factory.makeSnap(**snap_data) for _ in range(3)]
+        # Backwards compatibility check: NULL on information_type db column
+        # should make us consider the "private" db column.
+        snap = removeSecurityProxy(public_snaps[-1])
+        snap._private = False
+        snap.information_type = None
+        Store.of(snap).flush()
 
         with admin_logged_in():
             for snap in shared_snaps:

Follow ups