From a9723102b95089d905df72330193a1c96b222db8 Mon Sep 17 00:00:00 2001 From: LeandroJatai Date: Wed, 14 Sep 2022 15:45:09 -0300 Subject: [PATCH] refactor: inclui ContentType na API, apenas list e detail --- sapl/api/core/__init__.py | 7 +++++-- sapl/api/viewset.py | 5 +++++ sapl/rules/group_geral.py | 6 ++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/sapl/api/core/__init__.py b/sapl/api/core/__init__.py index 2ecab98fd..656ccebf4 100644 --- a/sapl/api/core/__init__.py +++ b/sapl/api/core/__init__.py @@ -167,8 +167,11 @@ class SaplApiViewSetConstrutor(): viewset.__name__ = '%sModelSaplViewSet' % _model.__name__ return viewset - apps_sapl = [apps.apps.get_app_config( - n[5:]) for n in settings.SAPL_APPS] + apps_sapl = [ + apps.apps.get_app_config('contenttypes') + ] + [ + apps.apps.get_app_config(n[5:]) for n in settings.SAPL_APPS + ] for app in apps_sapl: cls._built_sets[app] = {} for model in app.get_models(): diff --git a/sapl/api/viewset.py b/sapl/api/viewset.py index fe3a9fb0f..2b9a8632e 100644 --- a/sapl/api/viewset.py +++ b/sapl/api/viewset.py @@ -29,6 +29,11 @@ from sapl.utils import models_with_gr_for_model, choice_anos_com_sessaoplenaria SaplApiViewSetConstrutor = SaplApiViewSetConstrutor.build_class() +@customize(ContentType) +class _ContentTypeSet: + http_method_names = ['get', 'head', 'options', 'trace'] + + @customize(Autor) class _AutorViewSet: # Customização para AutorViewSet com implementação de actions específicas diff --git a/sapl/rules/group_geral.py b/sapl/rules/group_geral.py index f37c60314..5e9545d7b 100644 --- a/sapl/rules/group_geral.py +++ b/sapl/rules/group_geral.py @@ -1,3 +1,5 @@ +from django.contrib.contenttypes import models as contenttypes + from sapl.audiencia import models as audiencia from sapl.base import models as base from sapl.comissoes import models as comissoes @@ -11,6 +13,7 @@ from sapl.rules import SAPL_GROUP_GERAL, RP_ADD, __base__, __perms_publicas__, \ __listdetailchange__ from sapl.sessao import models as sessao + rules_group_geral = { 'group': SAPL_GROUP_GERAL, 'rules': [ @@ -114,5 +117,8 @@ rules_group_geral = { (audiencia.AudienciaPublica, __base__, __perms_publicas__), (audiencia.TipoAudienciaPublica, __base__, __perms_publicas__), + # permite consulta anônima pela api a lista de contenttypes + (contenttypes.ContentType, [], __perms_publicas__), + ] }