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)