Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
test_oauth2_django
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
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