From 0885a94612ef57eda7f731490f32a01ffcb7bfb2 Mon Sep 17 00:00:00 2001
From: Carlos Vega <carlos.vega@uni.lu>
Date: Thu, 22 Nov 2018 13:23:59 +0100
Subject: [PATCH] removed unnecessary code

---
 smash/web/decorators.py | 17 +----------------
 1 file changed, 1 insertion(+), 16 deletions(-)

diff --git a/smash/web/decorators.py b/smash/web/decorators.py
index 9d15f7d8..2aafa532 100644
--- a/smash/web/decorators.py
+++ b/smash/web/decorators.py
@@ -62,7 +62,7 @@ class PermissionDecorator:
 
     @staticmethod
     def get_permissions():
-        if PermissionDecorator.permissions_queryset is None and len(PermissionDecorator.codenames) > 0:
+        if PermissionDecorator.permissions_queryset is None or len(PermissionDecorator.codenames) > len(PermissionDecorator.permissions_queryset):
             PermissionDecorator.permissions_queryset = Permission.objects.filter(codename__in=PermissionDecorator.codenames)
 
         return PermissionDecorator.permissions_queryset
@@ -81,21 +81,6 @@ class PermissionDecorator:
         #variables to be used on decorator call
         self.perm_codename = perm_codename
 
-        # since the decorators are executed during code interpretation, we need to avoid executing
-        # the rest of the code if we are in the process of ./manage migrate or makemigrations
-        # since Permission won't be already migrated
-        if is_django_migrating():
-            return
-
-        query_result = Permission.objects.filter(codename=perm_codename)
-        if len(query_result) < 0:
-            logger.warn('Codename {} used in PermissionDecorator does not exist.'.format(perm_codename))
-            raise ValueError
-
-        if query_result[0].id not in PermissionDecorator.permission_ids: #avoid re-query if the permissions remain the same
-            PermissionDecorator.permission_ids.add(query_result[0].id)
-            PermissionDecorator.permissions_queryset = Permission.objects.filter(id__in=PermissionDecorator.permission_ids).all()
-
     def __call__(self, func):
         '''
         This method is also called when the function is decorated
-- 
GitLab