From adac6e3b7ee6c47668c06ef8c56e09321a45f9f9 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Tue, 5 Dec 2017 13:36:16 -0200 Subject: [PATCH] =?UTF-8?q?remove=20acesso=20n=C3=A3o=20permitido=20via=20?= =?UTF-8?q?url=20ao=20crud=20tipoautor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/views.py | 18 +++++++++++++++++- sapl/test_urls.py | 7 ++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/sapl/base/views.py b/sapl/base/views.py index 4bb6cb580..6b666da0d 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -2,7 +2,7 @@ from django.conf import settings from django.contrib.auth import get_user_model from django.contrib.auth.models import Group from django.contrib.auth.tokens import default_token_generator -from django.core.exceptions import ObjectDoesNotExist +from django.core.exceptions import ObjectDoesNotExist, PermissionDenied from django.core.mail import send_mail from django.core.urlresolvers import reverse from django.db.models import Count @@ -80,6 +80,22 @@ class TipoAutorCrud(CrudAux): return context + class TipoAutorMixin: + def dispatch(self, request, *args, **kwargs): + object = self.get_object() + if object.content_type: + raise PermissionDenied() + return super().get(request, *args, **kwargs) + + class UpdateView(TipoAutorMixin, CrudAux.UpdateView): + pass + + class DetailView(TipoAutorMixin, CrudAux.DetailView): + pass + + class DeleteView(TipoAutorMixin, CrudAux.DeleteView): + pass + class AutorCrud(CrudAux): model = Autor diff --git a/sapl/test_urls.py b/sapl/test_urls.py index 590bbc689..bffb59c18 100644 --- a/sapl/test_urls.py +++ b/sapl/test_urls.py @@ -1,12 +1,12 @@ -import pytest from django.apps import apps from django.contrib.auth import get_user_model from django.contrib.auth.management import _get_all_permissions from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.db import transaction -from django.utils.translation import ugettext_lazy as _ from django.utils.translation import string_concat +from django.utils.translation import ugettext_lazy as _ +import pytest from sapl.crud.base import PermissionRequiredForAppCrudMixin from sapl.rules.apps import AppConfig, update_groups @@ -14,6 +14,7 @@ from scripts.lista_urls import lista_urls from .settings import SAPL_APPS + pytestmark = pytest.mark.django_db sapl_appconfs = [apps.get_app_config(n[5:]) for n in SAPL_APPS] @@ -72,6 +73,7 @@ def create_perms_post_migrate(sapl_app_config): ] Permission.objects.bulk_create(perms) + btn_login = ('') @@ -259,7 +261,6 @@ apps_url_patterns_prefixs_and_users = { } -@pytest.mark.skip(reason="TODO: Lento demais. Precisa ser refatorado") @pytest.mark.parametrize('url_item', _lista_urls) def test_urlpatterns(url_item, admin_client):