Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
test-it
test_oauth2_django
Commits
8847bdc6
Commit
8847bdc6
authored
Nov 05, 2017
by
Sharad Heft
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor the group creation process.
parent
8cda1db4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
16 deletions
+19
-16
test_oauth/backend.py
test_oauth/backend.py
+19
-16
No files found.
test_oauth/backend.py
View file @
8847bdc6
...
...
@@ -9,7 +9,6 @@ UserModel = get_user_model()
class
TESTOAuth2Backend
(
ModelBackend
):
@
transaction
.
atomic
def
authenticate
(
self
,
id
=
None
,
username
=
None
,
**
profile
):
if
id
is
None
or
username
is
None
:
return
None
...
...
@@ -19,21 +18,8 @@ class TESTOAuth2Backend(ModelBackend):
username
=
username
)
user
.
groups
.
clear
()
if
getattr
(
settings
,
'TEST_AUTH_CREATE_GROUPS'
,
False
):
for
g
in
profile
.
get
(
'groups'
,
[]):
group
,
_
=
Group
.
objects
.
get_or_create
(
id
=
g
[
'id'
],
name
=
g
[
'name'
]
)
user
.
groups
.
add
(
group
)
# Adding carveout for Server Admin group
if
g
[
'name'
]
==
"Server Admin"
:
user
.
is_staff
=
True
user
.
save
()
if
getattr
(
settings
,
'TEST_OAUTH_CREATE_GROUPS'
,
False
):
self
.
_do_create_groups
(
user
,
profile
.
get
(
'groups'
,
[]))
return
user
...
...
@@ -42,3 +28,20 @@ class TESTOAuth2Backend(ModelBackend):
return
UserModel
.
objects
.
get
(
pk
=
user_id
)
except
UserModel
.
DoesNotExist
:
return
None
@
transaction
.
atomic
def
_do_create_groups
(
self
,
user
,
groups
):
user
.
groups
.
clear
()
for
g
in
groups
:
group
,
_
=
Group
.
objects
.
get_or_create
(
id
=
g
[
'id'
],
name
=
g
[
'name'
]
)
user
.
groups
.
add
(
group
)
# Adding carveout for Server Admin group
if
g
[
'name'
]
==
"Server Admin"
:
user
.
is_staff
=
True
user
.
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