diff --git a/registry/quilt_server/views.py b/registry/quilt_server/views.py index c72b5de2d31..1c7fe7f19fd 100644 --- a/registry/quilt_server/views.py +++ b/registry/quilt_server/views.py @@ -1423,8 +1423,6 @@ def profile(): plan = None have_cc = None - public_access = sa.orm.aliased(Access) - # Check for outstanding package sharing invitations invitations = ( db.session.query(Invitation, Package) @@ -1439,13 +1437,19 @@ def profile(): if invitations: db.session.commit() + # We want to show only the packages owned by or explicitly shared with the user - + # but also show whether they're public, in case a package is both public and shared with the user. + # So do a "GROUP BY" to get the public info, then "HAVING" to filter out packages that aren't shared. packages = ( - db.session.query(Package, public_access.user.isnot(None)) + db.session.query(Package, sa.func.bool_or(Access.user == PUBLIC)) .join(Package.access) - .filter(Access.user == g.auth.user) - .outerjoin(public_access, sa.and_( - Package.id == public_access.package_id, public_access.user == PUBLIC)) - .order_by(Package.owner, Package.name) + .filter(Access.user.in_([g.auth.user, PUBLIC])) + .group_by(Package.id) + .order_by( + sa.func.lower(Package.owner), + sa.func.lower(Package.name) + ) + .having(sa.func.bool_or(Access.user == g.auth.user)) .all() ) @@ -1455,7 +1459,7 @@ def profile(): dict( owner=package.owner, name=package.name, - is_public=bool(is_public) + is_public=is_public, ) for package, is_public in packages if package.owner == g.auth.user ], @@ -1463,7 +1467,7 @@ def profile(): dict( owner=package.owner, name=package.name, - is_public=bool(is_public) + is_public=is_public, ) for package, is_public in packages if package.owner != g.auth.user ],