From 09af5336bd5a4e157f27d4b44303895fb0da4090 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 22 Jun 2016 12:34:06 -0300 Subject: [PATCH] Restringe as tabelas auxiliares aos superusers --- sapl/base/views.py | 15 +++++++++------ sapl/comissoes/views.py | 14 ++++++++++---- sapl/materia/views.py | 34 ++++++++++++++++++++++----------- sapl/parlamentares/views.py | 38 +++++++++++++++++++++++-------------- sapl/sessao/views.py | 18 ++++++++++++------ sapl/utils.py | 7 +++++++ 6 files changed, 85 insertions(+), 41 deletions(-) diff --git a/sapl/base/views.py b/sapl/base/views.py index 5219dabc9..e0ea3f9e3 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -2,6 +2,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin from django.views.generic.base import TemplateView from sapl.crud.base import Crud, CrudBaseMixin, CrudCreateView, CrudUpdateView +from sapl.utils import permissao_tb_aux from .forms import CasaLegislativaForm from .models import CasaLegislativa @@ -16,9 +17,14 @@ class CasaLegislativaCrud(Crud): help_path = '' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = {'base.add_casalegislativa'} list_field_names = ['codigo', 'nome', 'sigla'] + def has_permission(self): + if self.request.user.is_superuser: + return True + else: + return False + class CreateView(PermissionRequiredMixin, CrudCreateView): permission_required = {'base.add_casa_legislativa'} form_class = CasaLegislativaForm @@ -39,8 +45,5 @@ class SistemaView(PermissionRequiredMixin, TemplateView): template_name = 'sistema.html' permission_required = '' - def has_perm(self): - if self.request.user.is_superuser: - return True - else: - return False + def has_permission(self): + return permissao_tb_aux(self) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 4772c4566..8821b9d85 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -6,7 +6,7 @@ from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudUpdateView, CrudDeleteView) from sapl.crud.masterdetail import MasterDetailCrud from sapl.materia.models import Tramitacao -from sapl.utils import permissoes_comissoes +from sapl.utils import permissoes_comissoes, permissao_tb_aux from .models import (CargoComissao, Comissao, Composicao, Participacao, Periodo, TipoComissao) @@ -24,28 +24,34 @@ class CargoCrud(Crud): help_path = 'cargo_comissao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_comissoes() list_field_names = ['nome', 'unico'] + def has_permission(self): + return permissao_tb_aux(self) + class PeriodoComposicaoCrud(Crud): model = Periodo help_path = 'periodo_composicao_comissao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_comissoes() list_field_names = ['data_inicio', 'data_fim'] + def has_permission(self): + return permissao_tb_aux(self) + class TipoComissaoCrud(Crud): model = TipoComissao help_path = 'tipo_comissao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_comissoes() list_field_names = ['sigla', 'nome', 'natureza', 'dispositivo_regimental'] + def has_permission(self): + return permissao_tb_aux(self) + class ParticipacaoCrud(MasterDetailCrud): model = Participacao diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 5807bf45e..db45d9fd7 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -23,7 +23,7 @@ from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudListView, from sapl.crud.masterdetail import MasterDetailCrud from sapl.norma.models import LegislacaoCitada from sapl.utils import (autor_label, autor_modal, get_base_url, - permissoes_materia) + permissoes_materia, permissao_tb_aux) from .forms import (AcompanhamentoMateriaForm, AnexadaForm, AutoriaForm, DespachoInicialForm, DocumentoAcessorioForm, @@ -48,7 +48,8 @@ class OrigemCrud(Crud): help_path = 'origem' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class TipoMateriaCrud(Crud): @@ -56,7 +57,8 @@ class TipoMateriaCrud(Crud): help_path = 'tipo_materia_legislativa' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class RegimeTramitacaoCrud(Crud): @@ -64,7 +66,8 @@ class RegimeTramitacaoCrud(Crud): help_path = 'regime_tramitacao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class TipoDocumentoCrud(Crud): @@ -72,7 +75,8 @@ class TipoDocumentoCrud(Crud): help_path = 'tipo_documento' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class TipoFimRelatoriaCrud(Crud): @@ -80,7 +84,8 @@ class TipoFimRelatoriaCrud(Crud): help_path = 'fim_relatoria' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class TipoAutorCrud(Crud): @@ -88,7 +93,8 @@ class TipoAutorCrud(Crud): help_path = 'tipo_autor' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class AutorCrud(Crud): @@ -96,7 +102,8 @@ class AutorCrud(Crud): help_path = 'autor' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class OrgaoCrud(Crud): @@ -104,7 +111,9 @@ class OrgaoCrud(Crud): help_path = 'orgao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + + def has_permission(self): + return permissao_tb_aux(self) class TipoProposicaoCrud(Crud): @@ -112,7 +121,8 @@ class TipoProposicaoCrud(Crud): help_path = 'tipo_proposicao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + def has_permission(self): + return permissao_tb_aux(self) class StatusTramitacaoCrud(Crud): @@ -120,7 +130,9 @@ class StatusTramitacaoCrud(Crud): help_path = 'status_tramitacao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_materia() + + def has_permission(self): + return permissao_tb_aux(self) class UnidadeTramitacaoCrud(Crud): diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 2d24eec0e..5f1dfb0ec 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -10,7 +10,7 @@ from sapl.crud.base import (Crud, CrudCreateView, CrudListView, CrudUpdateView, CrudBaseMixin, CrudDeleteView) from sapl.crud.masterdetail import MasterDetailCrud -from sapl.utils import permissoes_parlamentares +from sapl.utils import permissoes_parlamentares, permissao_tb_aux from .forms import (ComposicaoColigacaoForm, FiliacaoForm, LegislaturaForm, ParlamentarCreateForm, ParlamentarForm) @@ -25,7 +25,8 @@ class CargoMesaCrud(Crud): help_path = 'cargo_mesa' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class PartidoCrud(Crud): @@ -33,7 +34,8 @@ class PartidoCrud(Crud): help_path = 'partidos' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class SessaoLegislativaCrud(Crud): @@ -41,7 +43,8 @@ class SessaoLegislativaCrud(Crud): help_path = 'sessao_legislativa' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class TipoDependenteCrud(Crud): @@ -49,7 +52,8 @@ class TipoDependenteCrud(Crud): help_path = 'nivel_instrucao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class NivelInstrucaoCrud(Crud): @@ -57,7 +61,8 @@ class NivelInstrucaoCrud(Crud): help_path = 'tipo_dependente' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class TipoAfastamentoCrud(Crud): @@ -65,7 +70,8 @@ class TipoAfastamentoCrud(Crud): help_path = 'tipo_afastamento' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class TipoMilitarCrud(Crud): @@ -73,7 +79,8 @@ class TipoMilitarCrud(Crud): help_path = 'tipo_situa_militar' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class DependenteCrud(MasterDetailCrud): @@ -117,7 +124,8 @@ class ColigacaoCrud(Crud): ordering = ('-legislatura__data_inicio', 'nome') class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class ComposicaoColigacaoCrud(MasterDetailCrud): @@ -143,7 +151,8 @@ class ComposicaoColigacaoCrud(MasterDetailCrud): ordering = '-partido__sigla' class BaseMixin(PermissionRequiredMixin, MasterDetailCrud.BaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class LegislaturaCrud(Crud): @@ -157,7 +166,8 @@ class LegislaturaCrud(Crud): form_class = LegislaturaForm class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_parlamentares() + def has_permission(self): + return permissao_tb_aux(self) class FiliacaoCrud(MasterDetailCrud): @@ -261,9 +271,9 @@ class MesaDiretoraView(PermissionRequiredMixin, FormView): # Essa função avisa quando se pode compor uma Mesa Legislativa def validation(self, request): - mensagem = _("Não há nenhuma Sessão Legislativa cadastrada. \ - Só é possível compor uma Mesa Diretora quando há uma Sessão \ - Legislativa cadastrada.") + mensagem = _('Não há nenhuma Sessão Legislativa cadastrada. ' + + 'Só é possível compor uma Mesa Diretora quando ' + + 'há uma Sessão Legislativa cadastrada.') messages.add_message(request, messages.INFO, mensagem) return self.render_to_response( diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 5407c1268..fcf86f165 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -23,7 +23,7 @@ from sapl.materia.models import (Autoria, DocumentoAcessorio, from sapl.norma.models import NormaJuridica from sapl.parlamentares.models import Parlamentar from sapl.sessao.serializers import SessaoPlenariaSerializer -from sapl.utils import permissoes_sessao, permissoes_painel +from sapl.utils import permissoes_sessao, permissoes_painel, permissao_tb_aux from .forms import (BancadaForm, ExpedienteForm, ExpedienteMateriaForm, ListMateriaForm, MateriaOrdemDiaForm, MesaForm, @@ -59,7 +59,9 @@ class BancadaCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): list_field_names = ['nome', 'legislatura'] - permission_required = permissoes_sessao() + + def has_permission(self): + return permissao_tb_aux(self) class ListView(CrudListView): ordering = 'legislatura' @@ -76,7 +78,8 @@ class TipoSessaoCrud(Crud): help_path = 'tipo_sessao_plenaria' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_sessao() + def has_permission(self): + return permissao_tb_aux(self) class TipoResultadoVotacaoCrud(Crud): @@ -84,7 +87,8 @@ class TipoResultadoVotacaoCrud(Crud): help_path = 'tipo_resultado_votacao' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_sessao() + def has_permission(self): + return permissao_tb_aux(self) class TipoExpedienteCrud(Crud): @@ -92,7 +96,8 @@ class TipoExpedienteCrud(Crud): help_path = 'tipo_expediente' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_sessao() + def has_permission(self): + return permissao_tb_aux(self) class CargoBancadaCrud(Crud): @@ -100,7 +105,8 @@ class CargoBancadaCrud(Crud): help_path = '' class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): - permission_required = permissoes_sessao() + def has_permission(self): + return permissao_tb_aux(self) def abrir_votacao_view(request, pk, spk): diff --git a/sapl/utils.py b/sapl/utils.py index 4f99611e2..f6a0dd22a 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -295,3 +295,10 @@ def permissoes_painel(): for p in perms_painel: lista_permissoes.append('painel.' + p.codename) return set(lista_permissoes) + + +def permissao_tb_aux(self): + if self.request.user.is_superuser: + return True + else: + return False