diff --git a/djangoldp/permissions.py b/djangoldp/permissions.py index 4e1112068df585a163e992293407ed28bab88e76..34f1fa0614b2eb80742239c2b52eb6db37dd69e1 100644 --- a/djangoldp/permissions.py +++ b/djangoldp/permissions.py @@ -2,6 +2,7 @@ from django.core.exceptions import PermissionDenied from django.db.models.base import ModelBase from rest_framework.permissions import DjangoObjectPermissions from django.contrib.auth.models import _user_get_all_permissions +from guardian.shortcuts import get_user_perms class LDPPermissions(DjangoObjectPermissions): @@ -47,10 +48,16 @@ class LDPPermissions(DjangoObjectPermissions): perms = set() if obj is not None and not user.is_anonymous: - # get permissions from all backends and then remove model name from the permissions + + '''guardian_perms = get_user_perms(user, obj) +>>>>>>> update: new tests for permissions model_name = model._meta.model_name forbidden_string = "_" + model_name +<<<<<<< HEAD perms = set([p.replace(forbidden_string, '') for p in _user_get_all_permissions(user, obj)]) +======= + perms = set([p.replace(forbidden_string, '') for p in guardian_perms])''' + perms = _user_get_all_permissions(user, obj) # apply anon, owner and auth permissions if user.is_anonymous: diff --git a/djangoldp/tests/models.py b/djangoldp/tests/models.py index 288a0b35643e5a50592b40c0626334057de6b5ed..1f2526d279295c60d7f68ac13d9ad5e0a8376458 100644 --- a/djangoldp/tests/models.py +++ b/djangoldp/tests/models.py @@ -172,7 +172,6 @@ class Circle(Model): anonymous_perms = ['view', 'add', 'delete', 'add', 'change', 'control'] authenticated_perms = ["inherit"] rdf_type = 'hd:circle' - depth = 1 class Batch(Model): @@ -219,7 +218,6 @@ class Project(Model): anonymous_perms = ['view', 'add', 'delete', 'add', 'change', 'control'] authenticated_perms = ["inherit"] rdf_type = 'hd:project' - depth = 1 class DateModel(Model): diff --git a/djangoldp/tests/settings_default.py b/djangoldp/tests/settings_default.py index 6ecb12a9129cab2b3adf3b5e017daa9fc5b2c5f2..acfc847f4d8a4cbc0a16f06bd9020600d1945be0 100644 --- a/djangoldp/tests/settings_default.py +++ b/djangoldp/tests/settings_default.py @@ -45,7 +45,7 @@ MIDDLEWARE = [ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] AUTHENTICATION_BACKENDS=( - 'django.contrib.auth.backends.ModelBackend', 'guardian.backends.ObjectPermissionBackend') + 'django.contrib.auth.backends.ModelBackend') ROOT_URLCONF='djangoldp.urls' diff --git a/djangoldp/tests/tests_performance.py b/djangoldp/tests/tests_performance.py index f34aec235ce32f8018337079b4bc0c26c73931bb..4d817a40bd61c8e29ad4c5de8aef7a9d62f156fb 100644 --- a/djangoldp/tests/tests_performance.py +++ b/djangoldp/tests/tests_performance.py @@ -1,3 +1,4 @@ +from django.contrib.auth import get_user_model from rest_framework.test import APIClient, APITestCase from djangoldp.tests.models import User, Project import cProfile, pstats, io @@ -8,6 +9,9 @@ class TestPerformance(APITestCase): def setUp(self): self.client = APIClient() + self.user = get_user_model().objects.create_user(username='john', email='jlennon@beatles.com', + password='glass onion') + self.client.force_authenticate(user=self.user) print('there are ' + str(Project.objects.count()) + ' projects in the database') print('there are ' + str(User.objects.count()) + ' users in the database') @@ -28,11 +32,11 @@ class TestPerformance(APITestCase): self.assertEqual(response.status_code, 200) print('counted ' + str(len(response.data['ldp:contains'])) + ' projects') pr.disable() - self._print_stats(pr) + #self._print_stats(pr) pr = self._enable_new_profiler() response = self.client.get('/users/', content_type='application/ld+json') self.assertEqual(response.status_code, 200) print('counted ' + str(len(response.data['ldp:contains'])) + ' users') pr.disable() - self._print_stats(pr) + #self._print_stats(pr)