Browse Source

Adiciona permissão COADFI, COPLAF e Usuario_Habilitado

pull/6/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
committed by Luciano Almeida
parent
commit
9decb74cd8
  1. 15
      scripts/atendimento/criar_grupos.py
  2. 16
      sigi/apps/solicitacoes/views.py
  3. 18
      sigi/apps/usuarios/migrations/0011_delete_subsecretaria.py
  4. 15
      sigi/apps/usuarios/models.py
  5. 21
      sigi/apps/usuarios/views.py
  6. 1
      templates/base.html

15
scripts/atendimento/criar_grupos.py

@ -0,0 +1,15 @@
from django.contrib.auth.models import Group
def criar_grupos():
# COPLAF = Atestar usuário
if not Group.objects.filter(name='COPLAF').exists():
Group.objects.create(name='COPLAF')
# COADFI = Atestar convênio
if not Group.objects.filter(name='COADFI').exists():
Group.objects.create(name='COADFI')
# Já recebeu aprovação dos dois grupos de cima
if not Group.objects.filter(name='Usuario_Habilitado').exists():
Group.objects.create(name='Usuario_Habilitado')

16
sigi/apps/solicitacoes/views.py

@ -2,6 +2,7 @@ from __future__ import absolute_import
import random import random
from braces.views import GroupRequiredMixin
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@ -9,25 +10,34 @@ import sigi.apps.crud.base
from sigi.apps.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sigi.apps.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudListView, CrudUpdateView) CrudListView, CrudUpdateView)
from sigi.apps.usuarios.models import Usuario from sigi.apps.usuarios.models import Usuario
from sigi.context_processors import recupera_usuario
from .forms import SolicitacaoForm from .forms import SolicitacaoForm
from .models import Solicitacao from .models import Solicitacao
from sigi.context_processors import recupera_usuario
class SolicitacaoCrud(LoginRequiredMixin, Crud): class SolicitacaoCrud(LoginRequiredMixin, Crud):
model = Solicitacao model = Solicitacao
help_path = u'' help_path = u''
class ListView(LoginRequiredMixin, CrudListView): class ListView(CrudListView):
def get_rows(self, object_list): def get_rows(self, object_list):
object_list = Solicitacao.objects.filter( object_list = Solicitacao.objects.filter(
usuario=recupera_usuario(self.request)) usuario=recupera_usuario(self.request))
return [self._as_row(obj) for obj in object_list] return [self._as_row(obj) for obj in object_list]
class CreateView(LoginRequiredMixin, CrudCreateView): class UpdateView(GroupRequiredMixin, CrudUpdateView):
# TODO: Usado para ngm ter acesso
group_required = u'admin'
class CrudDeleteView(GroupRequiredMixin, CrudUpdateView):
# TODO: Usado para ngm ter acesso
group_required = u'admin'
class CreateView(GroupRequiredMixin, CrudCreateView):
form_class = SolicitacaoForm form_class = SolicitacaoForm
group_required = u'Usuario_Habilitado'
def get_initial(self): def get_initial(self):
try: try:

18
sigi/apps/usuarios/migrations/0011_delete_subsecretaria.py

@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-30 12:52
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('usuarios', '0010_auto_20160629_1448'),
]
operations = [
migrations.DeleteModel(
name='Subsecretaria',
),
]

15
sigi/apps/usuarios/models.py

@ -12,21 +12,6 @@ from sigi.apps.crud.utils import UF, YES_NO_CHOICES
from sigi.apps.utils import SearchField from sigi.apps.utils import SearchField
class Subsecretaria(models.Model):
nome = models.CharField(verbose_name=_(u'Nome'), max_length=100, null=True)
sigla = models.CharField(verbose_name=_(u'Sigla'),
max_length=10, null=True)
class Meta(object):
ordering = (u'nome', u'sigla')
verbose_name = _(u'Subsecretaria')
verbose_name_plural = _(u'Subsecretarias')
def __str__(self):
return u'[%s] %s' % (self.sigla, self.nome)
class Telefone(models.Model): class Telefone(models.Model):
TIPO_TELEFONE = [(u'FIXO', u'FIXO'), (u'CELULAR', u'CELULAR')] TIPO_TELEFONE = [(u'FIXO', u'FIXO'), (u'CELULAR', u'CELULAR')]

