Commit c177b3e8 by Kálmán Viktor

Merge branch 'issue_458' into 'master'

Rework VM list filter

More info: #458

See merge request !387
parents 11e13c2e ca15148f
Pipeline #241 passed with stage
in 0 seconds
...@@ -1541,6 +1541,7 @@ class VmResourcesForm(forms.ModelForm): ...@@ -1541,6 +1541,7 @@ class VmResourcesForm(forms.ModelForm):
vm_search_choices = ( vm_search_choices = (
("owned", _("owned")), ("owned", _("owned")),
("shared", _("shared")), ("shared", _("shared")),
("shared_with_me", _("shared with me")),
("all", _("all")), ("all", _("all")),
) )
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
{% trans "Sorting ... " %} {% trans "Sorting ... " %}
<!--<i class="fa fa-refresh fa-spin fa-2x"></i>--> <!--<i class="fa fa-refresh fa-spin fa-2x"></i>-->
</div> </div>
<a class="pull-right btn btn-success btn-xs vm-create" href="{% url "dashboard.views.vm-create" %}"><i class="fa fa-plus-circle"></i> {% trans "new virtual machine" %}</a>
<h3 class="no-margin"><i class="fa fa-desktop"></i> {% trans "Virtual machines" %}</h3> <h3 class="no-margin"><i class="fa fa-desktop"></i> {% trans "Virtual machines" %}</h3>
</div> </div>
<div class="panel-body"> <div class="panel-body">
......
...@@ -32,7 +32,7 @@ from django.contrib.sites.shortcuts import get_current_site ...@@ -32,7 +32,7 @@ from django.contrib.sites.shortcuts import get_current_site
from django.core import signing from django.core import signing
from django.core.exceptions import PermissionDenied, SuspiciousOperation from django.core.exceptions import PermissionDenied, SuspiciousOperation
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db.models import Q from django.db.models import Q, Count, Sum
from django.http import ( from django.http import (
HttpResponse, Http404, HttpResponseRedirect, JsonResponse HttpResponse, Http404, HttpResponseRedirect, JsonResponse
) )
...@@ -55,6 +55,7 @@ from common.models import HumanReadableException, HumanReadableObject ...@@ -55,6 +55,7 @@ from common.models import HumanReadableException, HumanReadableObject
from ..models import GroupProfile, Profile from ..models import GroupProfile, Profile
from ..forms import TransferOwnershipForm from ..forms import TransferOwnershipForm
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
saml_available = hasattr(settings, "SAML_CONFIG") saml_available = hasattr(settings, "SAML_CONFIG")
...@@ -167,14 +168,31 @@ class FilterMixin(object): ...@@ -167,14 +168,31 @@ class FilterMixin(object):
def create_acl_queryset(self, model): def create_acl_queryset(self, model):
cleaned_data = self.search_form.cleaned_data cleaned_data = self.search_form.cleaned_data
stype = cleaned_data.get('stype', "all") stype = cleaned_data.get('stype', 'all')
superuser = stype == "all" superuser = stype == 'all'
shared = stype == "shared" or stype == "all" shared = stype == 'shared' or stype == 'all'
level = "owner" if stype == "owned" else "user" level = 'owner' if stype == 'owned' else 'user'
user = self.request.user
queryset = model.get_objects_with_level( queryset = model.get_objects_with_level(
level, self.request.user, level, user, group_also=shared, disregard_superuser=not superuser)
group_also=shared, disregard_superuser=not superuser, if stype == 'owned':
) queryset = queryset.filter(owner=user)
elif stype == 'shared':
queryset = queryset.filter(owner=user)
pk_list = []
for record in queryset:
count = record.object_level_set.annotate(
Count('users'), Count('groups')).aggregate(
Sum('users__count'), Sum('groups__count'))
if (count['users__count__sum'] > 1 or
count['groups__count__sum'] > 0):
pk_list.append(record.pk)
queryset = queryset.filter(pk__in=pk_list)
elif stype == 'shared_with_me':
queryset = queryset.exclude(owner=user)
return queryset return queryset
......
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 sign in to comment