Browse Source

Implementa a Autorizacao para Proposicoes

pull/508/head
Eduardo Calil 9 years ago
parent
commit
3686447497
  1. 3
      sapl/materia/layouts.yaml
  2. 54
      sapl/materia/views.py
  3. 9
      sapl/utils.py

3
sapl/materia/layouts.yaml

@ -97,8 +97,7 @@ ProposicaoCreate:
Proposição:
- tipo data_envio
- descricao
Materia:
- tipo_materia numero_materia ano_materia
Complemento:
- texto_original

54
sapl/materia/views.py

@ -23,12 +23,14 @@ from django_filters.views import FilterView
from sapl.base.models import CasaLegislativa
from sapl.compilacao.views import IntegracaoTaView
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudListView,
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDetailView, CrudListView,
CrudUpdateView, CrudDeleteView, make_pagination)
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, permissao_tb_aux)
permissoes_autor, permissoes_materia,
permissao_tb_aux)
from .forms import (AcompanhamentoMateriaForm, AnexadaForm, AutorForm,
AutoriaForm, DespachoInicialForm, DocumentoAcessorioForm,
@ -219,14 +221,53 @@ class ProposicaoCrud(Crud):
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
form_class = ProposicaoForm
permission_required = permissoes_materia()
permission_required = permissoes_autor()
@property
def layout_key(self):
return 'ProposicaoCreate'
class ListView(CrudListView):
def has_permission(self):
perms = self.get_permission_required()
if self.request.user.has_perms(perms):
if (Proposicao.objects.filter(
id=self.kwargs['pk'],
autor__user_id=self.request.user.id).exists()):
proposicao = Proposicao.objects.get(
id=self.kwargs['pk'],
autor__user_id=self.request.user.id)
if not proposicao.data_recebimento:
return True
else:
msg = _('Essa proposição já foi recebida. ' +
'Não pode mais ser editada')
messages.add_message(self.request, messages.ERROR, msg)
return False
else:
return False
class DetailView(PermissionRequiredMixin, CrudDetailView):
permission_required = permissoes_autor()
@property
def layout_key(self):
return 'ProposicaoCreate'
def has_permission(self):
perms = self.get_permission_required()
if self.request.user.has_perms(perms):
if (Proposicao.objects.filter(
id=self.kwargs['pk'],
autor__user_id=self.request.user.id).exists()):
return True
else:
return False
else:
return False
class ListView(PermissionRequiredMixin, CrudListView):
ordering = ['-data_envio', 'descricao']
permission_required = permissoes_autor()
def get_rows(self, object_list):
@ -236,6 +277,11 @@ class ProposicaoCrud(Crud):
return [self._as_row(obj) for obj in object_list]
def get_queryset(self):
lista = Proposicao.objects.filter(
autor__user_id=self.request.user.id)
return lista
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
permission_required = permissoes_materia()

9
sapl/utils.py

@ -302,3 +302,12 @@ def permissao_tb_aux(self):
return True
else:
return False
def permissoes_autor():
lista_permissoes = []
perms_autor = list(Permission.objects.filter(
group__name='Autor'))
for p in perms_autor:
lista_permissoes.append('materia.' + p.codename)
return set(lista_permissoes)

Loading…
Cancel
Save