diff --git a/scripts/atendimento/criar_grupos.py b/scripts/atendimento/criar_grupos.py new file mode 100644 index 0000000..e870269 --- /dev/null +++ b/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') diff --git a/sigi/apps/solicitacoes/views.py b/sigi/apps/solicitacoes/views.py index afebd16..6dae6d0 100644 --- a/sigi/apps/solicitacoes/views.py +++ b/sigi/apps/solicitacoes/views.py @@ -2,6 +2,7 @@ from __future__ import absolute_import import random +from braces.views import GroupRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin from django.core.urlresolvers import reverse @@ -9,25 +10,34 @@ import sigi.apps.crud.base from sigi.apps.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudListView, CrudUpdateView) from sigi.apps.usuarios.models import Usuario +from sigi.context_processors import recupera_usuario from .forms import SolicitacaoForm from .models import Solicitacao -from sigi.context_processors import recupera_usuario class SolicitacaoCrud(LoginRequiredMixin, Crud): model = Solicitacao help_path = u'' - class ListView(LoginRequiredMixin, CrudListView): + class ListView(CrudListView): def get_rows(self, object_list): object_list = Solicitacao.objects.filter( usuario=recupera_usuario(self.request)) 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 + group_required = u'Usuario_Habilitado' def get_initial(self): try: diff --git a/sigi/apps/usuarios/migrations/0011_delete_subsecretaria.py b/sigi/apps/usuarios/migrations/0011_delete_subsecretaria.py new file mode 100644 index 0000000..a2c1bdd --- /dev/null +++ b/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', + ), + ] diff --git a/sigi/apps/usuarios/models.py b/sigi/apps/usuarios/models.py index 95c0723..589b460 100644 --- a/sigi/apps/usuarios/models.py +++ b/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 -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): TIPO_TELEFONE = [(u'FIXO', u'FIXO'), (u'CELULAR', u'CELULAR')] diff --git a/sigi/apps/usuarios/views.py b/sigi/apps/usuarios/views.py index a0bd74c..2d67804 100644 --- a/sigi/apps/usuarios/views.py +++ b/sigi/apps/usuarios/views.py @@ -2,10 +2,11 @@ from __future__ import absolute_import -from braces.views import FormValidMessageMixin +from braces.views import FormValidMessageMixin, GroupRequiredMixin from django.conf import settings from django.contrib.auth.decorators import login_required 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.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail @@ -29,23 +30,31 @@ from .models import (AtestoConvenio, AtestoResponsavel, ConfirmaEmail, User, 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' model = Usuario queryset = Usuario.objects.filter(conveniado=True, responsavel=False) 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' model = Usuario queryset = Usuario.objects.filter(conveniado=False, responsavel=False) ordering = [u'casa_legislativa'] + group_required = u'COADFI' -class ConveniadoView(CreateView): +class ConveniadoView(GroupRequiredMixin, CreateView): template_name = u'usuarios/convenio.html' form_class = ConveniadoForm + group_required = u'COADFI' def post(self, request, *args, **kwargs): form = ConveniadoForm(request.POST) @@ -88,9 +97,10 @@ class ConveniadoView(CreateView): return reverse(u'usuarios:convenio_list') -class ResponsavelView(CreateView): +class ResponsavelView(GroupRequiredMixin, CreateView): template_name = u'usuarios/responsavel.html' form_class = ResponsavelForm + group_required = u'COPLAF' def post(self, request, *args, **kwargs): form = ResponsavelForm(request.POST) @@ -107,6 +117,7 @@ class ResponsavelView(CreateView): usuario.atesto_responsavel = atesto usuario.responsavel = form.data['responsavel'] + habilitar_usuario(usuario) usuario.save() return HttpResponseRedirect(self.get_success_url()) diff --git a/templates/base.html b/templates/base.html index 7c5d503..8df5d7e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -37,7 +37,6 @@