Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
manhattan
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
InnovacionDocente
manhattan
Commits
3a6a4840
Commit
3a6a4840
authored
Jun 23, 2020
by
Enrique Matías Sánchez (Quique)
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat Obtener los evaluadores de Gestión de Identidades
parent
565872cf
Pipeline
#583
failed with stage
in 0 seconds
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
9 deletions
+65
-9
models.py
accounts/models.py
+33
-0
forms.py
indo/forms.py
+6
-1
views.py
indo/views.py
+5
-3
settings-sample.py
manhattan_project/settings-sample.py
+21
-5
No files found.
accounts/models.py
View file @
3a6a4840
...
...
@@ -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
()
indo/forms.py
View file @
3a6a4840
...
...
@@ -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
:
...
...
indo/views.py
View file @
3a6a4840
...
...
@@ -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)
...
...
manhattan_project/settings-sample.py
View file @
3a6a4840
...
...
@@ -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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment