Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
greg
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
it-bott-integrasjoner
greg
Commits
15cd8ee6
Commit
15cd8ee6
authored
3 years ago
by
Andreas Ellewsen
Browse files
Options
Downloads
Plain Diff
Merge branch 'GREG-116-non-oidc-sessions' into 'master'
Greg 116 non oidc sessions See merge request
!172
parents
3806f2ca
0a8dfb13
No related branches found
No related tags found
1 merge request
!172
Greg 116 non oidc sessions
Pipeline
#101238
passed
3 years ago
Stage: venv update
Stage: tests and linting
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
gregui/api/views/userinfo.py
+58
-94
58 additions, 94 deletions
gregui/api/views/userinfo.py
with
58 additions
and
94 deletions
gregui/api/views/userinfo.py
+
58
−
94
View file @
15cd8ee6
...
...
@@ -3,13 +3,12 @@ from typing import (
Type
,
)
from
rest_framework
import
permissions
from
rest_framework.authentication
import
BaseAuthentication
,
SessionAuthentication
from
rest_framework.permissions
import
AllowAny
,
BasePermission
from
rest_framework.status
import
HTTP_403_FORBIDDEN
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
greg.models
import
Identity
,
InvitationLink
from
greg.models
import
InvitationLink
from
gregui.models
import
GregUserProfile
...
...
@@ -27,112 +26,77 @@ class UserInfoView(APIView):
def
get
(
self
,
request
,
format
=
None
):
"""
Get info about the visiting user
Get info about the visiting user
.
Works for users logged in using Feide, and those relying solely on an
invitation id.
TODO: Can this be modified into a permission class to reduce clutter?
invitation id. Pure django users, and anonymous users are denied access.
"""
user
=
request
.
user
invite_id
=
request
.
session
.
get
(
"
invite_id
"
)
# Authenticated user, allow access
if
user
.
is_authenticated
:
user_profile
=
GregUserProfile
.
objects
.
get
(
user
=
user
)
sponsor_id
=
None
person_id
=
None
if
user_profile
.
sponsor
:
sponsor_id
=
user_profile
.
sponsor
.
id
if
user_profile
.
person
:
person_id
=
user_profile
.
person
.
id
content
=
{
"
feide_id
"
:
user_profile
.
userid_feide
,
"
sponsor_id
"
:
sponsor_id
,
"
person_id
"
:
person_id
,
"
roles
"
:
[],
}
person
=
user_profile
.
person
if
person
:
passports
=
person
.
identities
.
filter
(
type
=
Identity
.
IdentityType
.
PASSPORT_NUMBER
).
first
()
person
=
None
sponsor
=
None
content
=
{
"
feide_id
"
:
None
,
"
sponsor_id
"
:
None
,
"
person_id
"
:
None
,
"
roles
"
:
[],
}
# Fetch sponsor and/or person object from profile of authenticated user
if
user
.
is_authenticated
:
try
:
user_profile
=
GregUserProfile
.
objects
.
get
(
user
=
user
)
sponsor
=
user_profile
.
sponsor
person
=
user_profile
.
person
content
.
update
(
{
"
first_name
"
:
person
.
first_name
,
"
last_name
"
:
person
.
last_name
,
"
email
"
:
person
.
private_email
and
person
.
private_email
.
value
,
"
mobile_phone
"
:
person
.
private_mobile
and
person
.
private_mobile
.
value
,
"
fnr
"
:
person
.
fnr
and
""
.
join
((
person
.
fnr
.
value
[:
-
5
],
"
*****
"
)),
"
passport
"
:
passports
and
passports
.
value
,
"
roles
"
:
[],
"
feide_id
"
:
user_profile
.
userid_feide
,
}
)
roles
=
person
.
roles
if
roles
:
content
.
update
(
{
"
roles
"
:
[
{
"
id
"
:
role
.
id
,
"
ou_nb
"
:
role
.
orgunit
.
name_nb
,
"
ou_en
"
:
role
.
orgunit
.
name_en
,
"
name_nb
"
:
role
.
type
.
name_nb
,
"
name_en
"
:
role
.
type
.
name_en
,
"
start_date
"
:
role
.
start_date
,
"
end_date
"
:
role
.
end_date
,
"
sponsor
"
:
{
"
first_name
"
:
role
.
sponsor
.
first_name
,
"
last_name
"
:
role
.
sponsor
.
last_name
,
},
}
for
role
in
roles
.
all
()
],
}
)
return
Response
(
content
)
except
GregUserProfile
.
DoesNotExist
:
return
Response
(
status
=
HTTP_403_FORBIDDEN
)
#
Invitation cookie, allow acc
es
s
#
Or fetch person info for invited gu
es
t
elif
invite_id
:
link
=
InvitationLink
.
objects
.
get
(
uuid
=
invite_id
)
invitation
=
link
.
invitation
person
=
invitation
.
role
.
person
passports
=
person
.
identities
.
filter
(
type
=
Identity
.
IdentityType
.
PASSPORT_NUMBER
).
first
()
content
=
{
"
feide_id
"
:
None
,
"
sponsor_id
"
:
None
,
"
person_id
"
:
person
.
id
,
"
first_name
"
:
person
.
first_name
,
"
last_name
"
:
person
.
last_name
,
"
email
"
:
person
.
private_email
and
person
.
private_email
.
value
,
"
mobile_phone
"
:
person
.
private_mobile
and
person
.
private_mobile
.
value
,
"
fnr
"
:
person
.
fnr
and
""
.
join
((
person
.
fnr
.
value
[:
-
5
],
"
*****
"
)),
"
passport
"
:
passports
and
passports
.
value
,
"
roles
"
:
[
{
"
id
"
:
role
.
id
,
"
ou_nb
"
:
role
.
orgunit
.
name_nb
,
"
ou_en
"
:
role
.
orgunit
.
name_en
,
"
name_nb
"
:
role
.
type
.
name_nb
,
"
name_en
"
:
role
.
type
.
name_en
,
"
start_date
"
:
role
.
start_date
,
"
end_date
"
:
role
.
end_date
,
"
sponsor
"
:
{
"
first_name
"
:
role
.
sponsor
.
first_name
,
"
last_name
"
:
role
.
sponsor
.
last_name
,
},
}
for
role
in
person
.
roles
.
all
()
],
}
return
Response
(
content
)
person
=
link
.
invitation
.
role
.
person
#
Nei
ther, deny access
#
O
ther
wise
, deny access
else
:
return
Response
(
status
=
HTTP_403_FORBIDDEN
)
# Add sponsor fields if sponsor object present
if
sponsor
:
content
.
update
({
"
sponsor_id
"
:
user_profile
.
sponsor
.
id
})
# Add person fields if person object present
if
person
:
content
.
update
(
{
"
person_id
"
:
person
.
id
,
"
first_name
"
:
person
.
first_name
,
"
last_name
"
:
person
.
last_name
,
"
email
"
:
person
.
private_email
and
person
.
private_email
.
value
,
"
mobile_phone
"
:
person
.
private_mobile
and
person
.
private_mobile
.
value
,
"
fnr
"
:
person
.
fnr
and
""
.
join
((
person
.
fnr
.
value
[:
-
5
],
"
*****
"
)),
"
passport
"
:
person
.
passport
and
person
.
passport
.
value
,
"
roles
"
:
[
{
"
id
"
:
role
.
id
,
"
ou_nb
"
:
role
.
orgunit
.
name_nb
,
"
ou_en
"
:
role
.
orgunit
.
name_en
,
"
name_nb
"
:
role
.
type
.
name_nb
,
"
name_en
"
:
role
.
type
.
name_en
,
"
start_date
"
:
role
.
start_date
,
"
end_date
"
:
role
.
end_date
,
"
sponsor
"
:
{
"
first_name
"
:
role
.
sponsor
.
first_name
,
"
last_name
"
:
role
.
sponsor
.
last_name
,
},
}
for
role
in
person
.
roles
.
all
()
],
}
)
return
Response
(
content
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment