From 134c22b1c047589961085b6a4d9508c3224374a6 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 27 Jun 2016 17:51:33 -0300 Subject: [PATCH] Resolve alguns problemas apontados pelo Leandro --- sapl/comissoes/views.py | 8 +++---- sapl/materia/views.py | 2 +- sapl/parlamentares/models.py | 4 +++- sapl/parlamentares/views.py | 21 +++++++++++++++---- sapl/sessao/views.py | 2 +- sapl/templates/base.html | 2 +- .../mesa_diretora/mesa_diretora.html | 10 +++++++-- sapl/utils.py | 4 ++-- 8 files changed, 37 insertions(+), 16 deletions(-) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 8821b9d85..7051d3b15 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -95,7 +95,7 @@ class ParticipacaoCrud(MasterDetailCrud): def cancel_url(self): return pegar_url_composicao(self.kwargs['pk']) - class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + class BaseMixin(PermissionRequiredMixin, MasterDetailCrud.BaseMixin): permission_required = permissoes_comissoes() list_field_names = ['composicao', 'parlamentar', 'cargo'] @@ -114,13 +114,13 @@ class ComposicaoCrud(MasterDetailCrud): context['participacoes'] = composicao.participacao_set.all() return self.render_to_response(context) - class CreateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): permission_required = permissoes_comissoes() - class UpdateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): permission_required = permissoes_comissoes() - class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): permission_required = permissoes_comissoes() diff --git a/sapl/materia/views.py b/sapl/materia/views.py index b16048e9a..8076bc49a 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -233,7 +233,7 @@ class RelatoriaCrud(MasterDetailCrud): permission_required = permissoes_materia() form_class = RelatoriaForm - class DeleteView(PermissionRequiredMixin, CrudDeleteView): + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): permission_required = permissoes_materia() diff --git a/sapl/parlamentares/models.py b/sapl/parlamentares/models.py index 53e42a18e..d4c8d817a 100644 --- a/sapl/parlamentares/models.py +++ b/sapl/parlamentares/models.py @@ -40,7 +40,9 @@ class SessaoLegislativa(models.Model): ('E', 'extraordinaria', _('Extraordinária')), ) - legislatura = models.ForeignKey(Legislatura, verbose_name=Legislatura) + legislatura = models.ForeignKey( + Legislatura, + verbose_name=Legislatura._meta.verbose_name) numero = models.PositiveIntegerField(verbose_name=_('Número')) tipo = models.CharField( max_length=1, verbose_name=_('Tipo'), choices=TIPO_SESSAO_CHOICES) diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 5f1dfb0ec..f6abb062c 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -1,5 +1,8 @@ from django.contrib import messages +from django.contrib.auth.decorators import user_passes_test from django.contrib.auth.mixins import PermissionRequiredMixin +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType from django.core.urlresolvers import reverse_lazy from django.shortcuts import redirect from django.utils.datastructures import MultiValueDictKeyError @@ -264,10 +267,20 @@ class ParlamentarCrud(Crud): return context -class MesaDiretoraView(PermissionRequiredMixin, FormView): +def check_permission_mesa(request): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='parlamentares') + cts = cts.filter(model__icontains='mesa') + perms = list(Permission.objects.filter(content_type__in=cts)) + for p in perms: + lista_permissoes.append('parlamentares.' + p.codename) + + return request.user.has_perms(set(lista_permissoes)) + + +class MesaDiretoraView(FormView): template_name = "mesa_diretora/mesa_diretora.html" success_url = reverse_lazy('sapl.parlamentares:mesa_diretora') - permission_required = permissoes_parlamentares() # Essa função avisa quando se pode compor uma Mesa Legislativa def validation(self, request): @@ -317,7 +330,7 @@ class MesaDiretoraView(PermissionRequiredMixin, FormView): }) def post(self, request, *args, **kwargs): - if 'Incluir' in request.POST: + if 'Incluir' in request.POST and check_permission_mesa(request): if (not Legislatura.objects.all() or not SessaoLegislativa.objects.all()): @@ -334,7 +347,7 @@ class MesaDiretoraView(PermissionRequiredMixin, FormView): return redirect('sapl.parlamentares:mesa_diretora') - elif 'Excluir' in request.POST: + elif 'Excluir' in request.POST and check_permission_mesa(request): if (not Legislatura.objects.all() or not SessaoLegislativa.objects.all()): diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index fcf86f165..e26de79f1 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -314,7 +314,7 @@ class PresencaMixin: class PresencaView(PermissionRequiredMixin, FormMixin, PresencaMixin, - SessaoCrud.DetailView): + SessaoCrud.CrudDetailView): template_name = 'sessao/presenca.html' form_class = PresencaForm model = SessaoPlenaria diff --git a/sapl/templates/base.html b/sapl/templates/base.html index 60b7132f0..260dc5fec 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -54,7 +54,7 @@ - {% if user.is_authenticated %} + {% if perms.protocoloadm %}