From c0a53d5ee49f94d253303e3e3314b1fe37866e43 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Thu, 13 Oct 2016 16:15:56 -0300 Subject: [PATCH] Fix #733 --- sapl/comissoes/views.py | 1 + sapl/crud/base.py | 18 ++++++++++++------ sapl/materia/views.py | 26 +++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 8d3d80e88..fc679d611 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -30,6 +30,7 @@ class ParticipacaoCrud(MasterDetailCrud): public = [RP_DETAIL, ] ListView = None is_m2m = True + link_return_to_parent_field = True class BaseMixin(MasterDetailCrud.BaseMixin): list_field_names = ['composicao', 'parlamentar', 'cargo'] diff --git a/sapl/crud/base.py b/sapl/crud/base.py index a870e697f..19781c0c6 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -919,6 +919,7 @@ class CrudAux(Crud): class MasterDetailCrud(Crud): is_m2m = False + link_return_to_parent_field = False class BaseMixin(Crud.BaseMixin): @@ -1145,11 +1146,14 @@ class MasterDetailCrud(Crud): pk = root_pk - namespace = parent_object._meta.app_config.name - return reverse('%s:%s' % ( - namespace, - '%s_%s' % (parent_object._meta.model_name, ACTION_DETAIL)), - args=(pk,)) + if obj.is_m2m: + namespace = parent_object._meta.app_config.name + return reverse('%s:%s' % ( + namespace, + '%s_%s' % (parent_object._meta.model_name, ACTION_DETAIL)), + args=(pk,)) + else: + return self.resolve_url(ACTION_LIST, args=(pk,)) class DetailView(Crud.DetailView): permission_required = RP_DETAIL, @@ -1166,7 +1170,7 @@ class MasterDetailCrud(Crud): if not obj.ListView: return '' - if not obj.ListView.permission_required or\ + if obj.ListView.permission_required not in obj.public or\ self.request.user.has_perm(self.permission(RP_LIST)): if '__' in obj.parent_field: fields = obj.parent_field.split('__') @@ -1262,6 +1266,8 @@ class MasterDetailCrud(Crud): @property def detail_root_detail_url(self): obj = self.crud if hasattr(self, 'crud') else self + if not obj.link_return_to_parent_field: + return '' if hasattr(obj, 'parent_field'): parent_field = obj.parent_field.split('__') if not obj.is_m2m or len(parent_field) > 1: diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 782f74201..432801f48 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -757,7 +757,28 @@ class LegislacaoCitadaCrud(MasterDetailCrud): args=args) def has_permission(self): - return self.request.user.has_module_perms('materia') + perms = self.get_permission_required() + # Torna a view pública se não possuir conteudo + # no atributo permission_required + return self.request.user.has_module_perms('materia')\ + if len(perms) else True + + def permission(self, rad): + return '%s%s%s' % ('norma' if rad.endswith('_') else '', + rad, + self.model_name if rad.endswith('_') else '') + + @property + def detail_create_url(self): + obj = self.crud if hasattr(self, 'crud') else self + if self.request.user.has_module_perms('materia'): + parent_field = obj.parent_field.split('__')[0] + parent_object = getattr(self.object, parent_field) + + root_pk = parent_object.pk + + return self.resolve_url(ACTION_CREATE, args=(root_pk,)) + return '' @property def list_url(self): @@ -802,6 +823,9 @@ class LegislacaoCitadaCrud(MasterDetailCrud): def layout_key(self): return 'LegislacaoCitadaDetail' + class DeleteView(MasterDetailCrud.DeleteView): + pass + class NumeracaoCrud(MasterDetailCrud): model = Numeracao