Browse Source

Mudanças no menu e na conexão LDAP

pull/11/head
Sesostris Vieira 4 years ago
parent
commit
04680d9264
  1. 34
      sigi/apps/convenios/admin.py
  2. 0
      sigi/apps/convenios/management/__init__.py
  3. 0
      sigi/apps/convenios/management/commands/__init__.py
  4. 43
      sigi/apps/convenios/management/commands/duracao_act.py
  5. 58
      sigi/apps/home/templatetags/menu_conf.yaml
  6. 106
      sigi/apps/servidores/management/commands/sync_ldap.py

34
sigi/apps/convenios/admin.py

@ -41,7 +41,8 @@ class ConvenioAdmin(BaseModelAdmin):
change_list_template = 'convenios/change_list.html'
fieldsets = (
(None,
{'fields': ('casa_legislativa', 'num_processo_sf', 'num_convenio', 'projeto', 'observacao')}
{'fields': ('casa_legislativa', 'num_processo_sf', 'num_convenio',
'projeto', 'observacao')}
),
(_(u'Datas'),
{'fields': ('data_adesao', 'data_retorno_assinatura', 'duracao',
@ -55,8 +56,9 @@ class ConvenioAdmin(BaseModelAdmin):
actions = ['adicionar_convenios']
inlines = (TramitacaoInline, AnexosInline, EquipamentoPrevistoInline)
list_display = ('num_convenio', 'casa_legislativa', 'get_uf',
'data_adesao', 'data_retorno_assinatura', 'data_pub_diario', 'data_termo_aceite',
'projeto',
'status_convenio', 'link_sigad', 'data_adesao',
'data_retorno_assinatura', 'duracao', 'data_pub_diario',
'data_termo_aceite', 'projeto',
)
list_display_links = ('num_convenio', 'casa_legislativa',)
list_filter = ('projeto', 'casa_legislativa__tipo', 'conveniada','equipada', 'casa_legislativa__municipio__uf', )
@ -72,6 +74,32 @@ class ConvenioAdmin(BaseModelAdmin):
get_uf.short_description = _(u'UF')
get_uf.admin_order_field = 'casa_legislativa__municipio__uf__sigla'
def status_convenio(self, obj):
if obj.pk is None:
return ""
status = obj.get_status()
if status in [u"Vencido", u"Desistência"]:
label = r"danger"
elif status == u"Vigente":
label = r"success"
elif status == u"Pendente":
label = r"warning"
else:
label = r"info"
return u'<p class="label label-{label}">{status}</p>'.format(label=label, status=status)
status_convenio.short_description = _(u"Status do convênio")
status_convenio.allow_tags = True
def link_sigad(self, obj):
if obj.pk is None:
return ""
return obj.get_sigad_url()
link_sigad.short_description = _("Processo no Senado")
link_sigad.allow_tags = True
def changelist_view(self, request, extra_context=None):
import re
request.GET._mutable = True

0
sigi/apps/convenios/management/__init__.py

0
sigi/apps/convenios/management/commands/__init__.py

43
sigi/apps/convenios/management/commands/duracao_act.py

@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
#
# sigi.apps.casas.management.commands.importa_gerentes
#
# Copyright (c) 2015 by Interlegis
#
# GNU General Public License (GPL)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
from django.core.management.base import BaseCommand, CommandError
from sigi.apps.convenios.models import Projeto, Convenio
class Command(BaseCommand):
help = u"""Define a duração de todos os ACT para 60 meses.
* A sigla do Projeto precisa ser ACT;
* O campo duracao precisa estar em branco.
"""
def handle(self, *args, **options):
self.stdout.write(u"Atualizando ACTs... ")
act = Projeto.objects.get(sigla='ACT')
for conv in Convenio.objects.filter(projeto=act, duracao=None):
conv.duracao = 60
conv.save()
self.stdout.write(u"\tACT {sigad} da Casa {casa} atualizado".format(
sigad=conv.num_processo_sf, casa=conv.casa_legislativa.nome
))
self.stdout.write(u"Pronto!")

58
sigi/apps/home/templatetags/menu_conf.yaml

@ -34,15 +34,15 @@ main_menu:
url: parlamentares/cargo/
- title: Tabela de partidos
url: parlamentares/partido/
- title: Diagnósticos
url: diagnosticos/diagnostico/
children:
- title: Administração
url: diagnosticos/diagnostico/
- title: Coleta de dados
url: diagnosticos/mobile/
- title: Gráficos e estatísticas
url: diagnosticos/graficos
# - title: Diagnósticos
# url: diagnosticos/diagnostico/
# children:
# - title: Administração
# url: diagnosticos/diagnostico/
# - title: Coleta de dados
# url: diagnosticos/mobile/
# - title: Gráficos e estatísticas
# url: diagnosticos/graficos
- title: Convênios
url: convenios/convenio/
children:
@ -50,21 +50,21 @@ main_menu:
url: convenios/convenio/
- title: Planos diretores
url: metas/planodiretor/
- title: Inventário
url: inventario/bem/
children:
- title: Bens
url: inventario/bem/
- title: Fornecedores
url: inventario/fornecedor/
- title: Equipamentos
url: inventario/equipamento/
- title: Fabricantes
url: inventario/fabricante/
- title: Tipos de equipamentos
url: inventario/tipoequipamento/
- title: Modelos de equipamentos
url: inventario/modeloequipamento/
# - title: Inventário
# url: inventario/bem/
# children:
# - title: Bens
# url: inventario/bem/
# - title: Fornecedores
# url: inventario/fornecedor/
# - title: Equipamentos
# url: inventario/equipamento/
# - title: Fabricantes
# url: inventario/fabricante/
# - title: Tipos de equipamentos
# url: inventario/tipoequipamento/
# - title: Modelos de equipamentos
# url: inventario/modeloequipamento/
- title: Servidores
url: servidores/servidor/?user__is_active__exact=1
children:
@ -109,8 +109,8 @@ main_menu:
url: eventos/tipoevento/
- title: Funções na equipe
url: eventos/funcao/
- title: Financeiro
url: financeiro/desembolso/
children:
- title: Desembolsos
url: financeiro/desembolso/
# - title: Financeiro
# url: financeiro/desembolso/
# children:
# - title: Desembolsos
# url: financeiro/desembolso/

106
sigi/apps/servidores/management/commands/sync_ldap.py

@ -18,26 +18,95 @@ class Command(BaseCommand):
filter = "(&(objectclass=Group))"
values = ['cn', ]
l = ldap.initialize(AUTH_LDAP_SERVER_URI)
try:
l.protocol_version = ldap.VERSION3
l.simple_bind_s(AUTH_LDAP_BIND_DN.encode('utf-8'), AUTH_LDAP_BIND_PASSWORD)
result_id = l.search(AUTH_LDAP_GROUP, ldap.SCOPE_SUBTREE, filter, values)
result_type, result_data = l.result(result_id, 1)
l.set_option(ldap.OPT_REFERRALS, 0)
l.simple_bind_s(AUTH_LDAP_BIND_DN.encode('utf-8'),
AUTH_LDAP_BIND_PASSWORD)
page_control = ldap.controls.SimplePagedResultsControl(
True,
size=1000,
cookie=''
)
result = []
pages = 0
while True:
pages += 1
response = l.search_ext(
AUTH_LDAP_GROUP,
ldap.SCOPE_SUBTREE,
filter,
values,
serverctrls=[page_control]
)
rtype, rdata, rmsgid, serverctrls = l.result3(response)
result.extend(rdata)
controls = [control for control in serverctrls
if control.controlType ==
ldap.controls.SimplePagedResultsControl.controlType]
if not controls:
raise Exception('The server ignores RFC 2696 control')
if not controls[0].cookie:
break
page_control.cookie = controls[0].cookie
# result_id = l.search(AUTH_LDAP_GROUP, ldap.SCOPE_SUBTREE, filter, values)
# result_type, result_data = l.result(result_id, 1)
finally:
l.unbind()
return result_data
return result
def get_ldap_users(self):
filter = "(&(objectclass=user))"
filter = "(&(objectclass=user)(memberof=CN=ILB,OU=Grupos,DC=senado,DC=gov,DC=br))"
values = ['sAMAccountName', 'userPrincipalName', 'givenName', 'sn', 'cn']
l = ldap.initialize(AUTH_LDAP_SERVER_URI)
try:
l.protocol_version = ldap.VERSION3
l.simple_bind_s(AUTH_LDAP_BIND_DN.encode('utf-8'), AUTH_LDAP_BIND_PASSWORD)
result_id = l.search(AUTH_LDAP_USER.encode('utf-8'), ldap.SCOPE_SUBTREE, filter, values)
result_type, result_data = l.result(result_id, 1)
l.set_option(ldap.OPT_REFERRALS, 0)
l.simple_bind_s(
AUTH_LDAP_BIND_DN.encode('utf-8'),
AUTH_LDAP_BIND_PASSWORD
)
page_control = ldap.controls.SimplePagedResultsControl(
True,
size=1000,
cookie=''
)
result = []
pages = 0
while True:
pages += 1
response = l.search_ext(
AUTH_LDAP_USER.encode('utf-8'),
ldap.SCOPE_SUBTREE,
filter,
values,
serverctrls=[page_control]
)
rtype, rdata, rmsgid, serverctrls = l.result3(response)
result.extend(rdata)
controls = [control for control in serverctrls
if control.controlType ==
ldap.controls.SimplePagedResultsControl.controlType]
if not controls:
raise Exception('The server ignores RFC 2696 control')
if not controls[0].cookie:
break
page_control.cookie = controls[0].cookie
# result_id = l.search(AUTH_LDAP_USER.encode('utf-8'), ldap.SCOPE_SUBTREE, filter, values)
# result_type, result_data = l.result(result_id, 1)
finally:
l.unbind()
return result_data
return result
def sync_groups(self):
print "Syncing groups..."
ldap_groups = self.get_ldap_groups()
print "\tFetched groups: %s" % len(ldap_groups)
for ldap_group in ldap_groups:
try:
group_name = ldap_group[1]['cn'][0]
@ -49,12 +118,13 @@ class Command(BaseCommand):
except Group.DoesNotExist:
group = Group(name=group_name)
group.save()
print "Group '%s' created." % group_name
print "\tGroup '%s' created." % group_name
print "Groups are synchronized."
def sync_users(self):
print "Syncing users..."
ldap_users = self.get_ldap_users()
print "\tFetched users: %s" % len(ldap_users)
def get_ldap_property(ldap_user, property_name, default_value=None):
value = ldap_user[1].get(property_name, None)
return value[0].decode('utf8') if value else default_value
@ -72,7 +142,7 @@ class Command(BaseCommand):
user = User.objects.get(email=email)
old_username = user.username
user.username = username
print "User with email '%s' had his/her username updated from [%s] to [%s]." % (
print "\tUser with email '%s' had his/her username updated from [%s] to [%s]." % (
email, old_username, username)
except User.DoesNotExist:
user = User.objects.create_user(
@ -81,17 +151,17 @@ class Command(BaseCommand):
last_name=last_name,
email=email,
)
print "User '%s' created." % username
print "\tUser '%s' created." % username
if not user.first_name == first_name:
user.first_name = first_name
print "User '%s' first name updated." % username
print "\tUser '%s' first name updated." % username
if not user.last_name == last_name:
user.last_name = last_name
print "User '%s' last name updated." % username
print "\tUser '%s' last name updated." % username
if not user.email == email:
user.email = email
print "User '%s' email updated." % username
print "\tUser '%s' email updated." % username
nome_completo = get_ldap_property(ldap_user, 'cn', '')
try:
@ -101,11 +171,11 @@ class Command(BaseCommand):
servidor = Servidor.objects.get(nome_completo=nome_completo)
except Servidor.DoesNotExist:
servidor = user.servidor_set.create(nome_completo=nome_completo)
print "Servidor '%s' created." % nome_completo
print "\tServidor '%s' created." % nome_completo
else:
if not servidor.nome_completo == nome_completo:
servidor.nome_completo = nome_completo
print "Full name of Servidor '%s' updated." % nome_completo
print "\tFull name of Servidor '%s' updated." % nome_completo
servidor.user = user
servidor.save()

Loading…
Cancel
Save