From d5a2831c6ac625b38f2bd934a833ed220f096693 Mon Sep 17 00:00:00 2001 From: LeandroJatai Date: Fri, 26 Apr 2024 14:41:06 -0300 Subject: [PATCH] =?UTF-8?q?fix:=20corrige=20carga=20de=20permiss=C3=B5es?= =?UTF-8?q?=20p=C3=BAblicas=20do=20crud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit permissões declaradas como públicas no atributo "public" do Crud estavam sendo descartadas pois estavam sendo guardadas no atributo crud as subclasses originais do crud, e não a construída dentro do get_urls. --- sapl/base/templatetags/menus.py | 26 +++++++----- sapl/crud/base.py | 73 ++++++++++++++++++++++++--------- 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index 0c3f54ca9..65ecdcfec 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -183,17 +183,21 @@ def resolve_urls_inplace(menu, pk, rm, context): as funcionalidades diretas do MasterDetailCrud, como: - visualização de detalhes, adição, edição, remoção. """ - if 'view' in context: - view = context['view'] - if hasattr(view, '__class__') and\ - hasattr(view.__class__, 'crud'): - urls = view.__class__.crud.get_urls() - for u in urls: - if (u.name == url_name or - 'urls_extras' in menu and - u.name in menu['urls_extras']): - menu['active'] = 'active' - break + try: + if 'view' in context: + view = context['view'] + if hasattr(view, 'crud'): + urls = view.crud.get_urls() + for u in urls: + if (u.name == url_name or + 'urls_extras' in menu and + u.name in menu['urls_extras']): + menu['active'] = 'active' + break + except: + url_active = menu.get('url', '') + logger.warning( + f'Não foi possível definir se url {url_active} é a url ativa.') elif 'check_permission' in menu and not context[ 'request'].user.has_perm(menu['check_permission']): menu['active'] = '' diff --git a/sapl/crud/base.py b/sapl/crud/base.py index 94637d9d7..5dbc713dc 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -263,18 +263,18 @@ class CrudBaseMixin(CrispyLayoutFormMixin): self.model_name_set = getattr( obj.model, obj.model_set).field.model._meta.model_name - if hasattr(self, 'permission_required') and self.permission_required: - if hasattr(obj, 'public'): - self.permission_required = list( - set(self.permission_required) - set(obj.public)) - else: - obj.public = [] + if not hasattr(obj, 'public'): + obj.public = [] - self.permission_required = tuple(( - self.permission(pr) for pr in self.permission_required)) + if hasattr(self, 'permission_required') and self.permission_required: - else: - obj.public = [] + self.permission_required = tuple( + ( + self.permission(pr) for pr in ( + set(self.permission_required) - set(obj.public) + ) + ) + ) @classmethod def url_name(cls, suffix): @@ -460,7 +460,8 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): # URL padrão para primeira coluna da listagem url = self.resolve_url( ACTION_DETAIL, args=(obj.id,)) if i == 0 else None - # gera URL para matéria a partir de fk_urlify_for_list em layouts.yaml + # gera URL para matéria a partir de fk_urlify_for_list em + # layouts.yaml if i > 0 and func is not None: url = getattr(self, func)(obj, name)[0] @@ -495,7 +496,7 @@ class CrudListView(PermissionRequiredContainerCrudMixin, ListView): if m: ss = get_field_display(m, n[-1])[1] ss = ( - ('
' if '