21
sigi/apps/usuarios/views.py

@ -2,10 +2,11 @@
from __future__ import absolute_import from __future__ import absolute_import
from braces.views import FormValidMessageMixin from braces.views import FormValidMessageMixin, GroupRequiredMixin
from django.conf import settings from django.conf import settings
from django.contrib.auth.decorators import login_required from django.contrib.auth.decorators import login_required
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import Group
from django.contrib.auth.tokens import default_token_generator from django.contrib.auth.tokens import default_token_generator
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail from django.core.mail import send_mail
@ -29,23 +30,31 @@ from .models import (AtestoConvenio, AtestoResponsavel, ConfirmaEmail, User,
Usuario) Usuario)
class ResponsavelListView(ListView): def habilitar_usuario(usuario):
grupo = Group.objects.get(name='Usuario_Habilitado')
usuario.user.groups.add(grupo)
class ResponsavelListView(GroupRequiredMixin, ListView):
template_name = u'usuarios/responsavel_list.html' template_name = u'usuarios/responsavel_list.html'
model = Usuario model = Usuario
queryset = Usuario.objects.filter(conveniado=True, responsavel=False) queryset = Usuario.objects.filter(conveniado=True, responsavel=False)
ordering = [u'nome_completo', u'casa_legislativa'] ordering = [u'nome_completo', u'casa_legislativa']
group_required = u'COPLAF'
class ConveniadoListView(ListView): class ConveniadoListView(GroupRequiredMixin, ListView):
template_name = u'usuarios/convenio_list.html' template_name = u'usuarios/convenio_list.html'
model = Usuario model = Usuario
queryset = Usuario.objects.filter(conveniado=False, responsavel=False) queryset = Usuario.objects.filter(conveniado=False, responsavel=False)
ordering = [u'casa_legislativa'] ordering = [u'casa_legislativa']
group_required = u'COADFI'
class ConveniadoView(CreateView): class ConveniadoView(GroupRequiredMixin, CreateView):
template_name = u'usuarios/convenio.html' template_name = u'usuarios/convenio.html'
form_class = ConveniadoForm form_class = ConveniadoForm
group_required = u'COADFI'
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = ConveniadoForm(request.POST) form = ConveniadoForm(request.POST)
@ -88,9 +97,10 @@ class ConveniadoView(CreateView):
return reverse(u'usuarios:convenio_list') return reverse(u'usuarios:convenio_list')
class ResponsavelView(CreateView): class ResponsavelView(GroupRequiredMixin, CreateView):
template_name = u'usuarios/responsavel.html' template_name = u'usuarios/responsavel.html'
form_class = ResponsavelForm form_class = ResponsavelForm
group_required = u'COPLAF'
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = ResponsavelForm(request.POST) form = ResponsavelForm(request.POST)
@ -107,6 +117,7 @@ class ResponsavelView(CreateView):
usuario.atesto_responsavel = atesto usuario.atesto_responsavel = atesto
usuario.responsavel = form.data['responsavel'] usuario.responsavel = form.data['responsavel']
habilitar_usuario(usuario)
usuario.save() usuario.save()
return HttpResponseRedirect(self.get_success_url()) return HttpResponseRedirect(self.get_success_url())

1
templates/base.html

@ -37,7 +37,6 @@
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
{% if user.is_authenticated %} {% if user.is_authenticated %}
<li><a href="{% url 'solicitacoes:solicitacao_list' %}">Solicitação</a></li> <li><a href="{% url 'solicitacoes:solicitacao_list' %}">Solicitação</a></li>
<li><a href="{% url 'usuarios:usuario_list' %}">Habilitar</a></li>
{% endif %} {% endif %}
</ul> </ul>
</div> </div>

Loading…
Cancel
Save