Browse Source

Restringe as tabelas auxiliares aos superusers

pull/505/head
Eduardo Calil 9 years ago
committed by LeandroRoberto
parent
commit
7f5d12383d
  1. 19
      sapl/base/views.py
  2. 14
      sapl/comissoes/views.py
  3. 34
      sapl/materia/views.py
  4. 38
      sapl/parlamentares/views.py
  5. 18
      sapl/sessao/views.py
  6. 7
      sapl/utils.py

19
sapl/base/views.py

@ -3,8 +3,9 @@ from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.views.generic.base import TemplateView
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDetailView, CrudUpdateView)
from sapl.crud.base import Crud, CrudBaseMixin, CrudCreateView,\
CrudDetailView, CrudUpdateView
from sapl.utils import permissao_tb_aux
from .forms import CasaLegislativaForm
from .models import CasaLegislativa
@ -19,9 +20,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
@ -50,8 +56,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)

14
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

34
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):

38
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. \
é possível compor uma Mesa Diretora quando 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(

18
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):

7
sapl/utils.py

@ -293,3 +293,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

Loading…
Cancel
Save