Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
bookshare
Commits
c6a25855
Commit
c6a25855
authored
Jan 06, 2017
by
Daniel W Bond
Browse files
expanded cas callback to include new peoplefinder v. ldap method responses
parent
3dc4fd75
Changes
1
Hide whitespace changes
Inline
Side-by-side
bookshare/core/cas_callbacks.py
View file @
c6a25855
...
...
@@ -20,12 +20,21 @@ def pfinfo(u_name):
metadata
.
raise_for_status
()
except
requests
.
exceptions
.
RequestException
as
e
:
print
(
"Cannot resolve to peoplefinder api:"
,
e
)
return
[
''
,
''
]
return
[
''
,
''
]
# return empty response
else
:
pf_json
=
metadata
.
json
()
try
:
name
=
pf_json
[
'results'
][
0
][
'name'
]
return
name
.
split
(
','
)
if
len
(
pf_json
[
'results'
])
==
1
:
# ordinary case
if
pf_json
[
'method'
]
==
'peoplefinder'
:
name
=
pf_json
[
'results'
][
0
][
'name'
]
return
name
.
split
(
','
)
elif
pf_json
[
'method'
]
==
'ldap'
:
name
=
[
pf_json
[
'results'
][
0
][
'surname'
],
pf_json
[
'results'
][
0
][
'givenname'
]]
return
name
else
:
# handles student employees, whose employment info is listed first
name
=
pf_json
[
'results'
][
1
][
'name'
]
return
name
.
split
(
','
)
# if the name is not in peoplefinder, return empty first and last name
except
IndexError
:
return
[
''
,
''
]
...
...
@@ -49,7 +58,7 @@ def create_user(tree):
print
(
"Start peoplefinder parsing"
)
try
:
name_list
=
pfinfo
(
str
(
username
))
print
name_list
,
"name_list"
print
(
name_list
,
"name_list"
)
first_name
=
name_list
[
1
].
lstrip
().
split
(
' '
)
if
len
(
first_name
)
>
1
:
no_mi
=
first_name
[:
-
1
]
...
...
@@ -58,9 +67,9 @@ def create_user(tree):
user
.
first_name
=
' '
.
join
(
first_name
)
last_name
=
name_list
[
0
]
user
.
last_name
=
name_list
[
0
]
print
(
"Added user's name, %s %s."
%
(
user
.
first_name
,
user
.
last_name
))
except
Exception
as
e
:
print
(
"Un
handled peoplefinder exception
:"
,
e
)
print
(
"Un
able to add user's name
:"
,
e
)
user
.
save
()
print
(
"Created user %s!"
%
username
)
...
...
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