From a912a5a5028ab7d1081a1c8090c075d3e31e8e89 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 14 Jun 2016 13:31:47 -0300 Subject: [PATCH 01/24] Script de Inicializacao dos Grupos e Autorizacoes --- scripts/inicializa_grupos_autorizacoes.py | 153 ++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 scripts/inicializa_grupos_autorizacoes.py diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py new file mode 100644 index 000000000..64c05b3af --- /dev/null +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -0,0 +1,153 @@ +from django.contrib.auth.models import Group, Permission +from django.contrib.contenttypes.models import ContentType + + +def cria_grupos_permissoes(): + + if not Group.objects.filter("Teste"): + pass + + # Cria todos os grupos necessários para a aplicação + + if not Group.objects.filter(name="Operador Geral").exists(): + op_geral = Group.objects.create(name="Operador Geral") + else: + op_geral = Group.objects.get(name="Operador Geral") + + if not Group.objects.filter(name="Operador de Protocolo").exists(): + op_prot = Group.objects.create(name="Operador de Protocolo") + else: + op_prot = Group.objects.get(name="Operador de Protocolo") + + if not Group.objects.filter(name="Operador de Sessão").exists(): + op_sessao = Group.objects.create(name="Operador de Sessão") + else: + op_sessao = Group.objects.get(name="Operador de Sessão") + + if not Group.objects.filter(name="Operador de Comissão").exists(): + op_comissao = Group.objects.create(name="Operador de Comissão") + else: + op_comissao = Group.objects.get(name="Operador de Comissão") + + if not Group.objects.filter(name="Operador de Administração").exists(): + op_adm = Group.objects.create(name="Operador de Administração") + else: + op_adm = Group.objects.get(name="Operador de Administração") + + if not Group.objects.filter(name="Operador de Norma Jurídica").exists(): + op_norma = Group.objects.create(name="Operador de Norma Jurídica") + else: + op_norma = Group.objects.get(name="Operador de Norma Jurídica") + + if not Group.objects.filter(name="Operador de Matéria Legislativa").exists(): + op_materia = Group.objects.create( + name="Operador de Matéria Legislativa") + else: + op_materia = Group.objects.get(name="Operador de Matéria Legislativa") + + if not Group.objects.filter(name="Autor").exists(): + op_autor = Group.objects.create(name="Autor") + else: + op_autor = Group.objects.get(name="Autor") + + # Base + + permissao_add_cl = Permission.objects.get( + name="Can add Casa Legislativa") + permissao_edit_cl = Permission.objects.get( + name="Can change Casa Legislativa") + permissao_remove_cl = Permission.objects.get( + name="Can delete Casa Legislativa") + + permissoes_base = [permissao_add_cl, + permissao_edit_cl, + permissao_remove_cl] + + # Comissao + + cts = ContentType.objects.filter(app_label='comissoes') + perms_comissoes = list(Permission.objects.filter(content_type__in=cts)) + + # Materia + + cts = ContentType.objects.filter(app_label='materia') + perms_materia = list(Permission.objects.filter(content_type__in=cts)) + + # Norma + + cts = ContentType.objects.filter(app_label='norma') + perms_norma = list(Permission.objects.filter(content_type__in=cts)) + + # Painel + + cts = ContentType.objects.filter(app_label='painel') + perms_painel = list(Permission.objects.filter(content_type__in=cts)) + + # Parlamentares + + cts = ContentType.objects.filter(app_label='parlamentares') + perms_parlamentares = list(Permission.objects.filter(content_type__in=cts)) + + # ProtocoloADM e DOCADM + + cts = ContentType.objects.filter(app_label='protocoloadm') + + perms_docadm = list(Permission.objects.filter(content_type__in=cts)) + + cts_exc1 = cts.filter(model__icontains='tramitacao') + cts_exc2 = cts.filter(model__icontains='documentoadministrativo') + + cts = cts.exclude(id__in=[o.id for o in cts_exc1]) + cts = cts.exclude(id__in=[o.id for o in cts_exc2]) + + perms_protocoloadm = list(Permission.objects.filter(content_type__in=cts)) + + # Sessao + + cts = ContentType.objects.filter(app_label='sessao') + perms_sessao = list(Permission.objects.filter(content_type__in=cts)) + + # Autor + + perms_autor = Permission.objects.get(name="Can add Proposição") + + # Configura Permissoes Operador de Protocolo + for p in perms_protocoloadm: + op_prot.permissions.add(p) + + # Configura Permissoes Operador de Sessao + for p in perms_sessao: + op_sessao.permissions.add(p) + + # Configura Permissoes Operador de Comissao + for p in perms_comissoes: + op_comissao.permissions.add(p) + + # Configura Permissoes Operador de Administracao + for p in perms_docadm: + op_adm.permissions.add(p) + + # Configura Permissoes Operador de Norma + for p in perms_norma: + op_norma.permissions.add(p) + + # Configura Permissoes Operador de Materia + for p in perms_materia: + op_materia.permissions.add(p) + + # Configura Permissoes Autor + op_autor.permissions.add(perms_autor) + + # Configura Permissoes Operador Geral + perms_op_geral = perms_protocoloadm + perms_sessao + perms_comissoes + perms_op_geral = perms_op_geral + perms_docadm + perms_norma + perms_op_geral = perms_op_geral + perms_materia + perms_op_geral = perms_op_geral + perms_parlamentares + perms_painel + perms_op_geral = perms_op_geral + permissoes_base + + for p in perms_op_geral: + op_geral.permissions.add(p) + op_geral.permissions.add(perms_autor) + +if __name__ == '__main__': + cria_grupos_permissoes() From 023d9c90fa18da780018f5df4b40b5d11e7aba05 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 14 Jun 2016 14:03:39 -0300 Subject: [PATCH 02/24] =?UTF-8?q?Refatora=20recupera=C3=A7=C3=A3o/cria?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20grupos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/inicializa_grupos_autorizacoes.py | 48 ++++------------------- 1 file changed, 8 insertions(+), 40 deletions(-) diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py index 64c05b3af..8ad92a646 100644 --- a/scripts/inicializa_grupos_autorizacoes.py +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -9,46 +9,14 @@ def cria_grupos_permissoes(): # Cria todos os grupos necessários para a aplicação - if not Group.objects.filter(name="Operador Geral").exists(): - op_geral = Group.objects.create(name="Operador Geral") - else: - op_geral = Group.objects.get(name="Operador Geral") - - if not Group.objects.filter(name="Operador de Protocolo").exists(): - op_prot = Group.objects.create(name="Operador de Protocolo") - else: - op_prot = Group.objects.get(name="Operador de Protocolo") - - if not Group.objects.filter(name="Operador de Sessão").exists(): - op_sessao = Group.objects.create(name="Operador de Sessão") - else: - op_sessao = Group.objects.get(name="Operador de Sessão") - - if not Group.objects.filter(name="Operador de Comissão").exists(): - op_comissao = Group.objects.create(name="Operador de Comissão") - else: - op_comissao = Group.objects.get(name="Operador de Comissão") - - if not Group.objects.filter(name="Operador de Administração").exists(): - op_adm = Group.objects.create(name="Operador de Administração") - else: - op_adm = Group.objects.get(name="Operador de Administração") - - if not Group.objects.filter(name="Operador de Norma Jurídica").exists(): - op_norma = Group.objects.create(name="Operador de Norma Jurídica") - else: - op_norma = Group.objects.get(name="Operador de Norma Jurídica") - - if not Group.objects.filter(name="Operador de Matéria Legislativa").exists(): - op_materia = Group.objects.create( - name="Operador de Matéria Legislativa") - else: - op_materia = Group.objects.get(name="Operador de Matéria Legislativa") - - if not Group.objects.filter(name="Autor").exists(): - op_autor = Group.objects.create(name="Autor") - else: - op_autor = Group.objects.get(name="Autor") + op_geral = Group.objects.get_or_create(name="Operador Geral") + op_prot = Group.objects.get_or_create(name="Operador de Protocolo") + op_sessao = Group.objects.get_or_create(name="Operador de Sessão") + op_comissao = Group.objects.get_or_create(name="Operador de Comissão") + op_adm = Group.objects.get_or_create(name="Operador de Administração") + op_norma = Group.objects.get_or_create(name="Operador de Norma Jurídica") + op_materia = Group.objects.get_or_create(name="Operador de Matéria Legislativa") + op_autor = Group.objects.get_or_create(name="Autor") # Base From e3b85e57a4a598609723a587fd178d6ae04af257 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 17 Jun 2016 10:26:20 -0300 Subject: [PATCH 03/24] Atualiza script de grupos e autorizacoes --- scripts/inicializa_grupos_autorizacoes.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py index 8ad92a646..15f12fdbd 100644 --- a/scripts/inicializa_grupos_autorizacoes.py +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -15,7 +15,8 @@ def cria_grupos_permissoes(): op_comissao = Group.objects.get_or_create(name="Operador de Comissão") op_adm = Group.objects.get_or_create(name="Operador de Administração") op_norma = Group.objects.get_or_create(name="Operador de Norma Jurídica") - op_materia = Group.objects.get_or_create(name="Operador de Matéria Legislativa") + op_materia = Group.objects.get_or_create( + name="Operador de Matéria Legislativa") op_autor = Group.objects.get_or_create(name="Autor") # Base From 8f5cb4998f890861d472adb7fd2c6e91e761d49a Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 17 Jun 2016 10:26:57 -0300 Subject: [PATCH 04/24] Faz as permissoes de Casa Legislativa --- sapl/base/views.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sapl/base/views.py b/sapl/base/views.py index eef8f7f4b..cbea94455 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1,3 +1,4 @@ +from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect from django.views.generic.base import TemplateView @@ -17,13 +18,16 @@ class CasaLegislativaCrud(Crud): model = CasaLegislativa help_path = '' - class BaseMixin(CrudBaseMixin): + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = {'base.add_casalegislativa'} list_field_names = ['codigo', 'nome', 'sigla'] - class CreateView(CrudCreateView): + class CreateView(PermissionRequiredMixin, CrudCreateView): + permission_required = {'base.add_casa_legislativa'} form_class = CasaLegislativaForm - class UpdateView(CrudUpdateView): + class UpdateView(PermissionRequiredMixin, CrudUpdateView): + permission_required = {'base.change_casalegislativa'} form_class = CasaLegislativaForm class DetailView(CrudDetailView): @@ -35,7 +39,7 @@ class CasaLegislativaCrud(Crud): kwargs={'pk': self.kwargs['pk']})) -class HelpView(TemplateView): +class HelpView(PermissionRequiredMixin, TemplateView): # XXX treat non existing template as a 404!!!! def get_template_names(self): From f02fe0aa2a8972299a6f6377e97bf371403eb60a Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 17 Jun 2016 10:27:20 -0300 Subject: [PATCH 05/24] Faz as permissoes do app Comissoes --- sapl/comissoes/views.py | 97 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 93 insertions(+), 4 deletions(-) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index f8ca4a813..155b10e89 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -1,4 +1,7 @@ from django.core.urlresolvers import reverse +from django.contrib.auth.mixins import PermissionRequiredMixin +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType from django.views.generic import ListView from sapl.crud.base import Crud, CrudBaseMixin @@ -8,9 +11,14 @@ from sapl.materia.models import Tramitacao from .models import (CargoComissao, Comissao, Composicao, Participacao, Periodo, TipoComissao) -CargoCrud = Crud.build(CargoComissao, 'cargo_comissao') -PeriodoComposicaoCrud = Crud.build(Periodo, 'periodo_composicao_comissao') -TipoComissaoCrud = Crud.build(TipoComissao, 'tipo_comissao') + +def permissoes_comissoes(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='comissoes') + perms_comissoes = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_comissoes: + lista_permissoes.append('comissoes.' + p.codename) + return set(lista_permissoes) def pegar_url_composicao(pk): @@ -20,13 +28,40 @@ def pegar_url_composicao(pk): return url +class CargoCrud(Crud): + model = CargoComissao + help_path = 'cargo_comissao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_comissoes() + list_field_names = ['nome', 'unico'] + + +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'] + + +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'] + + class ParticipacaoCrud(MasterDetailCrud): model = Participacao parent_field = 'composicao' help_path = '' class DetailView(MasterDetailCrud.DetailView): - def get(self, request, *args, **kwargs): self.object = self.get_object() context = self.get_context_data(object=self.object) @@ -63,6 +98,10 @@ class ParticipacaoCrud(MasterDetailCrud): def cancel_url(self): return pegar_url_composicao(self.kwargs['pk']) + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_comissoes() + list_field_names = ['composicao', 'parlamentar', 'cargo'] + class ComposicaoCrud(MasterDetailCrud): model = Composicao @@ -78,11 +117,61 @@ class ComposicaoCrud(MasterDetailCrud): context['participacoes'] = composicao.participacao_set.all() return self.render_to_response(context) + class CreateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:composicao_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:composicao_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:composicao_list') + class ComissaoCrud(Crud): model = Comissao help_path = 'modulo_comissoes' + class CreateView(PermissionRequiredMixin, Crud.CreateView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:comissoes_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class UpdateView(PermissionRequiredMixin, Crud.UpdateView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:comissoes_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class DeleteView(PermissionRequiredMixin, Crud.DeleteView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:comissoes_list') + class BaseMixin(CrudBaseMixin): list_field_names = ['nome', 'sigla', 'tipo', 'data_criacao'] From 8e09d99af859fea9f369e21972fa909c19961a86 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 17 Jun 2016 11:34:47 -0300 Subject: [PATCH 06/24] Faz a autorizacao do app materia --- sapl/comissoes/views.py | 41 ++----------- sapl/materia/views.py | 125 +++++++++++++++++++++++++++++++--------- 2 files changed, 103 insertions(+), 63 deletions(-) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 155b10e89..86e1f2507 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -4,7 +4,8 @@ from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType from django.views.generic import ListView -from sapl.crud.base import Crud, CrudBaseMixin +from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, + CrudUpdateView, CrudDeleteView) from sapl.crud.masterdetail import MasterDetailCrud from sapl.materia.models import Tramitacao @@ -120,58 +121,26 @@ class ComposicaoCrud(MasterDetailCrud): class CreateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): permission_required = permissoes_comissoes() - def get_success_url(self): - return reverse( - 'sapl.comissoes:composicao_detail', - kwargs={'pk': self.kwargs['pk']} - ) - class UpdateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): permission_required = permissoes_comissoes() - def get_success_url(self): - return reverse( - 'sapl.comissoes:composicao_detail', - kwargs={'pk': self.kwargs['pk']} - ) - class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DetailView): permission_required = permissoes_comissoes() - def get_success_url(self): - return reverse( - 'sapl.comissoes:composicao_list') - class ComissaoCrud(Crud): model = Comissao help_path = 'modulo_comissoes' - class CreateView(PermissionRequiredMixin, Crud.CreateView): + class CreateView(PermissionRequiredMixin, CrudCreateView): permission_required = permissoes_comissoes() - def get_success_url(self): - return reverse( - 'sapl.comissoes:comissoes_detail', - kwargs={'pk': self.kwargs['pk']} - ) - - class UpdateView(PermissionRequiredMixin, Crud.UpdateView): + class UpdateView(PermissionRequiredMixin, CrudUpdateView): permission_required = permissoes_comissoes() - def get_success_url(self): - return reverse( - 'sapl.comissoes:comissoes_detail', - kwargs={'pk': self.kwargs['pk']} - ) - - class DeleteView(PermissionRequiredMixin, Crud.DeleteView): + class DeleteView(PermissionRequiredMixin, CrudDeleteView): permission_required = permissoes_comissoes() - def get_success_url(self): - return reverse( - 'sapl.comissoes:comissoes_list') - class BaseMixin(CrudBaseMixin): list_field_names = ['nome', 'sigla', 'tipo', 'data_criacao'] diff --git a/sapl/materia/views.py b/sapl/materia/views.py index b63efc737..80b1357cb 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -5,6 +5,9 @@ from string import ascii_letters, digits from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django.contrib import messages +from django.contrib.auth.models import Permission +from django.contrib.auth.mixins import PermissionRequiredMixin +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail from django.core.urlresolvers import reverse @@ -18,7 +21,7 @@ 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, - CrudUpdateView, make_pagination) + 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 @@ -52,16 +55,30 @@ TipoProposicaoCrud = Crud.build(TipoProposicao, 'tipo_proposicao') StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') +def permissoes_materia(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='materia') + perms_materia = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_materia: + lista_permissoes.append('materia.' + p.codename) + return set(lista_permissoes) + + class UnidadeTramitacaoCrud(Crud): model = UnidadeTramitacao help_path = 'unidade_tramitacao' - class CreateView(CrudCreateView): + class CreateView(PermissionRequiredMixin, CrudCreateView): + permission_required = permissoes_materia() form_class = UnidadeTramitacaoForm - class UpdateView(CrudUpdateView): + class UpdateView(PermissionRequiredMixin, CrudUpdateView): + permission_required = permissoes_materia() form_class = UnidadeTramitacaoForm + class DeleteView(PermissionRequiredMixin, CrudDeleteView): + permission_required = permissoes_materia() + class ProposicaoCrud(Crud): model = Proposicao @@ -70,15 +87,17 @@ class ProposicaoCrud(Crud): class BaseMixin(CrudBaseMixin): list_field_names = ['data_envio', 'descricao', 'tipo'] - class CreateView(CrudCreateView): + class CreateView(PermissionRequiredMixin, CrudCreateView): form_class = ProposicaoForm + permission_required = {'materia.add_proposicao'} @property def layout_key(self): return 'ProposicaoCreate' - class UpdateView(CrudUpdateView): + class UpdateView(PermissionRequiredMixin, CrudUpdateView): form_class = ProposicaoForm + permission_required = permissoes_materia() @property def layout_key(self): @@ -95,7 +114,8 @@ class ProposicaoCrud(Crud): return [self._as_row(obj) for obj in object_list] - class DeleteView(MasterDetailCrud.DeleteView): + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() def delete(self, request, *args, **kwargs): proposicao = Proposicao.objects.get(id=self.kwargs['pk']) @@ -117,7 +137,8 @@ class RelatoriaCrud(MasterDetailCrud): parent_field = 'materia' help_path = '' - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): + permission_required = permissoes_materia() form_class = RelatoriaForm def get_initial(self): @@ -137,9 +158,13 @@ class RelatoriaCrud(MasterDetailCrud): return {'comissao': localizacao} - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): + permission_required = permissoes_materia() form_class = RelatoriaForm + class DeleteView(PermissionRequiredMixin, CrudDeleteView): + permission_required = permissoes_materia() + class TramitacaoCrud(MasterDetailCrud): model = Tramitacao @@ -150,16 +175,18 @@ class TramitacaoCrud(MasterDetailCrud): list_field_names = ['data_tramitacao', 'unidade_tramitacao_local', 'unidade_tramitacao_destino', 'status'] - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = TramitacaoForm + permission_required = permissoes_materia() def post(self, request, *args, **kwargs): materia = MateriaLegislativa.objects.get(id=kwargs['pk']) do_envia_email_tramitacao(request, materia) return super(CreateView, self).post(request, *args, **kwargs) - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = TramitacaoForm + permission_required = permissoes_materia() def post(self, request, *args, **kwargs): materia = MateriaLegislativa.objects.get(id=kwargs['pk']) @@ -173,7 +200,8 @@ class TramitacaoCrud(MasterDetailCrud): kwargs = {self.crud.parent_field: self.kwargs['pk']} return qs.filter(**kwargs).order_by('-data_tramitacao') - class DeleteView(MasterDetailCrud.DeleteView): + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() def delete(self, request, *args, **kwargs): tramitacao = Tramitacao.objects.get(id=self.kwargs['pk']) @@ -230,8 +258,9 @@ class DocumentoAcessorioCrud(MasterDetailCrud): class BaseMixin(MasterDetailCrud.BaseMixin): list_field_names = ['nome', 'tipo', 'data', 'autor', 'arquivo'] - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = DocumentoAcessorioForm + permission_required = permissoes_materia() def __init__(self, *args, **kwargs): montar_helper_documento_acessorio(self) @@ -242,8 +271,9 @@ class DocumentoAcessorioCrud(MasterDetailCrud): context['helper'] = self.helper return context - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = DocumentoAcessorioForm + permission_required = permissoes_materia() def __init__(self, *args, **kwargs): montar_helper_documento_acessorio(self) @@ -254,17 +284,25 @@ class DocumentoAcessorioCrud(MasterDetailCrud): context['helper'] = self.helper return context + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() + class AutoriaCrud(MasterDetailCrud): model = Autoria parent_field = 'materia' help_path = '' - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = AutoriaForm + permission_required = permissoes_materia() - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = AutoriaForm + permission_required = permissoes_materia() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() class DespachoInicialCrud(MasterDetailCrud): @@ -272,11 +310,16 @@ class DespachoInicialCrud(MasterDetailCrud): parent_field = 'materia' help_path = '' - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = DespachoInicialForm + permission_required = permissoes_materia() - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = DespachoInicialForm + permission_required = permissoes_materia() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() class LegislacaoCitadaCrud(MasterDetailCrud): @@ -292,11 +335,13 @@ class LegislacaoCitadaCrud(MasterDetailCrud): return reverse('%s:%s' % (namespace, self.url_name(suffix)), args=args) - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = LegislacaoCitadaForm + permission_required = permissoes_materia() - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = LegislacaoCitadaForm + permission_required = permissoes_materia() def get_initial(self): self.initial['tipo'] = self.object.norma.tipo.id @@ -304,6 +349,9 @@ class LegislacaoCitadaCrud(MasterDetailCrud): self.initial['ano'] = self.object.norma.ano return self.initial + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() + class DetailView(MasterDetailCrud.DetailView): @property @@ -316,11 +364,16 @@ class NumeracaoCrud(MasterDetailCrud): parent_field = 'materia' help_path = '' - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = NumeracaoForm + permission_required = permissoes_materia() - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = NumeracaoForm + permission_required = permissoes_materia() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() class AnexadaCrud(MasterDetailCrud): @@ -331,11 +384,13 @@ class AnexadaCrud(MasterDetailCrud): class BaseMixin(MasterDetailCrud.BaseMixin): list_field_names = ['materia_anexada', 'data_anexacao'] - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = AnexadaForm + permission_required = permissoes_materia() - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = AnexadaForm + permission_required = permissoes_materia() def get_initial(self): self.initial['tipo'] = self.object.materia_anexada.tipo.id @@ -350,6 +405,9 @@ class AnexadaCrud(MasterDetailCrud): def layout_key(self): return 'AnexadaDetail' + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_materia() + class MateriaLegislativaCrud(Crud): model = MateriaLegislativa @@ -358,10 +416,20 @@ class MateriaLegislativaCrud(Crud): class BaseMixin(CrudBaseMixin): list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao'] + class CreateView(PermissionRequiredMixin, CrudCreateView): + permission_required = permissoes_materia() + + class UpdateView(PermissionRequiredMixin, CrudUpdateView): + permission_required = permissoes_materia() + + class DeleteView(PermissionRequiredMixin, CrudDeleteView): + permission_required = permissoes_materia() + -class DocumentoAcessorioView(CreateView): +class DocumentoAcessorioView(PermissionRequiredMixin, CreateView): template_name = "materia/documento_acessorio.html" form_class = DocumentoAcessorioForm + permission_required = permissoes_materia() def get(self, request, *args, **kwargs): materia = MateriaLegislativa.objects.get(id=kwargs['pk']) @@ -395,7 +463,8 @@ class DocumentoAcessorioView(CreateView): return reverse('sapl.materia:documento_acessorio', kwargs={'pk': pk}) -class AcompanhamentoConfirmarView(TemplateView): +class AcompanhamentoConfirmarView(PermissionRequiredMixin, TemplateView): + permission_required = permissoes_materia() def get_redirect_url(self): return reverse('sapl.sessao:list_pauta_sessao') @@ -412,7 +481,8 @@ class AcompanhamentoConfirmarView(TemplateView): return HttpResponseRedirect(self.get_redirect_url()) -class AcompanhamentoExcluirView(TemplateView): +class AcompanhamentoExcluirView(PermissionRequiredMixin, TemplateView): + permission_required = permissoes_materia() def get_redirect_url(self): return reverse('sapl.sessao:list_pauta_sessao') @@ -496,8 +566,9 @@ class ProposicaoTaView(IntegracaoTaView): model_type_foreignkey = TipoProposicao -class AcompanhamentoMateriaView(CreateView): +class AcompanhamentoMateriaView(PermissionRequiredMixin, CreateView): template_name = "materia/acompanhamento_materia.html" + permission_required = permissoes_materia() def get_random_chars(self): s = ascii_letters + digits From 33d150bce06786e2d7383dad18a17b4a86ab24ed Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 17 Jun 2016 12:10:53 -0300 Subject: [PATCH 07/24] Faz a autoriazacao das tabelas auxiliares do modulo materia legislativa --- sapl/materia/views.py | 103 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 92 insertions(+), 11 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 80b1357cb..3e4fc8915 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -41,18 +41,7 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao, Tramitacao, UnidadeTramitacao) -OrigemCrud = Crud.build(Origem, 'origem') -TipoMateriaCrud = Crud.build(TipoMateriaLegislativa, - 'tipo_materia_legislativa') -RegimeTramitacaoCrud = Crud.build(RegimeTramitacao, 'regime_tramitacao') -TipoDocumentoCrud = Crud.build(TipoDocumento, 'tipo_documento') -TipoFimRelatoriaCrud = Crud.build(TipoFimRelatoria, 'fim_relatoria') AnexadaCrud = Crud.build(Anexada, '') -TipoAutorCrud = Crud.build(TipoAutor, 'tipo_autor') -AutorCrud = Crud.build(Autor, 'autor') -OrgaoCrud = Crud.build(Orgao, 'orgao') -TipoProposicaoCrud = Crud.build(TipoProposicao, 'tipo_proposicao') -StatusTramitacaoCrud = Crud.build(StatusTramitacao, 'status_tramitacao') def permissoes_materia(): @@ -64,6 +53,98 @@ def permissoes_materia(): return set(lista_permissoes) +class OrigemCrud(Crud): + model = Origem + help_path = 'origem' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['nome', 'sigla'] + + +class TipoMateriaCrud(Crud): + model = TipoMateriaLegislativa + help_path = 'tipo_materia_legislativa' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['sigla', 'descricao'] + + +class RegimeTramitacaoCrud(Crud): + model = RegimeTramitacao + help_path = 'regime_tramitacao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['descricao'] + + +class TipoDocumentoCrud(Crud): + model = TipoDocumento + help_path = 'tipo_documento' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['descricao'] + + +class TipoFimRelatoriaCrud(Crud): + model = TipoFimRelatoria + help_path = 'fim_relatoria' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['descricao'] + + +class TipoAutorCrud(Crud): + model = TipoAutor + help_path = 'tipo_autor' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['descricao'] + + +class AutorCrud(Crud): + model = Autor + help_path = 'autor' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['username', 'tipo', 'nome'] + + +class OrgaoCrud(Crud): + model = Orgao + help_path = 'orgao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['nome', 'sigla', 'telefone', + 'unidade_deliberativa'] + + +class TipoProposicaoCrud(Crud): + model = TipoProposicao + help_path = 'tipo_proposicao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['descricao', 'materia_ou_documento', + 'tipo_materia', 'modelo'] + + +class StatusTramitacaoCrud(Crud): + model = StatusTramitacao + help_path = 'status_tramitacao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_materia() + list_field_names = ['sigla', 'descricao', 'indicador'] + + class UnidadeTramitacaoCrud(Crud): model = UnidadeTramitacao help_path = 'unidade_tramitacao' From 609ecab2d0c7df170bd2cbb2effd9a8e3989b9af Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 17 Jun 2016 12:25:12 -0300 Subject: [PATCH 08/24] Implementa a autorizacao no app norma --- sapl/norma/views.py | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/sapl/norma/views.py b/sapl/norma/views.py index 5f7624ae6..cd00298b6 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -1,27 +1,56 @@ from datetime import datetime +from django.contrib.auth.models import Permission +from django.contrib.auth.mixins import PermissionRequiredMixin +from django.contrib.contenttypes.models import ContentType from django.shortcuts import redirect from django.views.generic import FormView, ListView from sapl.compilacao.views import IntegracaoTaView from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, - CrudUpdateView, make_pagination) + CrudDeleteView, CrudUpdateView, make_pagination) from .forms import NormaJuridicaForm, NormaJuridicaPesquisaForm from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, TipoNormaJuridica) -AssuntoNormaCrud = Crud.build(AssuntoNorma, 'assunto_norma_juridica') -TipoNormaCrud = Crud.build(TipoNormaJuridica, 'tipo_norma_juridica') LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') +def permissoes_norma(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='norma') + perms_norma = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_norma: + lista_permissoes.append('norma.' + p.codename) + return set(lista_permissoes) + + +class AssuntoNormaCrud(Crud): + model = AssuntoNorma + help_path = 'assunto_norma_juridica' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_norma() + list_field_names = ['assunto', 'descricao'] + + +class TipoNormaCrud(Crud): + model = TipoNormaJuridica + help_path = 'tipo_norma_juridica' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_norma() + list_field_names = ['equivalente_lexml', 'sigla', 'descricao'] + + class NormaCrud(Crud): model = NormaJuridica help_path = 'norma_juridica' - class UpdateView(CrudUpdateView): + class UpdateView(PermissionRequiredMixin, CrudUpdateView): form_class = NormaJuridicaForm + permission_required = permissoes_norma() @property def layout_key(self): @@ -35,13 +64,17 @@ class NormaCrud(Crud): self.initial['numero_materia'] = norma.materia.numero return self.initial.copy() - class CreateView(CrudCreateView): + class CreateView(PermissionRequiredMixin, CrudCreateView): form_class = NormaJuridicaForm + permission_required = permissoes_norma() @property def layout_key(self): return 'NormaJuridicaCreate' + class DeleteView(PermissionRequiredMixin, CrudDeleteView): + permission_required = permissoes_norma() + class BaseMixin(CrudBaseMixin): list_field_names = ['tipo', 'numero', 'ano', 'ementa'] From fc43f6164467c99f8a6306236543c42fe7286c75 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Fri, 17 Jun 2016 13:01:54 -0300 Subject: [PATCH 09/24] Faz a autorizacao das tabelas auxiliares relacionadas a parlamentares --- sapl/parlamentares/models.py | 2 +- sapl/parlamentares/views.py | 88 ++++++++++++++++++++++++++++++++---- 2 files changed, 80 insertions(+), 10 deletions(-) diff --git a/sapl/parlamentares/models.py b/sapl/parlamentares/models.py index 77c7319d4..53e42a18e 100644 --- a/sapl/parlamentares/models.py +++ b/sapl/parlamentares/models.py @@ -40,7 +40,7 @@ class SessaoLegislativa(models.Model): ('E', 'extraordinaria', _('Extraordinária')), ) - legislatura = models.ForeignKey(Legislatura) + legislatura = models.ForeignKey(Legislatura, verbose_name=Legislatura) 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 629c6f50f..1e997b9bf 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -1,11 +1,15 @@ from django.contrib import messages +from django.contrib.auth.models import Permission +from django.contrib.auth.mixins import PermissionRequiredMixin +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 from django.utils.translation import ugettext_lazy as _ from django.views.generic import FormView -from sapl.crud.base import Crud, CrudCreateView, CrudListView, CrudUpdateView +from sapl.crud.base import (Crud, CrudCreateView, CrudListView, CrudUpdateView, + CrudBaseMixin) from sapl.crud.masterdetail import MasterDetailCrud from .forms import (ComposicaoColigacaoForm, FiliacaoForm, LegislaturaForm, @@ -15,17 +19,83 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, SituacaoMilitar, TipoAfastamento, TipoDependente) -CargoMesaCrud = Crud.build(CargoMesa, 'cargo_mesa') -PartidoCrud = Crud.build(Partido, 'partidos') -SessaoLegislativaCrud = Crud.build(SessaoLegislativa, 'sessao_legislativa') -TipoDependenteCrud = Crud.build(TipoDependente, 'tipo_dependente') -NivelInstrucaoCrud = Crud.build(NivelInstrucao, 'nivel_instrucao') -TipoAfastamentoCrud = Crud.build(TipoAfastamento, 'tipo_afastamento') -TipoMilitarCrud = Crud.build(SituacaoMilitar, 'tipo_situa_militar') - DependenteCrud = MasterDetailCrud.build(Dependente, 'parlamentar', '') +def permissoes_parlamentares(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='parlamentares') + perms_parlamentares = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_parlamentares: + lista_permissoes.append('parlamentares.' + p.codename) + return set(lista_permissoes) + + +class CargoMesaCrud(Crud): + model = CargoMesa + help_path = 'cargo_mesa' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + list_field_names = ['descricao', 'unico'] + + +class PartidoCrud(Crud): + model = Partido + help_path = 'partidos' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + list_field_names = ['nome', 'sigla', 'data_criacao', 'data_extincao'] + + +class SessaoLegislativaCrud(Crud): + model = SessaoLegislativa + help_path = 'sessao_legislativa' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + list_field_names = ['numero', 'tipo', 'legislatura', 'data_inicio', + 'data_fim', 'data_inicio_intervalo', + 'data_fim_intervalo'] + + +class TipoDependenteCrud(Crud): + model = TipoDependente + help_path = 'nivel_instrucao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + list_field_names = ['descricao'] + + +class NivelInstrucaoCrud(Crud): + model = NivelInstrucao + help_path = 'tipo_dependente' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + list_field_names = ['descricao'] + + +class TipoAfastamentoCrud(Crud): + model = TipoAfastamento + help_path = 'tipo_afastamento' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + list_field_names = ['descricao', 'dispositivo', 'fim_mandato'] + + +class TipoMilitarCrud(Crud): + model = SituacaoMilitar + help_path = 'tipo_situa_militar' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + list_field_names = ['descricao'] + + class MandatoCrud(MasterDetailCrud): model = Mandato parent_field = 'parlamentar' From 8bc84ef1e60f862dd27753df0c3ab94b94b43110 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 20 Jun 2016 11:18:11 -0300 Subject: [PATCH 10/24] Finaliza a autenticacao do app parlamentares --- sapl/materia/views.py | 14 +--------- sapl/parlamentares/views.py | 53 ++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 3e4fc8915..074b28e56 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -59,7 +59,6 @@ class OrigemCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['nome', 'sigla'] class TipoMateriaCrud(Crud): @@ -68,7 +67,6 @@ class TipoMateriaCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['sigla', 'descricao'] class RegimeTramitacaoCrud(Crud): @@ -77,7 +75,6 @@ class RegimeTramitacaoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['descricao'] class TipoDocumentoCrud(Crud): @@ -86,7 +83,6 @@ class TipoDocumentoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['descricao'] class TipoFimRelatoriaCrud(Crud): @@ -95,7 +91,6 @@ class TipoFimRelatoriaCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['descricao'] class TipoAutorCrud(Crud): @@ -104,7 +99,6 @@ class TipoAutorCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['descricao'] class AutorCrud(Crud): @@ -113,7 +107,6 @@ class AutorCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['username', 'tipo', 'nome'] class OrgaoCrud(Crud): @@ -122,8 +115,6 @@ class OrgaoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['nome', 'sigla', 'telefone', - 'unidade_deliberativa'] class TipoProposicaoCrud(Crud): @@ -132,8 +123,6 @@ class TipoProposicaoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['descricao', 'materia_ou_documento', - 'tipo_materia', 'modelo'] class StatusTramitacaoCrud(Crud): @@ -142,7 +131,6 @@ class StatusTramitacaoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_materia() - list_field_names = ['sigla', 'descricao', 'indicador'] class UnidadeTramitacaoCrud(Crud): @@ -195,7 +183,7 @@ class ProposicaoCrud(Crud): return [self._as_row(obj) for obj in object_list] - class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + class DeleteView(PermissionRequiredMixin, CrudDeleteView): permission_required = permissoes_materia() def delete(self, request, *args, **kwargs): diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 1e997b9bf..b2b6b57ce 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -9,7 +9,7 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic import FormView from sapl.crud.base import (Crud, CrudCreateView, CrudListView, CrudUpdateView, - CrudBaseMixin) + CrudBaseMixin, CrudDeleteView) from sapl.crud.masterdetail import MasterDetailCrud from .forms import (ComposicaoColigacaoForm, FiliacaoForm, LegislaturaForm, @@ -37,7 +37,6 @@ class CargoMesaCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_parlamentares() - list_field_names = ['descricao', 'unico'] class PartidoCrud(Crud): @@ -46,7 +45,6 @@ class PartidoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_parlamentares() - list_field_names = ['nome', 'sigla', 'data_criacao', 'data_extincao'] class SessaoLegislativaCrud(Crud): @@ -55,9 +53,6 @@ class SessaoLegislativaCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_parlamentares() - list_field_names = ['numero', 'tipo', 'legislatura', 'data_inicio', - 'data_fim', 'data_inicio_intervalo', - 'data_fim_intervalo'] class TipoDependenteCrud(Crud): @@ -66,7 +61,6 @@ class TipoDependenteCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_parlamentares() - list_field_names = ['descricao'] class NivelInstrucaoCrud(Crud): @@ -75,7 +69,6 @@ class NivelInstrucaoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_parlamentares() - list_field_names = ['descricao'] class TipoAfastamentoCrud(Crud): @@ -84,7 +77,6 @@ class TipoAfastamentoCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_parlamentares() - list_field_names = ['descricao', 'dispositivo', 'fim_mandato'] class TipoMilitarCrud(Crud): @@ -93,7 +85,6 @@ class TipoMilitarCrud(Crud): class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): permission_required = permissoes_parlamentares() - list_field_names = ['descricao'] class MandatoCrud(MasterDetailCrud): @@ -104,6 +95,15 @@ class MandatoCrud(MasterDetailCrud): class ListView(MasterDetailCrud.ListView): ordering = ('-legislatura__data_inicio') + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): + permission_required = permissoes_parlamentares() + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): + permission_required = permissoes_parlamentares() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_parlamentares() + class ColigacaoCrud(Crud): model = Coligacao @@ -112,6 +112,9 @@ class ColigacaoCrud(Crud): class ListView(CrudListView): ordering = ('-legislatura__data_inicio', 'nome') + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + class ComposicaoColigacaoCrud(MasterDetailCrud): model = ComposicaoColigacao @@ -135,6 +138,9 @@ class ComposicaoColigacaoCrud(MasterDetailCrud): class ListView(MasterDetailCrud.ListView): ordering = '-partido__sigla' + class BaseMixin(PermissionRequiredMixin, MasterDetailCrud.BaseMixin): + permission_required = permissoes_parlamentares() + class LegislaturaCrud(Crud): model = Legislatura @@ -146,17 +152,25 @@ class LegislaturaCrud(Crud): class UpdateView(CrudUpdateView): form_class = LegislaturaForm + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_parlamentares() + class FiliacaoCrud(MasterDetailCrud): model = Filiacao parent_field = 'parlamentar' help_path = '' - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = FiliacaoForm + permission_required = permissoes_parlamentares() - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = FiliacaoForm + permission_required = permissoes_parlamentares() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_parlamentares() class ListView(MasterDetailCrud.ListView): ordering = '-data' @@ -166,16 +180,22 @@ class ParlamentarCrud(Crud): model = Parlamentar help_path = '' - class UpdateView(CrudUpdateView): + class UpdateView(PermissionRequiredMixin, CrudUpdateView): form_class = ParlamentarForm + permission_required = permissoes_parlamentares() - class CreateView(CrudCreateView): + class CreateView(PermissionRequiredMixin, CrudCreateView): form_class = ParlamentarCreateForm + permission_required = permissoes_parlamentares() @property def layout_key(self): return 'ParlamentarCreate' + class DeleteView(PermissionRequiredMixin, CrudDeleteView): + form_class = ParlamentarCreateForm + permission_required = permissoes_parlamentares() + class ListView(CrudListView): template_name = "parlamentares/parlamentares_list.html" paginate_by = None @@ -230,11 +250,12 @@ class ParlamentarCrud(Crud): return context -class MesaDiretoraView(FormView): +class MesaDiretoraView(PermissionRequiredMixin, 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) + # 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 \ From 0fe8dfa715ffae5ce897e46fdad68e2abfc8bb45 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Mon, 20 Jun 2016 12:57:44 -0300 Subject: [PATCH 11/24] Faz a autorizacao no app protocoloadm --- sapl/protocoloadm/views.py | 81 ++++++++++++++++++++++++++++++-------- 1 file changed, 64 insertions(+), 17 deletions(-) diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 3eba8b729..66d85d664 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -2,6 +2,9 @@ import json from datetime import date, datetime from braces.views import FormValidMessageMixin +from django.contrib.auth.mixins import PermissionRequiredMixin +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.db.models import Max, Q @@ -12,7 +15,8 @@ from django.views.generic import CreateView, DetailView, FormView, ListView from django.views.generic.base import TemplateView from django_filters.views import FilterView -from sapl.crud.base import Crud, CrudBaseMixin, CrudListView, make_pagination +from sapl.crud.base import (Crud, CrudBaseMixin, CrudListView, make_pagination, + CrudCreateView, CrudUpdateView, CrudDeleteView) from sapl.materia.models import Proposicao, TipoMateriaLegislativa from sapl.utils import create_barcode, get_client_ip @@ -38,6 +42,24 @@ ProtocoloMateriaCrud = Crud.build(Protocolo, '') TipoInstituicaoCrud = Crud.build(TipoInstituicao, '') +def permissoes_protocoloadm(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='protocoloadm') + perms_protocolo = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_protocolo: + lista_permissoes.append('protocoloadm.' + p.codename) + return set(lista_permissoes) + + +def permissoes_adm(): + lista_permissoes = [] + perms_adm = Permission.objects.filter( + group__name='Operador de Administração') + for p in perms_adm: + lista_permissoes.append('protocoloadm.' + p.codename) + return set(lista_permissoes) + + class StatusTramitacaoAdministrativoCrud(Crud): model = StatusTramitacaoAdministrativo help_path = '' @@ -48,11 +70,21 @@ class StatusTramitacaoAdministrativoCrud(Crud): class ListView(CrudListView): ordering = 'sigla' + class CreateView(PermissionRequiredMixin, CrudCreateView): + permission_required = permissoes_adm() + + class UpdateView(PermissionRequiredMixin, CrudUpdateView): + permission_required = permissoes_adm() + + class DeleteView(PermissionRequiredMixin, CrudDeleteView): + permission_required = permissoes_adm() + -class ProtocoloPesquisaView(FilterView): +class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView): model = Protocolo filterset_class = ProtocoloFilterSet paginate_by = 10 + permission_required = permissoes_protocoloadm() def get_filterset_kwargs(self, filterset_class): super(ProtocoloPesquisaView, @@ -108,11 +140,12 @@ class ProtocoloPesquisaView(FilterView): return self.render_to_response(context) -class ProtocoloListView(ListView): +class ProtocoloListView(PermissionRequiredMixin, ListView): template_name = 'protocoloadm/protocolo_list.html' context_object_name = 'protocolos' model = Protocolo paginate_by = 10 + permission_required = permissoes_protocoloadm() def get_queryset(self): kwargs = self.request.session['kwargs'] @@ -131,10 +164,11 @@ class ProtocoloListView(ListView): return context -class AnularProtocoloAdmView(CreateView): +class AnularProtocoloAdmView(PermissionRequiredMixin, CreateView): template_name = 'protocoloadm/anular_protocoloadm.html' form_class = AnularProcoloAdmForm form_valid_message = _('Protocolo anulado com sucesso!') + permission_required = permissoes_protocoloadm() def get_success_url(self): return reverse('sapl.protocoloadm:protocolo') @@ -157,10 +191,11 @@ class AnularProtocoloAdmView(CreateView): return redirect(self.get_success_url()) -class ProtocoloDocumentoView(FormValidMessageMixin, CreateView): +class ProtocoloDocumentoView(PermissionRequiredMixin, FormValidMessageMixin, CreateView): template_name = "protocoloadm/protocolar_documento.html" form_class = ProtocoloDocumentForm form_valid_message = _('Protocolo cadastrado com sucesso!') + permission_required = permissoes_protocoloadm() def get_success_url(self): return reverse('sapl.protocoloadm:protocolo') @@ -189,9 +224,10 @@ class ProtocoloDocumentoView(FormValidMessageMixin, CreateView): return redirect(self.get_success_url()) -class CriarDocumentoProtocolo(CreateView): +class CriarDocumentoProtocolo(PermissionRequiredMixin, CreateView): template_name = "protocoloadm/criar_documento.html" form_class = DocumentoAdministrativoForm + permission_required = permissoes_protocoloadm() def get_initial(self): numero = self.kwargs['pk'] @@ -226,9 +262,10 @@ class CriarDocumentoProtocolo(CreateView): return doc -class ProtocoloMostrarView(TemplateView): +class ProtocoloMostrarView(PermissionRequiredMixin, TemplateView): template_name = "protocoloadm/protocolo_mostrar.html" + permission_required = permissoes_protocoloadm() def get_context_data(self, **kwargs): context = super(ProtocoloMostrarView, self).get_context_data(**kwargs) @@ -239,9 +276,10 @@ class ProtocoloMostrarView(TemplateView): return context -class ComprovanteProtocoloView(TemplateView): +class ComprovanteProtocoloView(PermissionRequiredMixin, TemplateView): template_name = "protocoloadm/comprovante.html" + permission_required = permissoes_protocoloadm() def get_context_data(self, **kwargs): context = super(ComprovanteProtocoloView, self).get_context_data( @@ -267,11 +305,12 @@ class ComprovanteProtocoloView(TemplateView): return context -class ProtocoloMateriaView(CreateView): +class ProtocoloMateriaView(PermissionRequiredMixin, CreateView): template_name = "protocoloadm/protocolar_materia.html" form_class = ProtocoloMateriaForm form_valid_message = _('Matéria cadastrada com sucesso!') + permission_required = permissoes_protocoloadm() def get_success_url(self): return reverse('sapl.protocoloadm:protocolo') @@ -368,10 +407,11 @@ class ProposicaoDetailView(DetailView): return context -class PesquisarDocumentoAdministrativoView(FilterView): +class PesquisarDocumentoAdministrativoView(PermissionRequiredMixin, FilterView): model = DocumentoAdministrativo filterset_class = DocumentoAdministrativoFilterSet paginate_by = 10 + permission_required = permissoes_adm() def get_filterset_kwargs(self, filterset_class): super(PesquisarDocumentoAdministrativoView, @@ -427,8 +467,9 @@ class PesquisarDocumentoAdministrativoView(FilterView): return self.render_to_response(context) -class DetailDocumentoAdministrativo(DetailView): +class DetailDocumentoAdministrativo(PermissionRequiredMixin, DetailView): template_name = "protocoloadm/detail_doc_adm.html" + permission_required = permissoes_adm() def get(self, request, *args, **kwargs): documento = DocumentoAdministrativo.objects.get( @@ -467,8 +508,9 @@ class DetailDocumentoAdministrativo(DetailView): 'pk': self.kwargs['pk']}) -class DocumentoAcessorioAdministrativoEditView(FormView): +class DocumentoAcessorioAdministrativoEditView(PermissionRequiredMixin, FormView): template_name = "protocoloadm/documento_acessorio_administrativo_edit.html" + permission_required = permissoes_adm() def get(self, request, *args, **kwargs): doc = DocumentoAdministrativo.objects.get( @@ -514,8 +556,9 @@ class DocumentoAcessorioAdministrativoEditView(FormView): return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk}) -class DocumentoAcessorioAdministrativoView(FormView): +class DocumentoAcessorioAdministrativoView(PermissionRequiredMixin, FormView): template_name = "protocoloadm/documento_acessorio_administrativo.html" + permission_required = permissoes_adm() def get(self, request, *args, **kwargs): form = DocumentoAcessorioAdministrativoForm() @@ -553,8 +596,9 @@ class DocumentoAcessorioAdministrativoView(FormView): return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk}) -class TramitacaoAdmView(FormView): +class TramitacaoAdmView(PermissionRequiredMixin, FormView): template_name = "protocoloadm/tramitacao.html" + permission_required = permissoes_adm() def get(self, request, *args, **kwargs): @@ -567,8 +611,9 @@ class TramitacaoAdmView(FormView): 'tramitacoes': tramitacoes}) -class TramitacaoAdmIncluirView(FormView): +class TramitacaoAdmIncluirView(PermissionRequiredMixin, FormView): template_name = "protocoloadm/tramitacao_incluir.html" + permission_required = permissoes_adm() def get(self, request, *args, **kwargs): pk = kwargs['pk'] @@ -592,9 +637,10 @@ class TramitacaoAdmIncluirView(FormView): return self.form_invalid(form) -class TramitacaoAdmEditView(FormView): +class TramitacaoAdmEditView(PermissionRequiredMixin, FormView): template_name = "protocoloadm/tramitacao_edit.html" + permission_required = permissoes_adm() def get(self, request, *args, **kwargs): pk = kwargs['pk'] @@ -620,9 +666,10 @@ class TramitacaoAdmEditView(FormView): return self.form_invalid(form) -class TramitacaoAdmDeleteView(DetailView): +class TramitacaoAdmDeleteView(PermissionRequiredMixin, DetailView): template_name = "protocoloadm/tramitacao.html" + permission_required = permissoes_adm() def get(self, request, *args, **kwargs): pk = kwargs['pk'] From 72e5542c734b8b0d9a138aea0f0f2f1d2e5b3cfe Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 21 Jun 2016 12:31:28 -0300 Subject: [PATCH 12/24] Faz a autorizacao do app sessao --- sapl/comissoes/views.py | 12 +-- sapl/materia/views.py | 14 +--- sapl/norma/views.py | 12 +-- sapl/parlamentares/views.py | 13 +-- sapl/protocoloadm/views.py | 23 +---- sapl/sessao/views.py | 162 ++++++++++++++++++++++++++++++------ sapl/utils.py | 75 +++++++++++++++++ 7 files changed, 220 insertions(+), 91 deletions(-) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 86e1f2507..4772c4566 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -1,27 +1,17 @@ from django.core.urlresolvers import reverse from django.contrib.auth.mixins import PermissionRequiredMixin -from django.contrib.auth.models import Permission -from django.contrib.contenttypes.models import ContentType from django.views.generic import ListView 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 .models import (CargoComissao, Comissao, Composicao, Participacao, Periodo, TipoComissao) -def permissoes_comissoes(): - lista_permissoes = [] - cts = ContentType.objects.filter(app_label='comissoes') - perms_comissoes = list(Permission.objects.filter(content_type__in=cts)) - for p in perms_comissoes: - lista_permissoes.append('comissoes.' + p.codename) - return set(lista_permissoes) - - def pegar_url_composicao(pk): participacao = Participacao.objects.get(id=pk) comp_pk = participacao.composicao.pk diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 074b28e56..833874825 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -5,9 +5,7 @@ from string import ascii_letters, digits from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django.contrib import messages -from django.contrib.auth.models import Permission from django.contrib.auth.mixins import PermissionRequiredMixin -from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail from django.core.urlresolvers import reverse @@ -24,7 +22,8 @@ from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, 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 +from sapl.utils import (autor_label, autor_modal, get_base_url, + permissoes_materia) from .forms import (AcompanhamentoMateriaForm, AnexadaForm, AutoriaForm, DespachoInicialForm, DocumentoAcessorioForm, @@ -44,15 +43,6 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, AnexadaCrud = Crud.build(Anexada, '') -def permissoes_materia(): - lista_permissoes = [] - cts = ContentType.objects.filter(app_label='materia') - perms_materia = list(Permission.objects.filter(content_type__in=cts)) - for p in perms_materia: - lista_permissoes.append('materia.' + p.codename) - return set(lista_permissoes) - - class OrigemCrud(Crud): model = Origem help_path = 'origem' diff --git a/sapl/norma/views.py b/sapl/norma/views.py index cd00298b6..2e05b819d 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -1,14 +1,13 @@ from datetime import datetime -from django.contrib.auth.models import Permission from django.contrib.auth.mixins import PermissionRequiredMixin -from django.contrib.contenttypes.models import ContentType from django.shortcuts import redirect from django.views.generic import FormView, ListView from sapl.compilacao.views import IntegracaoTaView from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudDeleteView, CrudUpdateView, make_pagination) +from sapl.utils import permissoes_norma from .forms import NormaJuridicaForm, NormaJuridicaPesquisaForm from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, @@ -17,15 +16,6 @@ from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') -def permissoes_norma(): - lista_permissoes = [] - cts = ContentType.objects.filter(app_label='norma') - perms_norma = list(Permission.objects.filter(content_type__in=cts)) - for p in perms_norma: - lista_permissoes.append('norma.' + p.codename) - return set(lista_permissoes) - - class AssuntoNormaCrud(Crud): model = AssuntoNorma help_path = 'assunto_norma_juridica' diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index b2b6b57ce..081420ab0 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -1,7 +1,5 @@ from django.contrib import messages -from django.contrib.auth.models import Permission from django.contrib.auth.mixins import PermissionRequiredMixin -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 @@ -12,6 +10,8 @@ from sapl.crud.base import (Crud, CrudCreateView, CrudListView, CrudUpdateView, CrudBaseMixin, CrudDeleteView) from sapl.crud.masterdetail import MasterDetailCrud +from sapl.utils import permissoes_parlamentares + from .forms import (ComposicaoColigacaoForm, FiliacaoForm, LegislaturaForm, ParlamentarCreateForm, ParlamentarForm) from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, @@ -22,15 +22,6 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, DependenteCrud = MasterDetailCrud.build(Dependente, 'parlamentar', '') -def permissoes_parlamentares(): - lista_permissoes = [] - cts = ContentType.objects.filter(app_label='parlamentares') - perms_parlamentares = list(Permission.objects.filter(content_type__in=cts)) - for p in perms_parlamentares: - lista_permissoes.append('parlamentares.' + p.codename) - return set(lista_permissoes) - - class CargoMesaCrud(Crud): model = CargoMesa help_path = 'cargo_mesa' diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 66d85d664..82ecc22c2 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -3,8 +3,6 @@ from datetime import date, datetime from braces.views import FormValidMessageMixin from django.contrib.auth.mixins import PermissionRequiredMixin -from django.contrib.auth.models import Permission -from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.db.models import Max, Q @@ -18,7 +16,8 @@ from django_filters.views import FilterView from sapl.crud.base import (Crud, CrudBaseMixin, CrudListView, make_pagination, CrudCreateView, CrudUpdateView, CrudDeleteView) from sapl.materia.models import Proposicao, TipoMateriaLegislativa -from sapl.utils import create_barcode, get_client_ip +from sapl.utils import (create_barcode, get_client_ip, permissoes_protocoloadm, + permissoes_adm) from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, DocumentoAdministrativoFilterSet, @@ -42,24 +41,6 @@ ProtocoloMateriaCrud = Crud.build(Protocolo, '') TipoInstituicaoCrud = Crud.build(TipoInstituicao, '') -def permissoes_protocoloadm(): - lista_permissoes = [] - cts = ContentType.objects.filter(app_label='protocoloadm') - perms_protocolo = list(Permission.objects.filter(content_type__in=cts)) - for p in perms_protocolo: - lista_permissoes.append('protocoloadm.' + p.codename) - return set(lista_permissoes) - - -def permissoes_adm(): - lista_permissoes = [] - perms_adm = Permission.objects.filter( - group__name='Operador de Administração') - for p in perms_adm: - lista_permissoes.append('protocoloadm.' + p.codename) - return set(lista_permissoes) - - class StatusTramitacaoAdministrativoCrud(Crud): model = StatusTramitacaoAdministrativo help_path = '' diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 7cdb90d2a..5407c1268 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -2,6 +2,7 @@ from datetime import datetime from re import sub from django.contrib import messages +from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.urlresolvers import reverse from django.forms.utils import ErrorList @@ -14,14 +15,15 @@ from django_filters.views import FilterView from rest_framework import generics from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, - CrudDetailView, CrudListView, CrudUpdateView, - make_pagination) + CrudDeleteView, CrudDetailView, CrudListView, + CrudUpdateView, make_pagination) from sapl.crud.masterdetail import MasterDetailCrud from sapl.materia.models import (Autoria, DocumentoAcessorio, TipoMateriaLegislativa, Tramitacao) 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 .forms import (BancadaForm, ExpedienteForm, ExpedienteMateriaForm, ListMateriaForm, MateriaOrdemDiaForm, MesaForm, @@ -34,13 +36,8 @@ from .models import (Bancada, CargoBancada, CargoMesa, ExpedienteMateria, TipoExpediente, TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar) -TipoSessaoCrud = Crud.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') OrdemDiaCrud = Crud.build(OrdemDia, '') -TipoResultadoVotacaoCrud = Crud.build( - TipoResultadoVotacao, 'tipo_resultado_votacao') -TipoExpedienteCrud = Crud.build(TipoExpediente, 'tipo_expediente') RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') -CargoBancadaCrud = Crud.build(CargoBancada, '') def reordernar_materias_expediente(request, pk): @@ -60,8 +57,9 @@ class BancadaCrud(Crud): model = Bancada help_path = '' - class BaseMixin(CrudBaseMixin): + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): list_field_names = ['nome', 'legislatura'] + permission_required = permissoes_sessao() class ListView(CrudListView): ordering = 'legislatura' @@ -73,6 +71,38 @@ class BancadaCrud(Crud): form_class = BancadaForm +class TipoSessaoCrud(Crud): + model = TipoSessaoPlenaria + help_path = 'tipo_sessao_plenaria' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_sessao() + + +class TipoResultadoVotacaoCrud(Crud): + model = TipoResultadoVotacao + help_path = 'tipo_resultado_votacao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_sessao() + + +class TipoExpedienteCrud(Crud): + model = TipoExpediente + help_path = 'tipo_expediente' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_sessao() + + +class CargoBancadaCrud(Crud): + model = CargoBancada + help_path = '' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_sessao() + + def abrir_votacao_view(request, pk, spk): existe_votacao_aberta = ExpedienteMateria.objects.filter( sessao_plenaria_id=spk, votacao_aberta=True @@ -163,11 +193,13 @@ class ExpedienteMateriaCrud(MasterDetailCrud): obj.resultado) return [self._as_row(obj) for obj in object_list] - class CreateView(MasterDetailCrud.CreateView): + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): form_class = ExpedienteMateriaForm + permission_required = permissoes_sessao() - class UpdateView(MasterDetailCrud.UpdateView): + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): form_class = ExpedienteMateriaForm + permission_required = permissoes_sessao() def get_initial(self): self.initial['tipo_materia'] = self.object.materia.tipo.id @@ -175,6 +207,9 @@ class ExpedienteMateriaCrud(MasterDetailCrud): self.initial['ano_materia'] = self.object.materia.ano return self.initial + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_sessao() + class DetailView(MasterDetailCrud.DetailView): @property @@ -190,14 +225,41 @@ class OradorCrud(MasterDetailCrud): class ListView(MasterDetailCrud.ListView): ordering = ['numero_ordem', 'parlamentar'] + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): + permission_required = permissoes_sessao() + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): + permission_required = permissoes_sessao() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_sessao() + class OradorExpedienteCrud(OradorCrud): model = OradorExpediente + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): + permission_required = permissoes_sessao() + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): + permission_required = permissoes_sessao() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_sessao() + class OradorCrud(OradorCrud): model = Orador + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): + permission_required = permissoes_sessao() + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): + permission_required = permissoes_sessao() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_sessao() + class SessaoCrud(Crud): model = SessaoPlenaria @@ -216,6 +278,15 @@ class SessaoCrud(Crud): class ListView(CrudListView): ordering = ['-data_inicio'] + class CreateView(PermissionRequiredMixin, CrudCreateView): + permission_required = permissoes_sessao() + + class UpdateView(PermissionRequiredMixin, CrudUpdateView): + permission_required = permissoes_sessao() + + class DeleteView(PermissionRequiredMixin, CrudDeleteView): + permission_required = permissoes_sessao() + class PresencaMixin: @@ -234,10 +305,14 @@ class PresencaMixin: yield (parlamentar, False) -class PresencaView(FormMixin, PresencaMixin, SessaoCrud.DetailView): +class PresencaView(PermissionRequiredMixin, + FormMixin, + PresencaMixin, + SessaoCrud.DetailView): template_name = 'sessao/presenca.html' form_class = PresencaForm model = SessaoPlenaria + permission_required = permissoes_sessao() def post(self, request, *args, **kwargs): self.object = self.get_object() @@ -275,15 +350,18 @@ class PresencaView(FormMixin, PresencaMixin, SessaoCrud.DetailView): return reverse('sapl.sessao:presenca', kwargs={'pk': pk}) -class PainelView(TemplateView): +class PainelView(PermissionRequiredMixin, TemplateView): template_name = 'sessao/painel.html' + permission_required = permissoes_painel() -class PresencaOrdemDiaView(FormMixin, +class PresencaOrdemDiaView(PermissionRequiredMixin, + FormMixin, PresencaMixin, SessaoCrud.CrudDetailView): template_name = 'sessao/presenca_ordemdia.html' form_class = PresencaForm + permission_required = permissoes_sessao() def post(self, request, *args, **kwargs): @@ -427,9 +505,12 @@ class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): return self.get(self, request, args, kwargs) -class MateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): +class MateriaOrdemDiaView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): template_name = 'sessao/materia_ordemdia.html' form_class = MateriaOrdemDiaForm + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -491,9 +572,12 @@ class MateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class EditMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): +class EditMateriaOrdemDiaView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): template_name = 'sessao/materia_ordemdia_edit.html' form_class = MateriaOrdemDiaForm + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -602,9 +686,10 @@ class EditMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class MesaView(FormMixin, SessaoCrud.CrudDetailView): +class MesaView(PermissionRequiredMixin, FormMixin, SessaoCrud.CrudDetailView): template_name = 'sessao/mesa.html' form_class = MesaForm + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -872,9 +957,12 @@ class ResumoView(SessaoCrud.CrudDetailView): return self.render_to_response(context) -class ExpedienteView(FormMixin, SessaoCrud.CrudDetailView): +class ExpedienteView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): template_name = 'sessao/expediente.html' form_class = ExpedienteForm + permission_required = permissoes_sessao() def post(self, request, *args, **kwargs): self.object = self.get_object() @@ -936,13 +1024,16 @@ class ExpedienteView(FormMixin, SessaoCrud.CrudDetailView): return reverse('sapl.sessao:expediente', kwargs={'pk': pk}) -class VotacaoEditView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoEditView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): ''' Votação Simbólica e Secreta ''' template_name = 'sessao/votacao/votacao_edit.html' + permission_required = permissoes_sessao() def post(self, request, *args, **kwargs): @@ -1009,7 +1100,9 @@ class VotacaoEditView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class VotacaoView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): ''' Votação Simbólica e Secreta @@ -1017,6 +1110,7 @@ class VotacaoView(FormMixin, SessaoCrud.CrudDetailView): template_name = 'sessao/votacao/votacao.html' form_class = VotacaoForm + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -1128,8 +1222,11 @@ class VotacaoView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class VotacaoNominalView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoNominalView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): template_name = 'sessao/votacao/nominal.html' + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -1255,8 +1352,11 @@ class VotacaoNominalView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class VotacaoNominalEditView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoNominalEditView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): template_name = 'sessao/votacao/nominal_edit.html' + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -1332,8 +1432,11 @@ class VotacaoNominalEditView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class VotacaoNominalExpedienteView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoNominalExpedienteView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): template_name = 'sessao/votacao/nominal.html' + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -1457,8 +1560,11 @@ class VotacaoNominalExpedienteView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class VotacaoNominalExpedienteEditView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoNominalExpedienteEditView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): template_name = 'sessao/votacao/nominal_edit.html' + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -1534,7 +1640,9 @@ class VotacaoNominalExpedienteEditView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class VotacaoExpedienteView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoExpedienteView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): ''' Votação Simbólica e Secreta @@ -1542,6 +1650,7 @@ class VotacaoExpedienteView(FormMixin, SessaoCrud.CrudDetailView): template_name = 'sessao/votacao/votacao.html' form_class = VotacaoForm + permission_required = permissoes_sessao() def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -1655,7 +1764,9 @@ class VotacaoExpedienteView(FormMixin, SessaoCrud.CrudDetailView): kwargs={'pk': pk}) -class VotacaoExpedienteEditView(FormMixin, SessaoCrud.CrudDetailView): +class VotacaoExpedienteEditView(PermissionRequiredMixin, + FormMixin, + SessaoCrud.CrudDetailView): ''' Votação Simbólica e Secreta @@ -1663,6 +1774,7 @@ class VotacaoExpedienteEditView(FormMixin, SessaoCrud.CrudDetailView): template_name = 'sessao/votacao/votacao_edit.html' form_class = VotacaoEditForm + permission_required = permissoes_sessao() def get_success_url(self): pk = self.kwargs['pk'] diff --git a/sapl/utils.py b/sapl/utils.py index c4a6f8a70..2b5e20de8 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -5,6 +5,9 @@ import magic from django.apps import apps from django.conf import settings from django.contrib import admin +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType +from django.core.checks import Warning, register from django.core.exceptions import ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput @@ -218,3 +221,75 @@ def intervalos_tem_intersecao(a_inicio, a_fim, b_inicio, b_fim): maior_inicio = max(a_inicio, b_inicio) menor_fim = min(a_fim, b_fim) return maior_inicio <= menor_fim + + +def permissoes_materia(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='materia') + perms_materia = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_materia: + lista_permissoes.append('materia.' + p.codename) + return set(lista_permissoes) + + +def permissoes_comissoes(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='comissoes') + perms_comissoes = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_comissoes: + lista_permissoes.append('comissoes.' + p.codename) + return set(lista_permissoes) + + +def permissoes_norma(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='norma') + perms_norma = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_norma: + lista_permissoes.append('norma.' + p.codename) + return set(lista_permissoes) + + +def permissoes_parlamentares(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='parlamentares') + perms_parlamentares = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_parlamentares: + lista_permissoes.append('parlamentares.' + p.codename) + return set(lista_permissoes) + + +def permissoes_protocoloadm(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='protocoloadm') + perms_protocolo = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_protocolo: + lista_permissoes.append('protocoloadm.' + p.codename) + return set(lista_permissoes) + + +def permissoes_adm(): + lista_permissoes = [] + perms_adm = Permission.objects.filter( + group__name='Operador de Administração') + for p in perms_adm: + lista_permissoes.append('protocoloadm.' + p.codename) + return set(lista_permissoes) + + +def permissoes_sessao(): + lista_permissoes = [] + perms_sessao = list(Permission.objects.filter( + group__name='Operador de Sessão')) + for p in perms_sessao: + lista_permissoes.append('sessao.' + p.codename) + return set(lista_permissoes) + + +def permissoes_painel(): + lista_permissoes = [] + perms_painel = list(Permission.objects.filter( + group__name='Operador de Painel')) + for p in perms_painel: + lista_permissoes.append('painel.' + p.codename) + return set(lista_permissoes) From 076705c7c11a58b27e297a7cf48b9da7024c4f3e Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 21 Jun 2016 12:59:21 -0300 Subject: [PATCH 13/24] Faz as permissoes do app painel --- sapl/painel/views.py | 13 +++++++++++++ scripts/inicializa_grupos_autorizacoes.py | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/sapl/painel/views.py b/sapl/painel/views.py index a4baa0c2e..a54881ced 100644 --- a/sapl/painel/views.py +++ b/sapl/painel/views.py @@ -1,5 +1,6 @@ from datetime import date +from django.contrib.auth.decorators import user_passes_test from django.core.exceptions import ObjectDoesNotExist from django.http import HttpResponse, JsonResponse from django.shortcuts import render @@ -11,12 +12,18 @@ 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 CronometroPainelCrud = Crud.build(Cronometro, '') +def check_permission(user): + return user.has_perms(permissoes_painel()) + + +@user_passes_test(check_permission) def controlador_painel(request): painel_created = Painel.objects.get_or_create(data_painel=date.today()) @@ -37,23 +44,28 @@ def controlador_painel(request): return render(request, 'painel/controlador.html', context) +@user_passes_test(check_permission) def painel_view(request, pk): context = {'head_title': str(_('Painel Plenário')), 'sessao_id': pk} return render(request, 'painel/index.html', context) +@user_passes_test(check_permission) def painel_mensagem_view(request): return render(request, 'painel/mensagem.html') +@user_passes_test(check_permission) def painel_parlamentar_view(request): return render(request, 'painel/parlamentares.html') +@user_passes_test(check_permission) def painel_votacao_view(request): return render(request, 'painel/votacao.html') +@user_passes_test(check_permission) def cronometro_painel(request): request.session[request.GET['tipo']] = request.GET['action'] return HttpResponse({}) @@ -316,6 +328,7 @@ def get_votos_nominal(response, materia): return response +@user_passes_test(check_permission) def get_dados_painel(request, pk): sessao = SessaoPlenaria.objects.get(id=pk) cronometro_discurso = get_cronometro_status(request, 'discurso') diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py index 15f12fdbd..9e63db94b 100644 --- a/scripts/inicializa_grupos_autorizacoes.py +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -17,8 +17,19 @@ def cria_grupos_permissoes(): op_norma = Group.objects.get_or_create(name="Operador de Norma Jurídica") op_materia = Group.objects.get_or_create( name="Operador de Matéria Legislativa") + op_painel = Group.objects.get_or_create(name="Operador de Painel") op_autor = Group.objects.get_or_create(name="Autor") + op_geral = op_geral[0] + op_prot = op_prot[0] + op_sessao = op_sessao[0] + op_comissao = op_comissao[0] + op_adm = op_adm[0] + op_norma = op_norma[0] + op_materia = op_materia[0] + op_painel = op_painel[0] + op_autor = op_autor[0] + # Base permissao_add_cl = Permission.objects.get( @@ -76,6 +87,11 @@ def cria_grupos_permissoes(): cts = ContentType.objects.filter(app_label='sessao') perms_sessao = list(Permission.objects.filter(content_type__in=cts)) + # Painel + + cts = ContentType.objects.filter(app_label='painel') + perms_painel = list(Permission.objects.filter(content_type__in=cts)) + # Autor perms_autor = Permission.objects.get(name="Can add Proposição") @@ -104,6 +120,10 @@ def cria_grupos_permissoes(): for p in perms_materia: op_materia.permissions.add(p) + # Configura Permissoes Operador de Painel + for p in perms_painel: + op_painel.permissions.add(p) + # Configura Permissoes Autor op_autor.permissions.add(perms_autor) From bf18177f9282aa6d5e758ee7c4bc063002073057 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 21 Jun 2016 13:15:44 -0300 Subject: [PATCH 14/24] Faz o script criar tambem usuarios --- scripts/inicializa_grupos_autorizacoes.py | 35 ++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py index 9e63db94b..ec21e02bc 100644 --- a/scripts/inicializa_grupos_autorizacoes.py +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -1,4 +1,4 @@ -from django.contrib.auth.models import Group, Permission +from django.contrib.auth.models import User, Group, Permission from django.contrib.contenttypes.models import ContentType @@ -138,5 +138,38 @@ def cria_grupos_permissoes(): op_geral.permissions.add(p) op_geral.permissions.add(perms_autor) + # Cria usuarios + op_geral_user = User.objects.get_or_create(username='op_geral')[0] + op_geral_user.set_password('interlegis') + op_geral.user_set.add(op_geral_user) + + op_materia_user = User.objects.get_or_create(username='op_materia')[0] + op_materia_user.set_password('interlegis') + op_materia.user_set.add(op_materia_user) + + op_prot_user = User.objects.get_or_create(username='op_protocolo')[0] + op_prot_user.set_password('interlegis') + op_prot.user_set.add(op_prot_user) + + op_sessao_user = User.objects.get_or_create(username='op_sessao')[0] + op_sessao_user.set_password('interlegis') + op_sessao.user_set.add(op_sessao_user) + + op_comissao_user = User.objects.get_or_create(username='op_comissao')[0] + op_comissao_user.set_password('interlegis') + op_comissao.user_set.add(op_comissao_user) + + op_adm_user = User.objects.get_or_create(username='op_adm')[0] + op_adm_user.set_password('interlegis') + op_adm.user_set.add(op_adm_user) + + op_norma_user = User.objects.get_or_create(username='op_norma')[0] + op_norma_user.set_password('interlegis') + op_norma.user_set.add(op_norma_user) + + op_painel_user = User.objects.get_or_create(username='op_painel')[0] + op_painel_user.set_password('interlegis') + op_painel.user_set.add(op_norma_user) + if __name__ == '__main__': cria_grupos_permissoes() From 2b9c99fc07c52b2734c006555ecf4cb57e3216ba Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 21 Jun 2016 13:32:53 -0300 Subject: [PATCH 15/24] Cria usuario autor no script --- scripts/inicializa_grupos_autorizacoes.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/inicializa_grupos_autorizacoes.py b/scripts/inicializa_grupos_autorizacoes.py index ec21e02bc..1a8c2f7be 100644 --- a/scripts/inicializa_grupos_autorizacoes.py +++ b/scripts/inicializa_grupos_autorizacoes.py @@ -171,5 +171,9 @@ def cria_grupos_permissoes(): op_painel_user.set_password('interlegis') op_painel.user_set.add(op_norma_user) + op_autor_user = User.objects.get_or_create(username='op_autor')[0] + op_autor_user.set_password('interlegis') + op_autor.user_set.add(op_autor_user) + if __name__ == '__main__': cria_grupos_permissoes() From 71e04e8bab882327e13bcd1073d7eafdb91a2c9b Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 21 Jun 2016 13:53:44 -0300 Subject: [PATCH 16/24] Restringe botoes da tela principal --- sapl/base/urls.py | 4 ++-- sapl/base/views.py | 11 +++++++++++ sapl/parlamentares/views.py | 17 +++++++++++++++-- sapl/templates/base.html | 8 ++++++-- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 9fd6f0dcb..f619423f2 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -4,13 +4,13 @@ from django.views.generic.base import TemplateView from .apps import AppConfig from .forms import LoginForm -from .views import CasaLegislativaCrud, HelpView +from .views import CasaLegislativaCrud, HelpView, SistemaView app_name = AppConfig.name urlpatterns = [ - url(r'^sistema/', TemplateView.as_view(template_name='sistema.html')), + url(r'^sistema/', SistemaView.as_view()), url(r'^ajuda/(?P\w+)$', HelpView.as_view(), name='help_topic'), url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'), name='help_base'), diff --git a/sapl/base/views.py b/sapl/base/views.py index cbea94455..f45834d1f 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -44,3 +44,14 @@ class HelpView(PermissionRequiredMixin, TemplateView): def get_template_names(self): return ['ajuda/%s.html' % self.kwargs['topic']] + + +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 diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 081420ab0..2d24eec0e 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -19,8 +19,6 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, SituacaoMilitar, TipoAfastamento, TipoDependente) -DependenteCrud = MasterDetailCrud.build(Dependente, 'parlamentar', '') - class CargoMesaCrud(Crud): model = CargoMesa @@ -78,6 +76,21 @@ class TipoMilitarCrud(Crud): permission_required = permissoes_parlamentares() +class DependenteCrud(MasterDetailCrud): + model = Dependente + parent_field = 'parlamentar' + help_path = '' + + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): + permission_required = permissoes_parlamentares() + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): + permission_required = permissoes_parlamentares() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_parlamentares() + + class MandatoCrud(MasterDetailCrud): model = Mandato parent_field = 'parlamentar' diff --git a/sapl/templates/base.html b/sapl/templates/base.html index 8c5eafc56..276423655 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -46,13 +46,15 @@ - + {% if user.is_authenticated %} + {% endif %} - + {% if user.is_authenticated %} + {% endif %} - {% if user.is_authenticated %} + {% if user.is_superuser %} - {% if user.is_authenticated %} + {% if perms.protocoloadm %} - {% if user.is_superuser %} + {% if user|ver_menu_sistema_perm %}