From 7f59dcf7282367ba9a611fd1db027a1ba55931ea Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Thu, 27 Oct 2016 17:54:34 -0200 Subject: [PATCH] =?UTF-8?q?ajusta=20alg=20defin=C3=A7=C3=B5es=20de=20permi?= =?UTF-8?q?ss=C3=B5es=20em=20protocolo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0005_auto_20161027_1741.py | 19 +++++++++++++++++ sapl/protocoloadm/models.py | 3 +++ sapl/protocoloadm/views.py | 21 +++++++++++-------- sapl/rules/map_rules.py | 3 ++- sapl/utils.py | 9 ++++---- 5 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 sapl/protocoloadm/migrations/0005_auto_20161027_1741.py diff --git a/sapl/protocoloadm/migrations/0005_auto_20161027_1741.py b/sapl/protocoloadm/migrations/0005_auto_20161027_1741.py new file mode 100644 index 000000000..891ff2a5e --- /dev/null +++ b/sapl/protocoloadm/migrations/0005_auto_20161027_1741.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-10-27 17:41 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('protocoloadm', '0004_auto_20161023_1444'), + ] + + operations = [ + migrations.AlterModelOptions( + name='protocolo', + options={'permissions': (('action_anular_protocolo', 'Permissão para Anular Protocolo'),), 'verbose_name': 'Protocolo', 'verbose_name_plural': 'Protocolos'}, + ), + ] diff --git a/sapl/protocoloadm/models.py b/sapl/protocoloadm/models.py index 16fa8462d..963ae4ae8 100644 --- a/sapl/protocoloadm/models.py +++ b/sapl/protocoloadm/models.py @@ -153,6 +153,9 @@ class Protocolo(models.Model): class Meta: verbose_name = _('Protocolo') verbose_name_plural = _('Protocolos') + permissions = ( + ('action_anular_protocolo', _('Permissão para Anular Protocolo')), + ) class StatusTramitacaoAdministrativo(models.Model): diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 8a52c1e38..1091c7785 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -12,12 +12,12 @@ from django.views.generic import CreateView, DetailView, FormView, ListView from django.views.generic.base import TemplateView from django_filters.views import FilterView -from sapl.base.apps import AppConfig as AppsAppConfig -from sapl.base.models import AppConfig from sapl.crud.base import Crud, CrudAux, MasterDetailCrud, make_pagination from sapl.materia.models import TipoMateriaLegislativa +from sapl.protocoloadm.apps import AppConfig from sapl.utils import (create_barcode, get_client_ip, permissoes_adm, - permissoes_protocoloadm) + permissoes_protocoloadm, permission_required_for_app) +import sapl from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, DocumentoAdministrativoFilterSet, @@ -28,6 +28,7 @@ from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, StatusTramitacaoAdministrativo, TipoDocumentoAdministrativo, TramitacaoAdministrativo) + TipoDocumentoAdministrativoCrud = CrudAux.build( TipoDocumentoAdministrativo, '') @@ -44,11 +45,11 @@ DocumentoAcessorioAdministrativoCrud = Crud.build( class DocumentoAdministrativoMixin: def has_permission(self): - app_config = AppConfig.objects.last() + app_config = sapl.base.models.AppConfig.objects.last() if app_config and app_config.documentos_administrativos == 'O': return True - return self.request.user.has_module_perms(AppsAppConfig.label) + return self.request.user.has_module_perms(sapl.base.models.AppConfig.label) class DocumentoAdministrativoCrud(Crud): @@ -82,7 +83,7 @@ class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView): model = Protocolo filterset_class = ProtocoloFilterSet paginate_by = 10 - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.list_protocolo',) def get_filterset_kwargs(self, filterset_class): super(ProtocoloPesquisaView, @@ -143,7 +144,7 @@ class ProtocoloListView(PermissionRequiredMixin, ListView): context_object_name = 'protocolos' model = Protocolo paginate_by = 10 - permission_required = permissoes_protocoloadm() + permission_required = ('protocoloadm.list_protocolo',) def get_queryset(self): kwargs = self.request.session['kwargs'] @@ -204,7 +205,8 @@ class ProtocoloDocumentoView(PermissionRequiredMixin, f = form.save(commit=False) try: - numeracao = AppConfig.objects.last().sequencia_numeracao + numeracao = sapl.base.models.AppConfig.objects.last( + ).sequencia_numeracao except AttributeError: msg = _('É preciso definir a sequencia de ' + 'numeração na tabelas auxiliares!') @@ -326,7 +328,8 @@ class ProtocoloMateriaView(PermissionRequiredMixin, CreateView): def form_valid(self, form): try: - numeracao = AppConfig.objects.last().sequencia_numeracao + numeracao = sapl.base.models.AppConfig.objects.last( + ).sequencia_numeracao except AttributeError: msg = _('É preciso definir a sequencia de ' + 'numeração na tabelas auxiliares!') diff --git a/sapl/rules/map_rules.py b/sapl/rules/map_rules.py index 2f927defa..981646d08 100644 --- a/sapl/rules/map_rules.py +++ b/sapl/rules/map_rules.py @@ -36,7 +36,8 @@ rules_group_administrativo = { rules_group_protocolo = { 'group': SAPL_GROUP_PROTOCOLO, 'rules': [ - (protocoloadm.Protocolo, __base__), + (protocoloadm.Protocolo, __base__ + [ + 'action_anular_protocolo']), (protocoloadm.DocumentoAdministrativo, __listdetailchange__), (protocoloadm.DocumentoAcessorioAdministrativo, __listdetailchange__), diff --git a/sapl/utils.py b/sapl/utils.py index 573dffb46..86dd66169 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,14 +1,12 @@ -import hashlib -import logging from datetime import date from functools import wraps from unicodedata import normalize as unicodedata_normalize - import hashlib +import hashlib +import logging import logging import re -import magic from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button from django import forms @@ -23,12 +21,13 @@ from django.contrib.contenttypes.models import ContentType from django.core.exceptions import PermissionDenied, ValidationError from django.utils.translation import ugettext_lazy as _ from floppyforms import ClearableFileInput - +import magic import magic from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.settings import BASE_DIR + sapl_logger = logging.getLogger(BASE_DIR.name)