Commit 53aaa57a by Őry Máté

dashboard: add acl data to detail view's context

parent 2532c57a
from django.core import signing from django.core import signing
from django.http import HttpResponse
from django.utils.translation import ugettext_lazy as _
from django.views.generic import TemplateView, DetailView from django.views.generic import TemplateView, DetailView
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from guardian.shortcuts import (get_users_with_perms, get_groups_with_perms,
get_perms)
from tables import VmListTable
from vm.models import Instance from vm.models import Instance
...@@ -24,6 +29,28 @@ class IndexView(TemplateView): ...@@ -24,6 +29,28 @@ class IndexView(TemplateView):
return context return context
def first_common_element(a, b):
for i in a:
if i in b:
return i
return None
def get_acl_data(obj):
levels = obj._meta.permissions
levelids = [id for (id, name) in levels]
users = get_users_with_perms(obj, with_group_users=False)
users = [{'user': u,
'perm': first_common_element(levelids, get_perms(u, obj))}
for u in users]
groups = get_groups_with_perms(obj)
groups = [{'group': g,
'perm': first_common_element(levelids, get_perms(g, obj))}
for g in groups]
return {'users': users, 'groups': groups, 'levels': levels,
'url': obj.get_absolute_url()}
class VmDetailView(DetailView): class VmDetailView(DetailView):
template_name = "dashboard/vm-detail.html" template_name = "dashboard/vm-detail.html"
queryset = Instance.objects.all() queryset = Instance.objects.all()
...@@ -39,6 +66,7 @@ class VmDetailView(DetailView): ...@@ -39,6 +66,7 @@ class VmDetailView(DetailView):
context.update({ context.update({
'vnc_url': '%s' % value 'vnc_url': '%s' % value
}) })
context['acl'] = get_acl_data(instance)
return context return context
......
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