diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index dc38f1014..6d4754461 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -36,3 +36,47 @@ def lookup(d, key): def isinst(value, class_str): classe = value.__class__.__name__ return classe == class_str + + +@register.filter +def to_class_name(value): + return value.__class__.__name__.lower() + + +@register.filter +def get_add_perm(value, arg): + perm = value + view = arg + + nome_app = view.__class__.model._meta.app_label + nome_model = view.__class__.model.__name__.lower() + can_add = '.add_' + nome_model + + return perm.__contains__(nome_app + can_add) + + +@register.filter +def get_change_perm(value, arg): + perm = value + view = arg + + nome_app = view.__class__.model._meta.app_label + nome_model = view.__class__.model.__name__.lower() + can_change = '.change_' + nome_model + + return perm.__contains__(nome_app + can_change) + + +@register.filter +def get_delete_perm(value, arg): + perm = value + view = arg + + nome_app = view.__class__.model._meta.app_label + nome_model = view.__class__.model.__name__.lower() + can_delete = '.delete_' + nome_model + + return perm.__contains__(nome_app + can_delete) + +# view.__class__.model._meta.app_label -> nome do app +# context.getcontext.get('view').__class__.model.__name__.lower() -> nome do model diff --git a/sapl/templates/crud/detail.html b/sapl/templates/crud/detail.html index 5eb502d19..1cf0cd182 100644 --- a/sapl/templates/crud/detail.html +++ b/sapl/templates/crud/detail.html @@ -1,13 +1,19 @@ {% extends "base.html" %} {% load i18n %} +{% load common_tags %} {% block base_content %}
{% block actions %}
- {% trans 'Editar' %} - {% trans 'Excluir' %} + {% if perms|get_change_perm:view %} + {% trans 'Editar' %} + {% endif %} + + {% if perms|get_delete_perm:view %} + {% trans 'Excluir' %} + {% endif %}
{% endblock actions %}
diff --git a/sapl/templates/crud/list.html b/sapl/templates/crud/list.html index 0d98cbdd2..b43fa8b1f 100644 --- a/sapl/templates/crud/list.html +++ b/sapl/templates/crud/list.html @@ -1,14 +1,17 @@ {% extends "base.html" %} {% load i18n %} +{% load common_tags %} {% block base_content %} -
- - {% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %} - - {% block more_buttons %}{% endblock more_buttons %} -
+
+ {% if perms|get_add_perm:view %} + + {% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %} + + {% endif %} + {% block more_buttons %}{% endblock more_buttons %} +


{% block extra_content %} {% endblock %} diff --git a/sapl/templates/materia/proposicao_detail.html b/sapl/templates/materia/proposicao_detail.html index 25834b48d..2eb15c6c7 100644 --- a/sapl/templates/materia/proposicao_detail.html +++ b/sapl/templates/materia/proposicao_detail.html @@ -1,14 +1,26 @@ {% extends "crud/detail.html" %} {% load i18n %} +{% load common_tags %} {% block actions %}
{% if proposicao.data_envio %} - {% trans 'Editar Proposição' %} - {% trans 'Retornar Proposição Enviada' %} + {% if perms|get_change_perm:view %} + {% trans 'Editar Proposição' %} + {% endif %} + + {% if perms|get_delete_perm:view %} + {% trans 'Retornar Proposição Enviada' %} + {% endif %} + {% else %} - {% trans 'Enviar/Editar Proposição' %} - {% trans 'Excluir Proposição' %} + {% if perms|get_change_perm:view %} + {% trans 'Enviar/Editar Proposição' %} + {% endif %} + + {% if perms|get_delete_perm:view %} + {% trans 'Excluir Proposição' %} + {% endif %} {% endif %}
{% endblock actions %} diff --git a/sapl/templates/norma/list_pesquisa.html b/sapl/templates/norma/list_pesquisa.html index a648121e8..c16cea1b6 100644 --- a/sapl/templates/norma/list_pesquisa.html +++ b/sapl/templates/norma/list_pesquisa.html @@ -1,10 +1,14 @@ {% extends "crud/detail.html" %} {% load i18n %} {% load crispy_forms_tags %} +{% load common_tags %} + {% block actions %}{% endblock %} {% block detail_content %}
- Adicionar Norma Jurídica + {% if perms.norma.add_normajuridica %} + Adicionar Norma Jurídica + {% endif %}



{% if object_list %} diff --git a/sapl/templates/norma/pesquisa.html b/sapl/templates/norma/pesquisa.html index d14c04c3f..0a3228575 100644 --- a/sapl/templates/norma/pesquisa.html +++ b/sapl/templates/norma/pesquisa.html @@ -1,12 +1,15 @@ {% extends "crud/detail.html" %} {% load i18n %} {% load crispy_forms_tags %} +{% load common_tags %} {% block base_content %} {% block actions %}
- {% trans 'Adicionar Norma Juridica' %} + {% if perms.norma.add_normajuridica %} + {% trans 'Adicionar Norma Juridica' %} + {% endif %}


{% endblock %} diff --git a/sapl/templates/sessao/materia_ordemdia_list.html b/sapl/templates/sessao/materia_ordemdia_list.html index 33d33fe84..4c4e9b9f5 100644 --- a/sapl/templates/sessao/materia_ordemdia_list.html +++ b/sapl/templates/sessao/materia_ordemdia_list.html @@ -1,5 +1,6 @@ {% extends "crud/detail.html" %} {% load i18n %} +{% load common_tags %} {% block detail_content %} @@ -74,11 +75,15 @@ Matérias da Ordem do Dia
{% csrf_token %} - {% trans 'Adicionar Matérias' %} -     + {% if perms|get_add_perm:view %} + {% trans 'Adicionar Matérias' %} +     + {% endif %}     - + {% if perms|get_add_perm:view %} + + {% endif %}
{% endblock detail_content %}