diff --git a/docs/changelog.rst b/docs/changelog.rst index 8307437..ff8024b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,6 +1,12 @@ Changelog ========= +* :release:`0.3.0 <2014-12-27>` +* :feature:`-` call create/delete mailbox tasks when saving/deleting mailboxes +* :support:`-` use celery routers from gvacommon +* :feature:`-` automatic creation of mailbox names from user names +* :bug:`- major` fix broken mailbox admin + * :release:`0.2.3 <2014-12-26>` * :bug:`-` remove attribute readonly_fields from :py:class:`osusers.admin.UserAdmin` to make saving of additional groups work diff --git a/docs/conf.py b/docs/conf.py index 3f2bc82..ffdf565 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -55,9 +55,9 @@ copyright = u'2014, Jan Dittberner' # built documents. # # The short X.Y version. -version = '0.2.3' +version = '0.3' # The full version, including alpha/beta/rc tags. -release = '0.2.3' +release = '0.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/gnuviechadmin/gnuviechadmin/settings/base.py b/gnuviechadmin/gnuviechadmin/settings/base.py index 5442654..f05a821 100644 --- a/gnuviechadmin/gnuviechadmin/settings/base.py +++ b/gnuviechadmin/gnuviechadmin/settings/base.py @@ -279,8 +279,8 @@ CELERY_RESULT_BACKEND = 'amqp' CELERY_RESULT_PERSISTENT = True CELERY_TASK_RESULT_EXPIRES = None CELERY_ROUTES = ( - 'osusers.tasks.LdapRouter', - 'osusers.tasks.FileRouter', + 'gvacommon.celeryrouters.LdapRouter', + 'gvacommon.celeryrouters.FileRouter', ) CELERY_ACCEPT_CONTENT = ['pickle', 'yaml', 'json'] CELERY_TASK_SERIALIZER = 'json' diff --git a/gnuviechadmin/gvacommon/.gitignore b/gnuviechadmin/gvacommon/.gitignore new file mode 100644 index 0000000..3bb2efd --- /dev/null +++ b/gnuviechadmin/gvacommon/.gitignore @@ -0,0 +1,2 @@ +.*.swp +*.pyc diff --git a/gnuviechadmin/gvacommon/__init__.py b/gnuviechadmin/gvacommon/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/gnuviechadmin/gvacommon/celeryrouters.py b/gnuviechadmin/gvacommon/celeryrouters.py new file mode 100644 index 0000000..e468813 --- /dev/null +++ b/gnuviechadmin/gvacommon/celeryrouters.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + + +class LdapRouter(object): + + def route_for_task(self, task, args=None, kwargs=None): + if 'ldap' in task: + return {'exchange': 'ldap', + 'exchange_type': 'direct', + 'queue': 'ldap'} + return None + + +class FileRouter(object): + + def route_for_task(self, task, args=None, kwargs=None): + if 'file' in task: + return {'exchange': 'file', + 'exchange_type': 'direct', + 'queue': 'file'} + return None + + diff --git a/gnuviechadmin/managemails/admin.py b/gnuviechadmin/managemails/admin.py index d74fcba..d1ddbdb 100644 --- a/gnuviechadmin/managemails/admin.py +++ b/gnuviechadmin/managemails/admin.py @@ -67,6 +67,8 @@ class MailboxCreationForm(forms.ModelForm): """ mailbox = super(MailboxCreationForm, self).save(commit=False) + mailbox.username = Mailbox.objects.get_next_mailbox_name( + mailbox.osuser) mailbox.set_password(self.cleaned_data['password1']) if commit: mailbox.save() @@ -113,12 +115,12 @@ class MailboxAdmin(ActivationChangeMixin, admin.ModelAdmin): list_filter = ('active',) fieldsets = ( (None, { - 'fields': ('username', 'password', 'osuser', 'active')}), + 'fields': ('osuser', 'username', 'password', 'active')}), ) add_fieldsets = ( (None, { 'classes': ('wide',), - 'fields': ('username', 'password1', 'password2')}), + 'fields': ('osuser', 'password1', 'password2')}), ) search_fields = ('username',) ordering = ('username',) diff --git a/gnuviechadmin/managemails/models.py b/gnuviechadmin/managemails/models.py index 425d79f..737dda0 100644 --- a/gnuviechadmin/managemails/models.py +++ b/gnuviechadmin/managemails/models.py @@ -7,6 +7,7 @@ from model_utils.models import TimeStampedModel from domains.models import MailDomain from osusers.models import User as OsUser +from osusers.tasks import create_file_mailbox, delete_file_mailbox class ActivateAbleMixin(models.Model): @@ -20,12 +21,32 @@ class ActivateAbleMixin(models.Model): abstract = True +class MailboxManager(models.Manager): + + def get_next_mailbox_name(self, osuser): + count = 1 + mailboxformat = "{0}p{1:02d}" + mailboxname = mailboxformat.format(osuser.username, count) + + for box in self.values('username').filter(osuser=osuser).order_by( + 'username' + ): + if box['username'] == mailboxname: + count += 1 + mailboxname = mailboxformat.format(osuser.username, count) + else: + break + return mailboxname + + @python_2_unicode_compatible class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model): osuser = models.ForeignKey(OsUser) username = models.CharField(max_length=128, unique=True) password = models.CharField(max_length=255) + objects = MailboxManager() + class Meta: verbose_name = _('Mailbox') verbose_name_plural = _('Mailboxes') @@ -33,6 +54,14 @@ class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model): def set_password(self, password): self.password = sha512_crypt.encrypt(password) + def save(self, *args, **kwargs): + create_file_mailbox.delay(self.osuser.username, self.username).get() + super(Mailbox, self).save(*args, **kwargs) + + def delete(self, *args, **kwargs): + delete_file_mailbox.delay(self.osuser.username, self.username).get() + super(Mailbox, self).delete(*args, **kwargs) + def __str__(self): return self.username diff --git a/gnuviechadmin/osusers/tasks.py b/gnuviechadmin/osusers/tasks.py index 7edd7c7..99c7b1c 100644 --- a/gnuviechadmin/osusers/tasks.py +++ b/gnuviechadmin/osusers/tasks.py @@ -3,26 +3,6 @@ from __future__ import absolute_import from celery import shared_task -class LdapRouter(object): - - def route_for_task(self, task, args=None, kwargs=None): - if 'ldap' in task: - return {'exchange': 'ldap', - 'exchange_type': 'direct', - 'queue': 'ldap'} - return None - - -class FileRouter(object): - - def route_for_task(self, task, args=None, kwargs=None): - if 'file' in task: - return {'exchange': 'file', - 'exchange_type': 'direct', - 'queue': 'file'} - return None - - @shared_task def create_ldap_group(groupname, gid, descr): pass @@ -71,3 +51,13 @@ def setup_file_mail_userdir(username): @shared_task def delete_file_mail_userdir(username): pass + + +@shared_task +def create_file_mailbox(username, mailboxname): + pass + + +@shared_task +def delete_file_mailbox(username, mailboxname): + pass