Commit e32ec378 authored by LETORT Sebastien's avatar LETORT Sebastien
Browse files

update of query_webapps_for_user, specially when used by views.WebappList.

Now the user cannot view public app if no version is published.
parent 55061286
Pipeline #87909 passed with stages
in 4 minutes and 41 seconds
......@@ -213,14 +213,23 @@ def get_request_user(request):
return request.user
def query_webapps_for_user(user):
def query_webapps_for_user(user, only_published_version=False):
"""Return a queryset of all webapps visible by a given user"""
if user.is_superuser:
return Webapp.objects.all()
else:
# select webapps that are either public or owned by the user
return Webapp.objects.filter(Q(private=False) | Q(user_id=user.id))
# if only_published_version is True, then only published version of non user app
# are returned.
q_filter = Q(private=False)
if only_published_version:
q_filter = q_filter & Q(webapp__published=True)
qs = Webapp.objects \
.filter(Q(user_id=user.id) | q_filter ) \
.distinct()
#log.debug( "query = {}".format(qs.query) )
return qs
......@@ -180,7 +180,11 @@ class WebappList(AllAccessMixin, ListView):
template_name = 'webapp_list.html'
def get_queryset(self):
return query_webapps_for_user(self.request.user).order_by('-created_at')
webapps = query_webapps_for_user(self.request.user, only_published_version=True) \
.order_by('-created_at').values()
# ~ for x in webapps:
# ~ log.debug( "app : {}".format(x) )
return webapps
class UserWebappList(AllAccessMixin, ListView):
"""List of user's webapp
......
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