Merge branch 'release/0.3.0' into production

* release/0.3.0:
  set version 0.3.0
  call create/delete mailbox tasks when saving/deleting mailboxes
  use celery routers from gvacommon
  initial version
  implement automatic creation of mailbox names
  repair mailbox creation admin
This commit is contained in:
Jan Dittberner 2014-12-27 16:39:37 +01:00
commit d2adfbebdd
9 changed files with 79 additions and 26 deletions

View file

@ -1,6 +1,12 @@
Changelog 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>` * :release:`0.2.3 <2014-12-26>`
* :bug:`-` remove attribute readonly_fields from * :bug:`-` remove attribute readonly_fields from
:py:class:`osusers.admin.UserAdmin` to make saving of additional groups work :py:class:`osusers.admin.UserAdmin` to make saving of additional groups work

View file

@ -55,9 +55,9 @@ copyright = u'2014, Jan Dittberner'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = '0.2.3' version = '0.3'
# The full version, including alpha/beta/rc tags. # 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 # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View file

@ -279,8 +279,8 @@ CELERY_RESULT_BACKEND = 'amqp'
CELERY_RESULT_PERSISTENT = True CELERY_RESULT_PERSISTENT = True
CELERY_TASK_RESULT_EXPIRES = None CELERY_TASK_RESULT_EXPIRES = None
CELERY_ROUTES = ( CELERY_ROUTES = (
'osusers.tasks.LdapRouter', 'gvacommon.celeryrouters.LdapRouter',
'osusers.tasks.FileRouter', 'gvacommon.celeryrouters.FileRouter',
) )
CELERY_ACCEPT_CONTENT = ['pickle', 'yaml', 'json'] CELERY_ACCEPT_CONTENT = ['pickle', 'yaml', 'json']
CELERY_TASK_SERIALIZER = 'json' CELERY_TASK_SERIALIZER = 'json'

2
gnuviechadmin/gvacommon/.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
.*.swp
*.pyc

View file

View file

@ -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

View file

@ -67,6 +67,8 @@ class MailboxCreationForm(forms.ModelForm):
""" """
mailbox = super(MailboxCreationForm, self).save(commit=False) mailbox = super(MailboxCreationForm, self).save(commit=False)
mailbox.username = Mailbox.objects.get_next_mailbox_name(
mailbox.osuser)
mailbox.set_password(self.cleaned_data['password1']) mailbox.set_password(self.cleaned_data['password1'])
if commit: if commit:
mailbox.save() mailbox.save()
@ -113,12 +115,12 @@ class MailboxAdmin(ActivationChangeMixin, admin.ModelAdmin):
list_filter = ('active',) list_filter = ('active',)
fieldsets = ( fieldsets = (
(None, { (None, {
'fields': ('username', 'password', 'osuser', 'active')}), 'fields': ('osuser', 'username', 'password', 'active')}),
) )
add_fieldsets = ( add_fieldsets = (
(None, { (None, {
'classes': ('wide',), 'classes': ('wide',),
'fields': ('username', 'password1', 'password2')}), 'fields': ('osuser', 'password1', 'password2')}),
) )
search_fields = ('username',) search_fields = ('username',)
ordering = ('username',) ordering = ('username',)

View file

@ -7,6 +7,7 @@ from model_utils.models import TimeStampedModel
from domains.models import MailDomain from domains.models import MailDomain
from osusers.models import User as OsUser from osusers.models import User as OsUser
from osusers.tasks import create_file_mailbox, delete_file_mailbox
class ActivateAbleMixin(models.Model): class ActivateAbleMixin(models.Model):
@ -20,12 +21,32 @@ class ActivateAbleMixin(models.Model):
abstract = True 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 @python_2_unicode_compatible
class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model): class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model):
osuser = models.ForeignKey(OsUser) osuser = models.ForeignKey(OsUser)
username = models.CharField(max_length=128, unique=True) username = models.CharField(max_length=128, unique=True)
password = models.CharField(max_length=255) password = models.CharField(max_length=255)
objects = MailboxManager()
class Meta: class Meta:
verbose_name = _('Mailbox') verbose_name = _('Mailbox')
verbose_name_plural = _('Mailboxes') verbose_name_plural = _('Mailboxes')
@ -33,6 +54,14 @@ class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model):
def set_password(self, password): def set_password(self, password):
self.password = sha512_crypt.encrypt(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): def __str__(self):
return self.username return self.username

View file

@ -3,26 +3,6 @@ from __future__ import absolute_import
from celery import shared_task 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 @shared_task
def create_ldap_group(groupname, gid, descr): def create_ldap_group(groupname, gid, descr):
pass pass
@ -71,3 +51,13 @@ def setup_file_mail_userdir(username):
@shared_task @shared_task
def delete_file_mail_userdir(username): def delete_file_mail_userdir(username):
pass pass
@shared_task
def create_file_mailbox(username, mailboxname):
pass
@shared_task
def delete_file_mailbox(username, mailboxname):
pass