Ejemplo n.º 1
0
 def images_for_user(cls, user=None):
     from core.models.user import AtmosphereUser
     is_public = Q(private=False)
     if not user or isinstance(user, AnonymousUser):
         # Images that are not endated and are public
         return Application.objects.filter(
             query.only_current_apps() & is_public,
             versions__machines__instance_source__provider__public=True
         ).distinct()
     if not isinstance(user, AtmosphereUser):
         raise Exception("Expected user to be of type AtmosphereUser"
                         " - Received %s" % type(user))
     queryset = None
     if user.is_staff:
         # Any image on a provider in the staff's provider list
         queryset = Application.objects.filter(
             query.in_users_providers(user))
     else:
         # This query is not the most clear. Here's an explanation:
         # Include all images created by the user or active images in the
         # users providers that are either shared with the user or public
         queryset = Application.objects.filter(
             query.created_by_user(user)
             | (query.only_current_apps() & query.in_users_providers(user)
                & (query.images_shared_with_user(user) | is_public)))
     return queryset.distinct()
 def images_for_user(cls, user=None):
     from core.models.user import AtmosphereUser
     is_public = Q(private=False)
     if not user or isinstance(user, AnonymousUser):
         # Images that are not endated and are public
         return Application.objects.filter(
             query.only_current_apps() & is_public,
             versions__machines__instance_source__provider__public=True
         ).distinct()
     if not isinstance(user, AtmosphereUser):
         raise Exception(
             "Expected user to be of type AtmosphereUser"
             " - Received %s" % type(user)
         )
     queryset = None
     if user.is_staff:
         # Any image on a provider in the staff's provider list
         queryset = Application.objects.filter(
             query.in_users_providers(user)
         )
     else:
         # This query is not the most clear. Here's an explanation:
         # Include all images created by the user or active images in the
         # users providers that are either shared with the user or public
         queryset = Application.objects.select_related(
             'created_by'
         ).prefetch_related(
             'versions__machines__instance_source__provider',
             'versions__machines__members', 'versions__membership'
         ).filter(
             query.created_by_user(user) | (
                 query.only_current_apps() & query.in_users_providers(user) &
                 (query.images_shared_with_user_by_ids(user) | is_public)
             )
         )
     return queryset.distinct()