Skip to content
Snippets Groups Projects
Verified Commit b36d0cb5 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Make userinfo work if user has no person info

Before this commit, the userinfo endpoint would fail if the user
did not have a person object connected to their GregUserProfile. We now
check that this is the case before checking the person objects roles.
parent acb8bc92
No related branches found
No related tags found
1 merge request!95Make userinfo work if user has no person info
Pipeline #96041 passed
......@@ -52,7 +52,6 @@ class UserInfoView(APIView):
"person_id": person_id,
}
person = user_profile.person
roles = person.roles
if person:
content.update(
{
......@@ -62,27 +61,28 @@ class UserInfoView(APIView):
"mobile_phone": person.mobile_phone,
}
)
if roles:
content.update(
{
"roles": [
{
"ou_name_nb": role.orgunit_id.name_nb,
"ou_name_en": role.orgunit_id.name_en,
"role_name_nb": role.type.name_nb,
"role_name_en": role.type.name_en,
"start": role.start_date,
"end": role.end_date,
"comments": role.comments,
"sponsor": {
"first_name": role.sponsor_id.first_name,
"last_name": role.sponsor_id.last_name,
},
}
for role in roles.all()
],
}
)
roles = person.roles
if roles:
content.update(
{
"roles": [
{
"ou_name_nb": role.orgunit_id.name_nb,
"ou_name_en": role.orgunit_id.name_en,
"role_name_nb": role.type.name_nb,
"role_name_en": role.type.name_en,
"start": role.start_date,
"end": role.end_date,
"comments": role.comments,
"sponsor": {
"first_name": role.sponsor_id.first_name,
"last_name": role.sponsor_id.last_name,
},
}
for role in roles.all()
],
}
)
return Response(content)
# Invitation cookie, allow access
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment