Browse Source

fix: corrige carga de permissões públicas do crud

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.
pull/3715/head
LeandroJatai 8 months ago
parent
commit
d5a2831c6a
  1. 10
      sapl/base/templatetags/menus.py
  2. 57
      sapl/crud/base.py

10
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.
"""
try:
if 'view' in context:
view = context['view']
if hasattr(view, '__class__') and\
hasattr(view.__class__, 'crud'):
urls = view.__class__.crud.get_urls()
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'] = ''

57
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:
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]
@ -947,6 +948,8 @@ class CrudDeleteView(PermissionRequiredContainerCrudMixin,
class Crud:
__abstract__ = True
BaseMixin = CrudBaseMixin
ListView = CrudListView
CreateView = CrudCreateView
@ -962,9 +965,26 @@ class Crud:
def get_urls(cls):
def _add_base(view):
if view:
if not view:
return
if not cls.__abstract__:
return view
pr = set()
if hasattr(view, 'permission_required') and \
view.permission_required and \
hasattr(cls, 'public') and \
cls.public:
#print(view.permission_required, view)
#print(cls.public, cls)
pr = set(view.permission_required) - set(cls.public)
class CrudViewWithBase(cls.BaseMixin, view):
permission_required = tuple(pr)
model = cls.model
help_topic = cls.help_topic
crud = cls
@ -978,6 +998,21 @@ class Crud:
CrudUpdateView = _add_base(cls.UpdateView)
CrudDeleteView = _add_base(cls.DeleteView)
cruds = CrudListView, CrudCreateView, CrudDetailView, CrudUpdateView, CrudDeleteView
if cls.__abstract__:
class CRUD(cls):
__abstract__ = False
ListView = CrudListView
CreateView = CrudCreateView
DetailView = CrudDetailView
UpdateView = CrudUpdateView
DeleteView = CrudDeleteView
for c in cruds:
if c:
c.crud = CRUD
cruds_base = [
(CrudListView.get_url_regex()
if CrudListView else None, CrudListView, ACTION_LIST),

Loading…
Cancel
Save