From 79c214d47ccc871f4c02006b8ee9a191533334b5 Mon Sep 17 00:00:00 2001
From: Kálmán Viktor <kviktor@cloud.bme.hu>
Date: Wed, 27 Aug 2014 18:42:03 +0200
Subject: [PATCH] dashboard: no migrate button for regular users

---
 circle/dashboard/views.py | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/circle/dashboard/views.py b/circle/dashboard/views.py
index f06bd16..e251cec 100644
--- a/circle/dashboard/views.py
+++ b/circle/dashboard/views.py
@@ -1041,7 +1041,8 @@ class MassOperationView(OperationView):
 
         return ctx
 
-    def check_auth(self):
+    @classmethod
+    def check_auth(self, user=None):
         pass
 
     def get_object(self):
@@ -1112,6 +1113,11 @@ class MassMigrationView(MassOperationView):
     icon = "truck"
     effect = "info"
 
+    @classmethod
+    def check_auth(self, user=None):
+        if user and not user.is_superuser:
+            raise PermissionDenied
+
     def get_context_data(self, **kwargs):
         ctx = super(MassMigrationView, self).get_context_data(**kwargs)
         ctx['nodes'] = [n for n in Node.objects.filter(enabled=True)
@@ -1715,7 +1721,14 @@ class VmList(LoginRequiredMixin, FilterMixin, ListView):
 
     def get_context_data(self, *args, **kwargs):
         context = super(VmList, self).get_context_data(*args, **kwargs)
-        context['ops'] = [v for k, v in vm_mass_ops.iteritems()]
+        context['ops'] = []
+        for k, v in vm_mass_ops.iteritems():
+            try:
+                v.check_auth(user=self.request.user)
+            except PermissionDenied:
+                pass
+            else:
+                context['ops'].append(v)
         context['search_form'] = self.search_form
         return context
 
--
libgit2 0.26.0