Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
iric-data
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
bioinfo_iric
iric-data
Commits
8ac03362
Commit
8ac03362
authored
2 years ago
by
Eric
Browse files
Options
Downloads
Plain Diff
Merge branch '152-lab-association-not-done-when-logging-in-with-token' into 'master'
Resolve "lab association not done when logging in with token" Closes
#152
See merge request
!80
parents
c3d798f1
141c5bc9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!80
Resolve "lab association not done when logging in with token"
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
portal/apps.py
+1
-1
1 addition, 1 deletion
portal/apps.py
portal/listeners.py
+28
-0
28 additions, 0 deletions
portal/listeners.py
portal/views/secure/login_success.py
+0
-26
0 additions, 26 deletions
portal/views/secure/login_success.py
with
29 additions
and
27 deletions
portal/apps.py
+
1
−
1
View file @
8ac03362
...
...
@@ -7,5 +7,5 @@ class PortalConfig(AppConfig):
def
ready
(
self
):
from
.listeners
import
(
create_external_user_profile
,
create_user_profile
,
create_lab_group
,
delete_lab_group
create_lab_group
,
delete_lab_group
,
user_login
)
This diff is collapsed.
Click to expand it.
portal/listeners.py
+
28
−
0
View file @
8ac03362
from
django.contrib.auth.models
import
User
,
Group
from
django.db.models.signals
import
post_save
,
post_delete
from
django.contrib.auth.signals
import
user_logged_in
from
django.dispatch
import
receiver
from
django_auth_ldap.backend
import
LDAPBackend
,
populate_user
from
.models
import
Profile
,
Lab
@receiver
(
user_logged_in
)
def
user_login
(
sender
,
user
,
**
kwargs
):
"""
User logged in (any method)
Update user association with IRIC labs. External lab associations are to be managed manually.
"""
azuread_data
=
{}
try
:
azuread_data
=
user
.
social_auth
.
get
(
provider
=
'
azuread-tenant-oauth2
'
).
extra_data
except
:
pass
azuread_groups
=
azuread_data
[
'
groups
'
]
if
'
groups
'
in
azuread_data
else
None
azuread_samaccountname
=
azuread_data
[
'
onPremisesSamAccountName
'
]
if
'
onPremisesSamAccountName
'
in
azuread_data
else
None
if
azuread_samaccountname
and
not
user
.
profile
.
accountname
:
user
.
profile
.
accountname
=
azuread_samaccountname
if
hasattr
(
user
,
'
ldapuser
'
)
or
azuread_groups
:
user
.
profile
.
labs
.
remove
(
*
Lab
.
objects
.
filter
(
ldap__startswith
=
'
iric-
'
))
if
hasattr
(
user
,
'
ldapuser
'
):
user
.
profile
.
labs
.
add
(
*
Lab
.
objects
.
filter
(
ldap__in
=
user
.
ldap_user
.
group_names
))
elif
azuread_groups
:
user
.
profile
.
labs
.
add
(
*
Lab
.
objects
.
filter
(
ldap__in
=
azuread_groups
))
user
.
profile
.
save
()
@receiver
(
populate_user
,
sender
=
LDAPBackend
)
def
create_user_profile
(
sender
,
user
,
ldap_user
=
None
,
**
kwargs
):
...
...
This diff is collapsed.
Click to expand it.
portal/views/secure/login_success.py
+
0
−
26
View file @
8ac03362
...
...
@@ -8,34 +8,8 @@ from ...models import Lab
class
LoginSuccess
(
View
):
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
"""
Update user association with IRIC labs and redirect to appropriate dashboard
External lab associations are to be managed manually
"""
user
=
self
.
request
.
user
if
user
.
is_anonymous
:
return
redirect
(
'
login
'
)
azuread_data
=
{}
try
:
azuread_data
=
user
.
social_auth
.
get
(
provider
=
'
azuread-tenant-oauth2
'
).
extra_data
except
:
pass
azuread_groups
=
azuread_data
[
'
groups
'
]
if
'
groups
'
in
azuread_data
else
None
azuread_samaccountname
=
azuread_data
[
'
onPremisesSamAccountName
'
]
if
'
onPremisesSamAccountName
'
in
azuread_data
else
None
if
azuread_samaccountname
and
not
user
.
profile
.
accountname
:
user
.
profile
.
accountname
=
azuread_samaccountname
if
hasattr
(
user
,
'
ldapuser
'
)
or
azuread_groups
:
user
.
profile
.
labs
.
remove
(
*
Lab
.
objects
.
filter
(
ldap__startswith
=
'
iric-
'
))
if
hasattr
(
user
,
'
ldapuser
'
):
user
.
profile
.
labs
.
add
(
*
Lab
.
objects
.
filter
(
ldap__in
=
user
.
ldap_user
.
group_names
))
elif
azuread_groups
:
user
.
profile
.
labs
.
add
(
*
Lab
.
objects
.
filter
(
ldap__in
=
azuread_groups
))
if
self
.
request
.
user
.
is_staff
:
# user is an admin
request
.
session
[
'
active_lab_id
'
]
=
Lab
.
objects
.
get
(
ldap
=
settings
.
AUTH_LDAP_STAFF_GROUP
.
split
(
'
,
'
)[
0
][
3
:]).
id
...
...
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