Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
feudal
feudalBackend
Commits
1d8eac79
Commit
1d8eac79
authored
Apr 19, 2018
by
Lukas Burgey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enhance user admin
parent
c2d1f0e5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
3 deletions
+35
-3
django_backend/backend/admin.py
django_backend/backend/admin.py
+19
-1
django_backend/backend/models.py
django_backend/backend/models.py
+16
-2
No files found.
django_backend/backend/admin.py
View file @
1d8eac79
from
django.contrib
import
admin
from
django.contrib.auth.admin
import
UserAdmin
from
.
import
models
from
.auth.v1.models
import
OIDCConfig
admin
.
site
.
register
(
models
.
User
)
class
TypeFilter
(
admin
.
SimpleListFilter
):
title
=
'Type'
parameter_name
=
'user_type'
def
lookups
(
self
,
request
,
model_admin
):
return
models
.
User
.
TYPE_CHOICES
def
queryset
(
self
,
request
,
queryset
):
if
self
.
value
():
return
queryset
.
filter
(
user_type
=
self
.
value
())
return
queryset
class
ClientAdmin
(
UserAdmin
):
list_filter
=
(
TypeFilter
,)
admin
.
site
.
register
(
models
.
User
,
ClientAdmin
)
admin
.
site
.
register
(
models
.
Site
)
admin
.
site
.
register
(
models
.
Service
)
admin
.
site
.
register
(
models
.
RabbitMQInstance
)
...
...
django_backend/backend/models.py
View file @
1d8eac79
...
...
@@ -142,7 +142,7 @@ class User(AbstractUser):
user_type
=
models
.
CharField
(
max_length
=
20
,
choices
=
TYPE_CHOICES
,
default
=
'
oidcuser
'
,
default
=
'
apiclient
'
,
)
sub
=
models
.
CharField
(
max_length
=
150
,
...
...
@@ -262,6 +262,16 @@ class User(AbstractUser):
userinfo
=
user_info
,
)
@
classmethod
def
construct_client
(
cls
,
username
,
password
):
LOGGER
.
debug
(
'APICLIENT: new client %s'
,
username
)
client
=
cls
(
username
=
username
,
user_type
=
'apiclient'
,
)
client
.
set_password
(
password
)
return
client
class
Site
(
models
.
Model
):
client
=
models
.
OneToOneField
(
...
...
@@ -622,7 +632,11 @@ class DeploymentTaskItem(models.Model):
@
receiver
(
post_save
,
sender
=
User
)
def
upgrade_password
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
created
and
instance
is
not
None
and
instance
.
user_type
==
'apiclient'
:
if
(
instance
is
not
None
and
instance
.
user_type
==
'apiclient'
and
not
instance
.
password
.
startswith
(
'pbkdf2_sha256'
)
):
instance
.
set_password
(
instance
.
password
)
instance
.
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