Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
89d5e857
Commit
89d5e857
authored
Feb 28, 2018
by
Lukas Burgey
Browse files
Add receivers for user (de-)activation
parent
d6c09c5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
django_backend/backend/models.py
View file @
89d5e857
...
...
@@ -246,8 +246,22 @@ class User(AbstractUser):
choices
=
TYPE_CHOICES
,
default
=
'oidcuser'
,
)
sub
=
models
.
CharField
(
max_length
=
150
,
blank
=
True
,
null
=
True
)
password
=
models
.
CharField
(
max_length
=
150
,
blank
=
True
,
null
=
True
)
sub
=
models
.
CharField
(
max_length
=
150
,
blank
=
True
,
null
=
True
,
)
password
=
models
.
CharField
(
max_length
=
150
,
blank
=
True
,
null
=
True
,
)
# the real state of the user
# (self.is_active is the supposed state of the user)
_is_active
=
models
.
BooleanField
(
default
=
True
,
editable
=
False
,
)
# we hide deleted keys here
# the full list of ssh keys is self._ssh_keys
...
...
@@ -280,12 +294,13 @@ class User(AbstractUser):
self
.
delete
()
def
activate
(
self
):
if
self
.
is_active
:
if
self
.
_
is_active
:
logger
.
error
(
self
.
msg
(
'already activated'
))
return
if
self
.
user_type
==
'oidcuser'
:
self
.
is_active
=
True
self
.
_is_active
=
True
self
.
save
()
for
dep
in
self
.
deployments
.
all
():
...
...
@@ -295,12 +310,13 @@ class User(AbstractUser):
# oidcuser: withdraw all credentials
def
deactivate
(
self
):
if
not
self
.
is_active
:
if
not
self
.
_
is_active
:
logger
.
error
(
self
.
msg
(
'already deactivated'
))
return
if
self
.
user_type
==
'oidcuser'
:
self
.
is_active
=
False
self
.
_is_active
=
False
self
.
save
()
for
dep
in
self
.
deployments
.
all
():
...
...
@@ -678,3 +694,21 @@ def deregister_at_rabbitmq(
sender
,
instance
=
None
,
**
kwargs
):
RabbitMQInstance
().
deregister_site
(
instance
)
@
receiver
(
post_save
,
sender
=
User
)
def
deactivate_user
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
created
:
return
if
not
instance
.
is_active
and
instance
.
_is_active
:
instance
.
deactivate
()
@
receiver
(
post_save
,
sender
=
User
)
def
activate_user
(
sender
,
instance
=
None
,
created
=
False
,
**
kwargs
):
if
created
:
return
if
instance
.
is_active
and
not
instance
.
_is_active
:
instance
.
activate
()
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment