use taskresults app and delete_ldap_group task

This commit is contained in:
Jan Dittberner 2014-12-29 15:57:03 +01:00
parent a336af46c2
commit 6bf65bba3b
3 changed files with 32 additions and 15 deletions

View file

@ -1,6 +1,6 @@
"""
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

View file

@ -20,13 +20,15 @@ from model_utils.models import TimeStampedModel
from passlib.hash import sha512_crypt
from passlib.utils import generate_password
from taskresults.models import TaskResult
from .tasks import (
add_ldap_user_to_group,
create_ldap_group,
create_ldap_user,
delete_file_mail_userdir,
delete_file_sftp_userdir,
delete_ldap_group_if_empty,
delete_ldap_group,
delete_ldap_user,
remove_ldap_user_from_group,
setup_file_mail_userdir,
@ -115,7 +117,10 @@ class Group(TimeStampedModel, models.Model):
: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)
@ -264,13 +269,18 @@ class User(TimeStampedModel, models.Model):
dn = create_ldap_user.delay(
self.username, self.uid, self.group.gid, self.gecos,
self.homedir, self.shell, password=None).get()
sftp_dir = setup_file_sftp_userdir.delay(self.username).get()
mail_dir = setup_file_mail_userdir.delay(self.username).get()
TaskResult.objects.create_task_result(
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(
"created user %(user)s with LDAP dn %(dn)s, home directory "
"%(homedir)s and mail base directory %(maildir)s.", {
"created user %(user)s with LDAP dn %(dn)s, scheduled home "
"directory and mail base directory creation.", {
'user': self, 'dn': dn,
'homedir': sftp_dir, 'maildir': mail_dir
})
return super(User, self).save(*args, **kwargs)
@ -286,8 +296,14 @@ class User(TimeStampedModel, models.Model):
:py:meth:`django.db.Model.delete`
"""
delete_file_mail_userdir.delay(self.username).get()
delete_file_sftp_userdir.delay(self.username).get()
TaskResult.objects.create_task_result(
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()]:
remove_ldap_user_from_group.delay(
self.username, group.groupname).get()
@ -436,6 +452,9 @@ class AdditionalGroup(TimeStampedModel, models.Model):
:param kwargs: keyword arguments to be passed on to
:py:meth:`django.db.Model.delete`
"""
TaskResult.objects.create_task_result(
remove_ldap_user_from_group.delay(
self.user.username, self.group.groupname).get()
self.user.username, self.group.groupname),
'remove_ldap_user_from_group'
)
super(AdditionalGroup, self).delete(*args, **kwargs)

View file

@ -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.
.. _Celery: http://www.celeryproject.org/
"""
from __future__ import absolute_import