use taskresults app and delete_ldap_group task
This commit is contained in:
parent
a336af46c2
commit
6bf65bba3b
3 changed files with 32 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
"""
|
"""
|
||||||
This module contains the :py:class:`django.apps.AppConfig` instance for the
|
This module contains the :py:class:`django.apps.AppConfig` instance for the
|
||||||
:py:module:`osusers` app.
|
:py:mod:`osusers` app.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
|
@ -20,13 +20,15 @@ from model_utils.models import TimeStampedModel
|
||||||
from passlib.hash import sha512_crypt
|
from passlib.hash import sha512_crypt
|
||||||
from passlib.utils import generate_password
|
from passlib.utils import generate_password
|
||||||
|
|
||||||
|
from taskresults.models import TaskResult
|
||||||
|
|
||||||
from .tasks import (
|
from .tasks import (
|
||||||
add_ldap_user_to_group,
|
add_ldap_user_to_group,
|
||||||
create_ldap_group,
|
create_ldap_group,
|
||||||
create_ldap_user,
|
create_ldap_user,
|
||||||
delete_file_mail_userdir,
|
delete_file_mail_userdir,
|
||||||
delete_file_sftp_userdir,
|
delete_file_sftp_userdir,
|
||||||
delete_ldap_group_if_empty,
|
delete_ldap_group,
|
||||||
delete_ldap_user,
|
delete_ldap_user,
|
||||||
remove_ldap_user_from_group,
|
remove_ldap_user_from_group,
|
||||||
setup_file_mail_userdir,
|
setup_file_mail_userdir,
|
||||||
|
@ -115,7 +117,10 @@ class Group(TimeStampedModel, models.Model):
|
||||||
:py:meth:`django.db.Model.delete`
|
:py:meth:`django.db.Model.delete`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
delete_ldap_group_if_empty.delay(self.groupname).get()
|
TaskResult.objects.create_task_result(
|
||||||
|
delete_ldap_group.delay(self.groupname),
|
||||||
|
'delete_ldap_group'
|
||||||
|
)
|
||||||
super(Group, self).delete(*args, **kwargs)
|
super(Group, self).delete(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,13 +269,18 @@ class User(TimeStampedModel, models.Model):
|
||||||
dn = create_ldap_user.delay(
|
dn = create_ldap_user.delay(
|
||||||
self.username, self.uid, self.group.gid, self.gecos,
|
self.username, self.uid, self.group.gid, self.gecos,
|
||||||
self.homedir, self.shell, password=None).get()
|
self.homedir, self.shell, password=None).get()
|
||||||
sftp_dir = setup_file_sftp_userdir.delay(self.username).get()
|
TaskResult.objects.create_task_result(
|
||||||
mail_dir = setup_file_mail_userdir.delay(self.username).get()
|
setup_file_sftp_userdir.delay(self.username),
|
||||||
|
'setup_file_sftp_userdir'
|
||||||
|
)
|
||||||
|
TaskResult.objects.create_task_result(
|
||||||
|
setup_file_mail_userdir.delay(self.username),
|
||||||
|
'setup_file_mail_userdir'
|
||||||
|
)
|
||||||
_LOGGER.info(
|
_LOGGER.info(
|
||||||
"created user %(user)s with LDAP dn %(dn)s, home directory "
|
"created user %(user)s with LDAP dn %(dn)s, scheduled home "
|
||||||
"%(homedir)s and mail base directory %(maildir)s.", {
|
"directory and mail base directory creation.", {
|
||||||
'user': self, 'dn': dn,
|
'user': self, 'dn': dn,
|
||||||
'homedir': sftp_dir, 'maildir': mail_dir
|
|
||||||
})
|
})
|
||||||
return super(User, self).save(*args, **kwargs)
|
return super(User, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
@ -286,8 +296,14 @@ class User(TimeStampedModel, models.Model):
|
||||||
:py:meth:`django.db.Model.delete`
|
:py:meth:`django.db.Model.delete`
|
||||||
|
|
||||||
"""
|
"""
|
||||||
delete_file_mail_userdir.delay(self.username).get()
|
TaskResult.objects.create_task_result(
|
||||||
delete_file_sftp_userdir.delay(self.username).get()
|
delete_file_mail_userdir.delay(self.username),
|
||||||
|
'delete_file_mail_userdir'
|
||||||
|
)
|
||||||
|
TaskResult.objects.create_task_result(
|
||||||
|
delete_file_sftp_userdir.delay(self.username),
|
||||||
|
'delete_file_sftp_userdir'
|
||||||
|
)
|
||||||
for group in [ag.group for ag in self.additionalgroup_set.all()]:
|
for group in [ag.group for ag in self.additionalgroup_set.all()]:
|
||||||
remove_ldap_user_from_group.delay(
|
remove_ldap_user_from_group.delay(
|
||||||
self.username, group.groupname).get()
|
self.username, group.groupname).get()
|
||||||
|
@ -436,6 +452,9 @@ class AdditionalGroup(TimeStampedModel, models.Model):
|
||||||
:param kwargs: keyword arguments to be passed on to
|
:param kwargs: keyword arguments to be passed on to
|
||||||
:py:meth:`django.db.Model.delete`
|
:py:meth:`django.db.Model.delete`
|
||||||
"""
|
"""
|
||||||
remove_ldap_user_from_group.delay(
|
TaskResult.objects.create_task_result(
|
||||||
self.user.username, self.group.groupname).get()
|
remove_ldap_user_from_group.delay(
|
||||||
|
self.user.username, self.group.groupname),
|
||||||
|
'remove_ldap_user_from_group'
|
||||||
|
)
|
||||||
super(AdditionalGroup, self).delete(*args, **kwargs)
|
super(AdditionalGroup, self).delete(*args, **kwargs)
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
"""
|
"""
|
||||||
This module defines task stubs for the tasks implemented on the `Celery`_
|
This module defines task stubs for the tasks implemented on the Celery
|
||||||
workers.
|
workers.
|
||||||
|
|
||||||
.. _Celery: http://www.celeryproject.org/
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue