diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index 0c589e847..a157010dd 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -1,7 +1,9 @@ from compressor.utils import get_class from django import template +from sapl.base.models import AppConfig from sapl.parlamentares.models import Filiacao +from sapl.utils import permissoes_adm register = template.Library() @@ -85,6 +87,18 @@ def get_delete_perm(value, arg): return perm.__contains__(nome_app + can_delete) +@register.filter +def get_doc_adm_template_perms(user): + app_config = AppConfig.objects.last() + if app_config.documentos_administrativos == 'O': + return True + elif user.has_perms(permissoes_adm()): + return True + + else: + return False + + @register.filter def ver_menu_sistema_perm(value): u = value diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index c9fffea30..6fcfd76af 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -17,7 +17,8 @@ from django_filters.views import FilterView import sapl.crud.base from sapl.base.models import AppConfig from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, - CrudDeleteView, CrudListView, CrudUpdateView, + CrudDetailView, CrudDeleteView, + CrudListView, CrudUpdateView, make_pagination) from sapl.crud.masterdetail import MasterDetailCrud from sapl.materia.models import TipoMateriaLegislativa @@ -62,6 +63,30 @@ class DocumentoAdministrativoCrud(Crud): class DeleteView(PermissionRequiredMixin, CrudDeleteView): permission_required = permissoes_adm() + class ListView(PermissionRequiredMixin, CrudListView): + permission_required = permissoes_adm() + + def has_permission(self): + app_config = AppConfig.objects.last() + if app_config.documentos_administrativos == 'O': + return True + + else: + perms = self.get_permission_required() + return self.request.user.has_perms(perms) + + class DetailView(PermissionRequiredMixin, CrudDetailView): + permission_required = permissoes_adm() + + def has_permission(self): + app_config = AppConfig.objects.last() + if app_config.documentos_administrativos == 'O': + return True + + else: + perms = self.get_permission_required() + return self.request.user.has_perms(perms) + class StatusTramitacaoAdministrativoCrud(Crud): model = StatusTramitacaoAdministrativo @@ -373,6 +398,15 @@ class PesquisarDocumentoAdministrativoView(PermissionRequiredMixin, paginate_by = 10 permission_required = permissoes_adm() + def has_permission(self): + app_config = AppConfig.objects.last() + if app_config.documentos_administrativos == 'O': + return True + + else: + perms = self.get_permission_required() + return self.request.user.has_perms(perms) + def get_filterset_kwargs(self, filterset_class): super(PesquisarDocumentoAdministrativoView, self).get_filterset_kwargs(filterset_class) @@ -574,6 +608,9 @@ class TramitacaoAdmCrud(MasterDetailCrud): form_class = TramitacaoAdmEditForm permission_required = permissoes_adm() + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_adm() + class ListView(PermissionRequiredMixin, MasterDetailCrud.ListView): permission_required = permissoes_adm() @@ -582,6 +619,27 @@ class TramitacaoAdmCrud(MasterDetailCrud): kwargs = {self.crud.parent_field: self.kwargs['pk']} return qs.filter(**kwargs).order_by('-id') + def has_permission(self): + app_config = AppConfig.objects.last() + if app_config.documentos_administrativos == 'O': + return True + + else: + perms = self.get_permission_required() + return self.request.user.has_perms(perms) + + class DetailView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + permission_required = permissoes_adm() + + def has_permission(self): + app_config = AppConfig.objects.last() + if app_config.documentos_administrativos == 'O': + return True + + else: + perms = self.get_permission_required() + return self.request.user.has_perms(perms) + def get_nome_autor(request): nome_autor = '' diff --git a/sapl/templates/base.html b/sapl/templates/base.html index 0d500716a..37d1e9f44 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -62,16 +62,19 @@ {# #} + {% endif %} + {% if user|get_doc_adm_template_perms %} + {% endif %}