Browse Source

Remove func globais de perms e explicita nas views

pull/781/head
LeandroRoberto 8 years ago
parent
commit
b593cde597
  1. 30
      sapl/materia/views.py
  2. 1
      sapl/painel/views.py
  3. 16
      sapl/protocoloadm/views.py
  4. 2
      sapl/rules/map_rules.py
  5. 16
      sapl/utils.py

30
sapl/materia/views.py

@ -20,7 +20,6 @@ from django.views.generic.base import RedirectView
from django.views.generic.edit import FormView
from django_filters.views import FilterView
import sapl
from sapl.base.models import Autor, CasaLegislativa
from sapl.compilacao.views import IntegracaoTaView
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions
@ -35,9 +34,8 @@ from sapl.materia.forms import (AnexadaForm, ConfirmarProposicaoForm,
from sapl.norma.models import LegislacaoCitada
from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label,
autor_modal, gerar_hash_arquivo, get_base_url,
montar_row_autor, permission_required_for_app,
permissoes_autor, permissoes_materia,
permissoes_protocoloadm)
montar_row_autor, permission_required_for_app)
import sapl
from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm,
DocumentoAcessorioForm, MateriaLegislativaFilterSet,
@ -52,6 +50,7 @@ from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial,
TipoMateriaLegislativa, TipoProposicao, Tramitacao,
UnidadeTramitacao)
OrigemCrud = Crud.build(Origem, '')
TipoMateriaCrud = CrudAux.build(
@ -185,7 +184,7 @@ class ProposicaoDevolvida(PermissionRequiredMixin, ListView):
model = Proposicao
ordering = ['data_envio']
paginate_by = 10
permission_required = permissoes_protocoloadm()
permission_required = ('materia.list_proposicao', )
def get_queryset(self):
return Proposicao.objects.filter(
@ -209,7 +208,7 @@ class ProposicaoPendente(PermissionRequiredMixin, ListView):
model = Proposicao
ordering = ['data_envio', 'autor', 'tipo', 'descricao']
paginate_by = 10
permission_required = permissoes_protocoloadm()
permission_required = ('materia.list_proposicao', )
def get_queryset(self):
return Proposicao.objects.filter(
@ -234,7 +233,7 @@ class ProposicaoRecebida(PermissionRequiredMixin, ListView):
model = Proposicao
ordering = ['data_envio']
paginate_by = 10
permission_required = permissoes_protocoloadm()
permission_required = ('materia.list_proposicao', )
def get_queryset(self):
return Proposicao.objects.filter(
@ -557,7 +556,7 @@ class ProposicaoCrud(Crud):
class ReciboProposicaoView(TemplateView):
template_name = "materia/recibo_proposicao.html"
permission_required = permissoes_autor()
permission_required = ('materia.detail_proposicao', )
def has_permission(self):
perms = self.get_permission_required()
@ -909,7 +908,7 @@ class MateriaLegislativaCrud(Crud):
class DocumentoAcessorioView(PermissionRequiredMixin, CreateView):
template_name = "materia/documento_acessorio.html"
form_class = DocumentoAcessorioForm
permission_required = permissoes_materia()
permission_required = ('materia.add_documentoacessorio', )
def get(self, request, *args, **kwargs):
materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
@ -943,8 +942,7 @@ class DocumentoAcessorioView(PermissionRequiredMixin, CreateView):
return reverse('sapl.materia:documento_acessorio', kwargs={'pk': pk})
class AcompanhamentoConfirmarView(PermissionRequiredMixin, TemplateView):
permission_required = permissoes_materia()
class AcompanhamentoConfirmarView(TemplateView):
def get_redirect_url(self):
return reverse('sapl.sessao:list_pauta_sessao')
@ -961,8 +959,7 @@ class AcompanhamentoConfirmarView(PermissionRequiredMixin, TemplateView):
return HttpResponseRedirect(self.get_redirect_url())
class AcompanhamentoExcluirView(PermissionRequiredMixin, TemplateView):
permission_required = permissoes_materia()
class AcompanhamentoExcluirView(TemplateView):
def get_redirect_url(self):
return reverse('sapl.sessao:list_pauta_sessao')
@ -1038,9 +1035,8 @@ class MateriaLegislativaPesquisaView(FilterView):
return context
class AcompanhamentoMateriaView(PermissionRequiredMixin, CreateView):
class AcompanhamentoMateriaView(CreateView):
template_name = "materia/acompanhamento_materia.html"
permission_required = permissoes_materia()
def get_random_chars(self):
s = ascii_letters + digits
@ -1296,7 +1292,7 @@ def do_envia_email_tramitacao(request, materia):
class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView):
filterset_class = AcessorioEmLoteFilterSet
template_name = 'materia/em_lote/acessorio.html'
permission_required = permissoes_materia()
permission_required = ('materia.add_documentoacessorio',)
def get_context_data(self, **kwargs):
context = super(DocumentoAcessorioEmLoteView,
@ -1340,7 +1336,7 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView):
class PrimeiraTramitacaoEmLoteView(PermissionRequiredMixin, FilterView):
filterset_class = PrimeiraTramitacaoEmLoteFilterSet
template_name = 'materia/em_lote/tramitacao.html'
permission_required = permissoes_materia()
permission_required = ('materia.add_tramitacao', )
def get_context_data(self, **kwargs):
context = super(PrimeiraTramitacaoEmLoteView,

1
sapl/painel/views.py

@ -12,7 +12,6 @@ from sapl.parlamentares.models import Filiacao
from sapl.sessao.models import (ExpedienteMateria, OrdemDia, PresencaOrdemDia,
RegistroVotacao, SessaoPlenaria,
SessaoPlenariaPresenca, VotoParlamentar)
from sapl.utils import permissoes_painel
from .models import Cronometro

16
sapl/protocoloadm/views.py

@ -12,11 +12,10 @@ from django.views.generic import CreateView, DetailView, FormView, ListView
from django.views.generic.base import TemplateView
from django_filters.views import FilterView
import sapl
from sapl.crud.base import Crud, CrudAux, MasterDetailCrud, make_pagination
from sapl.materia.models import TipoMateriaLegislativa
from sapl.utils import (create_barcode, get_client_ip, permissoes_adm,
permissoes_protocoloadm)
from sapl.utils import (create_barcode, get_client_ip)
import sapl
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoFilterSet,
@ -27,6 +26,7 @@ from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo,
Protocolo, StatusTramitacaoAdministrativo,
TipoDocumentoAdministrativo, TramitacaoAdministrativo)
TipoDocumentoAdministrativoCrud = CrudAux.build(
TipoDocumentoAdministrativo, '')
@ -362,7 +362,7 @@ class PesquisarDocumentoAdministrativoView(PermissionRequiredMixin,
model = DocumentoAdministrativo
filterset_class = DocumentoAdministrativoFilterSet
paginate_by = 10
permission_required = permissoes_adm()
permission_required = ('protocoloadm.list_documentoadministrativo', )
def get_filterset_kwargs(self, filterset_class):
super(PesquisarDocumentoAdministrativoView,
@ -420,7 +420,7 @@ class PesquisarDocumentoAdministrativoView(PermissionRequiredMixin,
class DetailDocumentoAdministrativo(PermissionRequiredMixin, DetailView):
template_name = "protocoloadm/detail_doc_adm.html"
permission_required = permissoes_adm()
permission_required = ('protocoloadm.detail_documentoadministrativo', )
def get(self, request, *args, **kwargs):
documento = DocumentoAdministrativo.objects.get(
@ -462,7 +462,8 @@ class DetailDocumentoAdministrativo(PermissionRequiredMixin, DetailView):
class DocumentoAcessorioAdministrativoEditView(PermissionRequiredMixin,
FormView):
template_name = "protocoloadm/documento_acessorio_administrativo_edit.html"
permission_required = permissoes_adm()
permission_required = (
'protocoloadm.change_documentoacessorioadministrativo', )
def get(self, request, *args, **kwargs):
doc = DocumentoAdministrativo.objects.get(
@ -510,7 +511,8 @@ class DocumentoAcessorioAdministrativoEditView(PermissionRequiredMixin,
class DocumentoAcessorioAdministrativoView(PermissionRequiredMixin, FormView):
template_name = "protocoloadm/documento_acessorio_administrativo.html"
permission_required = permissoes_adm()
permission_required = (
'protocoloadm.add_documentoacessorioadministrativo', )
def get(self, request, *args, **kwargs):
form = DocumentoAcessorioAdministrativoForm()

2
sapl/rules/map_rules.py

@ -44,7 +44,7 @@ rules_group_protocolo = {
(materia.Anexada, __base__),
(materia.Autoria, __base__),
(materia.Proposicao, [RP_CHANGE]),
(materia.Proposicao, __listdetailchange__),
]
}

16
sapl/utils.py

@ -1,11 +1,10 @@
import hashlib
import logging
import re
from datetime import date
from functools import wraps
from unicodedata import normalize as unicodedata_normalize
import hashlib
import logging
import re
import magic
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button
from django import forms
@ -20,10 +19,12 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied, ValidationError
from django.utils.translation import ugettext_lazy as _
from floppyforms import ClearableFileInput
import magic
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row
from sapl.settings import BASE_DIR
sapl_logger = logging.getLogger(BASE_DIR.name)
@ -383,7 +384,7 @@ def intervalos_tem_intersecao(a_inicio, a_fim, b_inicio, b_fim):
menor_fim = min(a_fim, b_fim)
return maior_inicio <= menor_fim
"""
def permissoes(nome_grupo, app_label):
lista_permissoes = []
try:
@ -394,6 +395,7 @@ def permissoes(nome_grupo, app_label):
except:
pass
return set(lista_permissoes)
"""
def permission_required_for_app(app_label, login_url=None,
@ -414,7 +416,7 @@ def permission_required_for_app(app_label, login_url=None,
return False
return user_passes_test(check_perms, login_url=login_url)
"""
def permissoes_materia():
return permissoes('Operador de Matéria', 'materia')
@ -467,6 +469,8 @@ def permissao_tb_aux(self):
else:
return False
"""
def gerar_hash_arquivo(arquivo, pk, block_size=2**20):
md5 = hashlib.md5()

Loading…
Cancel
Save