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
test-it
test_oauth2_django
Commits
cb5de71b
Commit
cb5de71b
authored
Nov 05, 2017
by
Sharad Heft
Browse files
Optionally create characters associated with auth.
parent
af5578e3
Changes
1
Hide whitespace changes
Inline
Side-by-side
test_oauth/backend.py
View file @
cb5de71b
...
...
@@ -27,7 +27,17 @@ class TESTOAuth2Backend(ModelBackend):
)
if
getattr
(
settings
,
'TEST_OAUTH_CREATE_GROUPS'
,
False
):
self
.
_do_create_groups
(
user
,
profile
.
get
(
'groups'
,
[]))
self
.
_do_create_groups
(
user
,
profile
.
get
(
'groups'
,
[])
)
if
getattr
(
settings
,
'TEST_OAUTH_CREATE_CHARACTERS'
,
False
):
self
.
_do_create_characters
(
user
,
profile
.
get
(
'characters'
,
[]),
profile
.
get
(
'primary_character'
,
None
),
)
return
user
...
...
@@ -55,3 +65,23 @@ class TESTOAuth2Backend(ModelBackend):
user
.
is_staff
=
True
user
.
save
()
@
transaction
.
atomic
def
_do_create_characters
(
self
,
user
,
characters
,
primary
):
user
.
auth
.
characters
.
clear
()
user
.
auth
.
primary_character
=
None
for
c
in
characters
:
character
,
_
=
Group
.
objects
.
update_or_create
(
id
=
c
[
'id'
],
defaults
=
{
'name'
:
c
[
'name'
],
'alliance_id'
:
c
[
'alliance'
][
'id'
],
'corporation_id'
:
c
[
'corporation'
][
'id'
]
}
)
user
.
auth
.
characters
.
add
(
character
)
user
.
auth
.
primary_character_id
=
primary
[
'id'
]
user
.
auth
.
save
()
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