Commit 869c7984 authored by BAIRE Anthony's avatar BAIRE Anthony
Browse files

Fix the main webapp index to include only apps that have a ready version

parent 0312cd9e
Pipeline #135834 failed with stages
in 1 second
import base64
import hashlib
import itertools
import logging
import os
import re
......@@ -7,10 +8,16 @@ import re
import redis
import IPy
from django.conf import settings
import django.db
from django.db.models import Q
import config
from .models import Job, Webapp, AllgoUser
from .models import (
log = logging.getLogger('allgo')
......@@ -218,18 +225,14 @@ def query_webapps_for_user(user):
if user.is_superuser:
return Webapp.objects.all()
# a webapp is visible in the public index if it is not private (obviously) and if it has at
# least one version published and ready.
with django.db.connection.cursor() as cur:
cur.execute("""SELECT webapp_id FROM dj_webapp_versions WHERE webapp_id IN (
SELECT id FROM dj_webapps WHERE private != 1
) AND published=1 AND state=%s GROUP BY webapp_id""", (WebappVersion.READY,))
public_ids = list(itertools.chain(*cur.fetchall()))
# select webapps that are either public (and have at least one published version) or owned by
# the current user
# if only_published_version is True, then only published version of non user app
# are returned.
# version__ refers to WebappVersion_set, with 'related_name'
# cf
q_filter = Q(private=False) & Q(version__published=True)
return Webapp.objects.filter(Q( | Q(id__in=public_ids))
qs = Webapp.objects \
.filter(Q( | q_filter) \
return qs
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment