feat Actualización de datos del usuario desde Identidades

parent fc512fa9
......@@ -12,6 +12,7 @@ mysqlclient = "*"
social-auth-app-django = "*"
social-auth-core = {extras = ["saml"],version = "*"}
python3-saml = "*"
cx-oracle = "*"
[requires]
python_version = "3.7"
{
"_meta": {
"hash": {
"sha256": "1016a34e3eff9effad91951bda6cc38484050da89650720ba18800ff9557daf0"
"sha256": "10726274f0df91f8bc04c1c8f18bd5e615c4cee22a69cd88f4e3d22a5e21e8c0"
},
"pipfile-spec": 6,
"requires": {
......@@ -30,6 +30,26 @@
],
"version": "==3.0.4"
},
"cx-oracle": {
"hashes": [
"sha256:17d760bdf89e364fc7c964c5640c1b38cbb22ab49b53830883f21fda92c59131",
"sha256:1c79be40c1413372062e4a09570ff25dde42111369730c81ca6dc3e5dd9857fe",
"sha256:1e7e161f9855dfa2cb29fb116d1374de966194976cd5a8d8265911b55a1ec9f9",
"sha256:2f4423eb7c652ad7c8352547054784456faed7b61d97a43fcf98f4a61fcc3095",
"sha256:4af28f3060ec26c293921e640ce49b834199ce79d41d771990520a0755d8334b",
"sha256:4ca456fb1889f8e6c34d66af455ef885d3c0390f4be2ef314a811a03d936641e",
"sha256:5895d6db9a7c70e43c48ee53e50a2a6ba647192d881e0689bba5739f9d8e1011",
"sha256:79a5b9c831033cde2bff438b9e87e628c30d160ea97f23bc1350f23af7f8607d",
"sha256:a77f0f3693acf602e59795f544982e127e819fbc6fbd3dda04748367d3883a69",
"sha256:a91f03ab85a8eb5860559c888e6abdba391a119e9bd4fb65c025f689392cc2df",
"sha256:b8e296add6386b56fc468b9e60b8981104c5ff9df1f318454c0a486c1800b3e5",
"sha256:fbbb92cd85d6c0ea91eeec1e82fa7434f8f9cc6089fc908ea9f66f2a93b2e92c",
"sha256:fda68322fe3d2ae77820170059049a0e64efdbb4ed547db96287959b12d975a5",
"sha256:ff44d60f50a03389f723bf7875e3eb8105ed4e344235908573313776af329b8b"
],
"index": "pypi",
"version": "==7.1.1"
},
"defusedxml": {
"hashes": [
"sha256:24d7f2f94f7f3cb6061acb215685e5125fbcdc40a857eff9de22518820b0a4f4",
......@@ -204,17 +224,17 @@
"develop": {
"astroid": {
"hashes": [
"sha256:1d5d0e6e408701ae657342645465d08be6fb66cf0ede16a31cc6435bd2e61718",
"sha256:8fc40235cd184bff5d7b8e1284a647005cbd36bbc87d0c39f6f6389ae26e17ad"
"sha256:39183aecc01d6f74eb54edc6739992e842f3bf3068bdfaaba30b5a1742f44091",
"sha256:62bd1d8d2ace3e812b3a22eb3c4b7856536d8cc0cdb37466f6a53cf881dbad1f"
],
"version": "==2.2.0"
"version": "==2.2.4"
},
"isort": {
"hashes": [
"sha256:ee5fddfd792e6e1d664ee28f3fbe00dfc26d8d3c6f059ee78f4da4c19718007c",
"sha256:f19b23b22fb5a919a081bc31aabcc0991614c244d9215267e11abf2ca7b684ce"
"sha256:89041186651a9a6159683098f337eed0994d9d94e006f891c6e8cbeb8e65f1c7",
"sha256:ba51a651505242b0b37ad94b281e1154301e221a40c623e62334ed863fc1c98c"
],
"version": "==4.3.9"
"version": "==4.3.12"
},
"lazy-object-proxy": {
"hashes": [
......@@ -259,11 +279,11 @@
},
"pylint": {
"hashes": [
"sha256:2bf4bd58d6d5d87174fbc9d1d134a9aeee852d4dc29cbd422a7015772770bc63",
"sha256:ee80c7af4f127b2a480d83010c9f0e97beb8eaa652b78c2837d3ed30b12e1182"
"sha256:5d77031694a5fb97ea95e828c8d10fc770a1df6eb3906067aaed42201a8a6a09",
"sha256:723e3db49555abaf9bf79dc474c6b9e2935ad82230b10c1138a71ea41ac0fff1"
],
"index": "pypi",
"version": "==2.3.0"
"version": "==2.3.1"
},
"six": {
"hashes": [
......@@ -294,7 +314,7 @@
"sha256:d659517ca116e6750101a1326107d3479028c5191f0ecee3c7203c50f5b915b0",
"sha256:eddd3fb1f3e0f82e5915a899285a39ee34ce18fd25d89582bc89fc9fb16cd2c6"
],
"markers": "python_version >= '3.7' and implementation_name == 'cpython'",
"markers": "implementation_name == 'cpython'",
"version": "==1.3.1"
},
"wrapt": {
......
import json
from django.db import connections
def dictfetchall(cursor):
"""Return all rows from a cursor as a dict."""
columns = [col[0] for col in cursor.description]
return [dict(zip(columns, row)) for row in cursor.fetchall()]
def dictfetchone(cursor):
"""Return a row from a cursor as a dict."""
columns = (col[0] for col in cursor.description)
return dict(zip(columns, cursor.fetchone()))
def get_identidad(strategy, response, user, *args, **kwargs):
"""Actualiza el modelo del usuario con los datos obtenidos de Gestión de Identidades."""
with connections["identidades"].cursor() as cursor:
cursor.execute(
"SELECT * FROM GESTIDEN.GI_V_IDENTIDAD WHERE NIP = %s", [user.username]
)
identidad = dictfetchone(cursor)
cursor.execute(
"SELECT * FROM GESTIDEN.GI_V_IDENTIDAD_PERFIL WHERE NIP = %s",
[user.username],
)
perfiles = dictfetchall(cursor)
cursor.execute(
"SELECT * FROM GESTIDEN.GI_V_IDENTIDAD_VINCULACION WHERE NIP = %s",
[user.username],
)
vinculaciones = dictfetchall(cursor)
user.first_name = identidad.get("NOMBRE")
user.last_name = identidad.get("APELLIDO_1")
user.last_name_2 = identidad.get("APELLIDO_2")
user.email = identidad.get("CORREO_PERSONAL") or identidad.get("CORREO_PRINCIPAL")
user.nombre_oficial = identidad.get("NOMBRE_ADMIN")
user.numero_documento = identidad.get("DOC_ID")
user.sexo = identidad.get("SEXO")
user.sexo_oficial = identidad.get("SEXO_ADMIN")
user.tipo_documento = identidad.get("TIPO_DOC_ID")
perfil_centro_id_nks = {
perfil.get("COD_CENTRO")
for perfil in perfiles
if perfil.get("COD_CENTRO") not in (0, None)
}
vinculacion_centro_id_nks = {
vinculacion.get("COD_CENTRO")
for vinculacion in vinculaciones
if vinculacion.get("COD_CENTRO") not in (0, None)
}
# Los objetos de tipo `set` no son serializables a JSON.
centro_id_nks = list(perfil_centro_id_nks.union(vinculacion_centro_id_nks))
user.centro_id_nks = json.dumps(centro_id_nks)
perfil_departamento_id_nks = {
perfil.get("COD_DEPARTAMENTO")
for perfil in perfiles
if perfil.get("COD_DEPARTAMENTO") not in (0, None)
}
vinculacion_departamento_id_nks = {
vinculacion.get("COD_DEPARTAMENTO")
for vinculacion in vinculaciones
if vinculacion.get("COD_DEPARTAMENTO") not in (0, None)
}
departamento_id_nks = list(
perfil_departamento_id_nks.union(vinculacion_departamento_id_nks)
)
user.departamento_id_nks = json.dumps(departamento_id_nks)
colectivos = list({perfil.get("COD_PERFIL") for perfil in perfiles})
user.colectivos = colectivos
# user.save()
strategy.storage.user.changed(user)
......@@ -92,6 +92,18 @@ DATABASES = {
"OPTIONS": {
'charset': 'utf8mb4', # Requires `innodb_default_row_format = dynamic`
}
},
"identidades": {
"ENGINE": "django.db.backends.oracle", # Database engine
"NAME": "DELFOS", # Database name
"USER": "dodona", # Database user
"PASSWORD": "PopolWuj", # Database password
"HOST": "oraculo.unizar.es", # Set to empty string for localhost.
"PORT": "1521", # Set to empty string for default.
# Additional database options
# "OPTIONS": {
# 'charset': 'WE8ISO8859P1',
# }
}
}
......@@ -130,7 +142,7 @@ STATIC_URL = "/static/"
STATICFILES_DIRS = [os.path.join(BASE_DIR, "static")]
AUTH_USER_MODEL = "accounts.CustomUser"
LOGIN_REDIRECT_URL = "home" # TODO
LOGIN_REDIRECT_URL = "userdata" # CÁMBIAME
LOGOUT_REDIRECT_URL = "home"
......@@ -178,4 +190,19 @@ SOCIAL_AUTH_SAML_ENABLED_IDPS = {
}
}
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
# 'social_core.pipeline.mail.mail_validation',
# 'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'accounts.pipeline.get_identidad', # Actualizar con los datos de Gestión de Identidades
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
SOCIAL_AUTH_URL_NAMESPACE = "social"
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