Browse Source

Ref criação de grp Votante e regras de permissões

pull/907/head
LeandroRoberto 8 years ago
parent
commit
c94d01897f
  1. 30
      sapl/parlamentares/apps.py
  2. 13
      sapl/parlamentares/forms.py
  3. 19
      sapl/parlamentares/migrations/0040_auto_20170214_1709.py
  4. 4
      sapl/parlamentares/models.py
  5. 2
      sapl/rules/__init__.py
  6. 12
      sapl/rules/map_rules.py

30
sapl/parlamentares/apps.py

@ -1,38 +1,10 @@
from django import apps
from django.core.exceptions import ObjectDoesNotExist
from django.db.models.signals import post_migrate
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ObjectDoesNotExist
def criar_grupo(permission):
from django.contrib.auth.models import Group
g = Group.objects.get_or_create(name='Votante')
g[0].permissions.add(permission)
def criar_permissao(sender, **kwargs):
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
try:
content_type = ContentType.objects.get(
app_label='parlamentares',
model='Votante')
except ObjectDoesNotExist:
content_type = ContentType.objects.create(
app_label='parlamentares',
model='Votante')
p = Permission.objects.get_or_create(
name='Can Vote', codename='can_vote', content_type=content_type)
criar_grupo(p[0])
class AppConfig(apps.AppConfig):
name = 'sapl.parlamentares'
label = 'parlamentares'
verbose_name = _('Parlamentares')
def ready(self):
post_migrate.connect(criar_permissao, sender=self)

13
sapl/parlamentares/forms.py

@ -1,9 +1,9 @@
from datetime import date, timedelta
from django.contrib.auth.models import Group
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Fieldset, Layout
from django import forms
from django.contrib.auth.models import Group
from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import transaction
@ -13,6 +13,7 @@ from django.utils.translation import ugettext_lazy as _
from floppyforms.widgets import ClearableFileInput
from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.rules import SAPL_GROUP_VOTANTE
from .models import (ComposicaoColigacao, Filiacao, Frente, Legislatura,
Mandato, Parlamentar, Votante)
@ -228,10 +229,10 @@ class ComposicaoColigacaoForm(ModelForm):
class FrenteForm(ModelForm):
def __init__(self, *args, **kwargs):
super(FrenteForm, self).__init__(*args, **kwargs)
self.fields['parlamentares'].queryset = Parlamentar.objects.filter(
ativo=True).order_by('nome_completo')
self.fields['parlamentares'].label = _('Parlamentares \
super(FrenteForm, self).__init__(*args, **kwargs)
self.fields['parlamentares'].queryset = Parlamentar.objects.filter(
ativo=True).order_by('nome_completo')
self.fields['parlamentares'].label = _('Parlamentares \
(Mantenha CTRL pressionado para selecionar vários)')
class Meta:
@ -317,7 +318,7 @@ class VotanteForm(ModelForm):
u.save()
# Adiciona user ao grupo
g = Group.objects.filter(name='Votante')[0]
g = Group.objects.filter(name=SAPL_GROUP_VOTANTE)[0]
u.groups.add(g)
votante.user = u

19
sapl/parlamentares/migrations/0040_auto_20170214_1709.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-02-14 17:09
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('parlamentares', '0039_remove_votante_ip'),
]
operations = [
migrations.AlterModelOptions(
name='votante',
options={'permissions': (('can_vote', 'Can Vote'),), 'verbose_name': 'Usuário', 'verbose_name_plural': 'Usuários'},
),
]

4
sapl/parlamentares/models.py

@ -5,6 +5,7 @@ from django.db import models
from django.utils.translation import ugettext_lazy as _
from model_utils import Choices
from sapl.api import permissions
from sapl.base.models import Autor
from sapl.utils import (INDICADOR_AFASTAMENTO, UF, YES_NO_CHOICES,
SaplGenericRelation, intervalos_tem_intersecao,
@ -509,6 +510,9 @@ class Votante(models.Model):
class Meta:
verbose_name = _('Usuário')
verbose_name_plural = _('Usuários')
permissions = (
('can_vote', _('Can Vote')),
)
def __str__(self):
return self.user.username

2
sapl/rules/__init__.py

@ -28,6 +28,7 @@ SAPL_GROUP_PAINEL = _("Operador de Painel Eletrônico")
SAPL_GROUP_GERAL = _("Operador Geral")
SAPL_GROUP_AUTOR = _("Autor")
SAPL_GROUP_PARLAMENTAR = _("Parlamentar")
SAPL_GROUP_VOTANTE = _("Votante")
# TODO - funcionalidade ainda não existe mas está aqui para efeito de anotação
SAPL_GROUP_LOGIN_SOCIAL = _("Usuários com Login Social")
@ -48,6 +49,7 @@ SAPL_GROUPS = [
SAPL_GROUP_GERAL,
SAPL_GROUP_AUTOR,
SAPL_GROUP_PARLAMENTAR,
SAPL_GROUP_VOTANTE,
SAPL_GROUP_LOGIN_SOCIAL,
SAPL_GROUP_ANONYMOUS,
]

12
sapl/rules/map_rules.py

@ -13,7 +13,8 @@ from sapl.rules import (SAPL_GROUP_ADMINISTRATIVO, SAPL_GROUP_ANONYMOUS,
SAPL_GROUP_MATERIA, SAPL_GROUP_NORMA,
SAPL_GROUP_PAINEL, SAPL_GROUP_PARLAMENTAR,
SAPL_GROUP_PROTOCOLO, SAPL_GROUP_SESSAO,
RP_LIST, RP_DETAIL, RP_ADD, RP_CHANGE, RP_DELETE)
RP_LIST, RP_DETAIL, RP_ADD, RP_CHANGE, RP_DELETE,
SAPL_GROUP_VOTANTE)
from sapl.sessao import models as sessao
@ -178,6 +179,13 @@ rules_group_parlamentar = {
'rules': []
}
rules_group_votante = {
'group': SAPL_GROUP_VOTANTE,
'rules': [
(parlamentares.Votante, ['can_vote'])
]
}
rules_group_geral = {
'group': SAPL_GROUP_GERAL,
'rules': [
@ -232,6 +240,7 @@ rules_group_geral = {
(parlamentares.CargoMesa, __base__),
(parlamentares.ComposicaoMesa, __base__),
(parlamentares.Frente, __base__),
(parlamentares.Votante, __base__),
(sessao.CargoBancada, __base__),
(sessao.Bancada, __base__),
@ -305,6 +314,7 @@ rules_patterns = [
rules_group_geral,
rules_group_autor,
rules_group_parlamentar,
rules_group_votante,
rules_group_anonymous, # anotação para validação do teste de rules
rules_group_login_social # TODO não implementado

Loading…
Cancel
Save