feat Obtener los evaluadores de Gestión de Identidades

parent 565872cf
Pipeline #583 failed with stage
in 0 seconds
......@@ -2,8 +2,13 @@
import json
# Third-party
from annoying.functions import get_config
from requests import Session
from requests.auth import HTTPBasicAuth
from requests.exceptions import ConnectionError as RequestConnectionError
from social_django.models import UserSocialAuth
from social_django.utils import load_strategy
import zeep
# Django
from django.contrib.auth.models import AbstractUser, UserManager
......@@ -120,5 +125,33 @@ class CustomUser(AbstractUser):
return usuario
@classmethod
def get_nips_vinculacion(cls, cod_vinculacion):
"""Devuelve los NIPs que tengan el código de vinculación indicado."""
wsdl = get_config('WSDL_VINCULACIONES')
session = Session()
session.auth = HTTPBasicAuth(
get_config('USER_VINCULACIONES'), get_config('PASS_VINCULACIONES')
)
try:
client = zeep.Client(wsdl=wsdl, transport=zeep.transports.Transport(session=session))
except RequestConnectionError:
raise RequestConnectionError('No fue posible conectarse al WS de Vinculaciones.')
except Exception as e:
print(e)
raise e
response = client.service.mostrarVinculaciones(cod_vinculacion)
if response.aviso:
# El WS produjo una advertencia. La mostramos y seguimos.
messages.warning(strategy.request, response.descripcionAviso)
if response.error:
# La comunicación con el WS fue correcta, pero éste devolvió un error. Finalizamos.
raise Exception(response.descripcionResultado)
return response.nipsInteger
# Custom Manager
objects = CustomUserManager()
......@@ -182,7 +182,12 @@ class EvaluadorForm(forms.ModelForm):
super().__init__(*args, **kwargs)
self.fields['evaluador'].widget.choices = tuple(
BLANK_CHOICE_DASH
+ [(u.id, u.full_name) for u in Group.objects.get(name="Evaluadores").user_set.all()]
+ [
(u.id, u.full_name)
for u in Group.objects.get(name="Evaluadores")
.user_set.order_by('first_name', 'last_name', 'last_name_2')
.all()
]
)
class Meta:
......
......@@ -293,10 +293,13 @@ class ProyectoEvaluadorUpdateView(LoginRequiredMixin, PermissionRequiredMixin, U
form_class = EvaluadorForm
def get(self, request, *args, **kwargs):
User = get_user_model()
# Obtenemos los NIPs de los usuarios con vinculación «Evaluador externo innovacion ACPUA».
nip_evaluadores = [136_040, 327_618, 329_639, 370_109] # FIXME - WS G.I.
nip_evaluadores = User.get_nips_vinculacion(60)
nip_evaluadores = [str(nip) for nip in nip_evaluadores]
# nip_evaluadores = ['136040', '327618', '329639', '370109'] # XXX - Desarrollo
# Creamos los usuarios que no existan ya en la aplicación.
User = get_user_model()
evaluadores = Group.objects.get(name='Evaluadores')
for nip in nip_evaluadores:
usuario = get_object_or_None(User, username=nip)
......@@ -307,7 +310,6 @@ class ProyectoEvaluadorUpdateView(LoginRequiredMixin, PermissionRequiredMixin, U
# Quitamos del grupo Evaluadores a los usuarios que ya no tengan esa vinculación.
for usuario in evaluadores.user_set.all():
nip_evaluadores = [str(nip) for nip in nip_evaluadores]
if usuario.username not in nip_evaluadores:
evaluadores.user_set.remove(usuario) # or usuario.groups.remove(evaluadores)
......
......@@ -24,7 +24,9 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'xk6ujnt_zj7xlnt@c&$jc9f_=u3io5e!87imbqz4)=li*$tu%w')
SECRET_KEY = os.environ.get(
'DJANGO_SECRET_KEY', 'xk6ujnt_zj7xlnt@c&$jc9f_=u3io5e!87imbqz4)=li*$tu%w'
)
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG', False) == 'True'
......@@ -118,7 +120,7 @@ DATABASES = {
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'}, # noqa: E501
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
......@@ -156,7 +158,10 @@ LOGOUT_REDIRECT_URL = 'home'
# ## SAML with Python Social Auth ## #
# https://python-social-auth.readthedocs.io/en/latest/backends/saml.html
AUTHENTICATION_BACKENDS = ('social_core.backends.saml.SAMLAuth', 'django.contrib.auth.backends.ModelBackend')
AUTHENTICATION_BACKENDS = (
'social_core.backends.saml.SAMLAuth',
'django.contrib.auth.backends.ModelBackend',
)
# When using PostgreSQL,
# it’s recommended to use the built-in JSONB field to store the extracted extra_data.
# To enable it define the setting:
......@@ -166,9 +171,16 @@ SOCIAL_AUTH_SAML_SP_ENTITY_ID = 'https://manhattan.local/accounts/metadata'
SOCIAL_AUTH_SAML_SP_PUBLIC_CERT = '''Spam, ham and eggs'''
SOCIAL_AUTH_SAML_SP_PRIVATE_KEY = '''Spam, sausages and bacon'''
SOCIAL_AUTH_SAML_ORG_INFO = {
'en-US': {'name': 'manhattan', 'displayname': 'Proyectos de Innovación Docente', 'url': 'http://manhattan.local'}
'en-US': {
'name': 'manhattan',
'displayname': 'Proyectos de Innovación Docente',
'url': 'http://manhattan.local',
}
}
SOCIAL_AUTH_SAML_TECHNICAL_CONTACT = {
'givenName': 'Quique',
'emailAddress': 'quique@manhattan.local',
}
SOCIAL_AUTH_SAML_TECHNICAL_CONTACT = {'givenName': 'Quique', 'emailAddress': 'quique@manhattan.local'}
SOCIAL_AUTH_SAML_SUPPORT_CONTACT = {
'givenName': 'Vicerrectorado de Política Académica',
'emailAddress': 'innova.docen@manhattan.local',
......@@ -347,3 +359,7 @@ X_FRAME_OPTIONS = 'SAMEORIGIN' # Required by SummernoteWidget on Django 3.x
WSDL_IDENTIDAD = os.environ.get('WSDL_IDENTIDAD')
USER_IDENTIDAD = os.environ.get('USER_IDENTIDAD')
PASS_IDENTIDAD = os.environ.get('PASS_IDENTIDAD')
WSDL_VINCULACIONES = os.environ.get('WSDL_VINCULACIONES')
USER_VINCULACIONES = os.environ.get('USER_VINCULACIONES')
PASS_VINCULACIONES = os.environ.get('PASS_VINCULACIONES')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment