let mailboxes reference os users
- refer to osuser instead of own home, uid and gid entries in mailboxes - add data and schema migrations
This commit is contained in:
parent
3de357d394
commit
f085dab017
3 changed files with 265 additions and 3 deletions
|
@ -0,0 +1,134 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# pymode:lint_ignore=E501
|
||||||
|
from south.v2 import DataMigration
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(DataMigration):
|
||||||
|
|
||||||
|
def forwards(self, orm):
|
||||||
|
"Adds user, group and shadow entries."
|
||||||
|
|
||||||
|
Mailbox = orm['managemails.Mailbox']
|
||||||
|
User = orm['osusers.User']
|
||||||
|
Group = orm['osusers.Group']
|
||||||
|
Shadow = orm['osusers.Shadow']
|
||||||
|
|
||||||
|
for mailbox in Mailbox.objects.all():
|
||||||
|
try:
|
||||||
|
group = Group.objects.get(gid=mailbox.gid)
|
||||||
|
except Group.DoesNotExist:
|
||||||
|
group = Group.objects.create(
|
||||||
|
groupname=mailbox.username, gid=mailbox.gid)
|
||||||
|
try:
|
||||||
|
user = User.objects.get(uid=mailbox.uid)
|
||||||
|
except User.DoesNotExist:
|
||||||
|
user = User.objects.create(
|
||||||
|
username=mailbox.username, uid=mailbox.uid,
|
||||||
|
homedir=mailbox.home, group=group
|
||||||
|
)
|
||||||
|
shadow = Shadow.objects.create(
|
||||||
|
user=user, passwd=mailbox.password)
|
||||||
|
shadow.save()
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
"Delete user, group and shadow entries."
|
||||||
|
|
||||||
|
Mailbox = orm['managemails.Mailbox']
|
||||||
|
User = orm['osusers.User']
|
||||||
|
Group = orm['osusers.Group']
|
||||||
|
|
||||||
|
for mailbox in Mailbox.objects.all():
|
||||||
|
group = Group.objects.get(gid=mailbox.gid)
|
||||||
|
user = User.objects.get(uid=mailbox.uid)
|
||||||
|
user.delete()
|
||||||
|
group.delete()
|
||||||
|
|
||||||
|
models = {
|
||||||
|
u'managemails.mailaddress': {
|
||||||
|
'Meta': {'unique_together': "(('localpart', 'domain'),)", 'object_name': 'MailAddress'},
|
||||||
|
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailDomain']"}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'localpart': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||||
|
},
|
||||||
|
u'managemails.mailaddressforward': {
|
||||||
|
'Meta': {'unique_together': "(('mailaddress', 'target'),)", 'object_name': 'MailAddressForward'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'mailaddress': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailAddress']"}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'target': ('django.db.models.fields.EmailField', [], {'max_length': '254'})
|
||||||
|
},
|
||||||
|
u'managemails.mailaddressmailbox': {
|
||||||
|
'Meta': {'unique_together': "(('mailaddress', 'mailbox'),)", 'object_name': 'MailAddressMailbox'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'mailaddress': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['managemails.MailAddress']", 'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'mailbox': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.Mailbox']"}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||||
|
},
|
||||||
|
u'managemails.mailbox': {
|
||||||
|
'Meta': {'object_name': 'Mailbox'},
|
||||||
|
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'gid': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
|
||||||
|
'home': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
|
||||||
|
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'})
|
||||||
|
},
|
||||||
|
u'managemails.maildomain': {
|
||||||
|
'Meta': {'object_name': 'MailDomain'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||||
|
},
|
||||||
|
u'osusers.additionalgroup': {
|
||||||
|
'Meta': {'unique_together': "(('user', 'group'),)", 'object_name': 'AdditionalGroup'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"})
|
||||||
|
},
|
||||||
|
u'osusers.group': {
|
||||||
|
'Meta': {'object_name': 'Group'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'descr': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'gid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'groupname': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'})
|
||||||
|
},
|
||||||
|
u'osusers.shadow': {
|
||||||
|
'Meta': {'object_name': 'Shadow'},
|
||||||
|
'changedays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'expiredays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'gracedays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'inactdays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'maxage': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'minage': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||||
|
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['osusers.User']", 'unique': 'True', 'primary_key': 'True'})
|
||||||
|
},
|
||||||
|
u'osusers.user': {
|
||||||
|
'Meta': {'object_name': 'User'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'gecos': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
'homedir': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'shell': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
|
||||||
|
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['osusers', 'managemails']
|
||||||
|
symmetrical = True
|
|
@ -0,0 +1,128 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# pymode:lint_ignore=E501
|
||||||
|
from south.db import db
|
||||||
|
from south.v2 import SchemaMigration
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(SchemaMigration):
|
||||||
|
|
||||||
|
def forwards(self, orm):
|
||||||
|
Mailbox = orm['managemails.Mailbox']
|
||||||
|
User = orm['osusers.User']
|
||||||
|
|
||||||
|
db.start_transaction()
|
||||||
|
|
||||||
|
db.add_column(
|
||||||
|
u'managemails_mailbox', 'osuser_id',
|
||||||
|
self.gf('django.db.models.fields.PositiveSmallIntegerField')(default=0))
|
||||||
|
|
||||||
|
for mailbox in Mailbox.objects.all():
|
||||||
|
user = User.objects.get(uid=mailbox.uid)
|
||||||
|
mailbox.osuser = user
|
||||||
|
mailbox.save()
|
||||||
|
|
||||||
|
db.alter_column(
|
||||||
|
u'managemails_mailbox', 'osuser_id',
|
||||||
|
self.gf('django.db.models.fields.related.ForeignKey')(to=orm['osusers.User']))
|
||||||
|
|
||||||
|
# Deleting field 'Mailbox.home'
|
||||||
|
db.delete_column(u'managemails_mailbox', 'home')
|
||||||
|
|
||||||
|
# Deleting field 'Mailbox.gid'
|
||||||
|
db.delete_column(u'managemails_mailbox', 'gid')
|
||||||
|
|
||||||
|
# Deleting field 'Mailbox.uid'
|
||||||
|
db.delete_column(u'managemails_mailbox', 'uid')
|
||||||
|
|
||||||
|
db.commit_transaction()
|
||||||
|
|
||||||
|
def backwards(self, orm):
|
||||||
|
raise RuntimeError("Cannot reverse this migration.")
|
||||||
|
|
||||||
|
models = {
|
||||||
|
u'managemails.mailaddress': {
|
||||||
|
'Meta': {'unique_together': "(('localpart', 'domain'),)", 'object_name': 'MailAddress'},
|
||||||
|
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'domain': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailDomain']"}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'localpart': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||||
|
},
|
||||||
|
u'managemails.mailaddressforward': {
|
||||||
|
'Meta': {'unique_together': "(('mailaddress', 'target'),)", 'object_name': 'MailAddressForward'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'mailaddress': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.MailAddress']"}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'target': ('django.db.models.fields.EmailField', [], {'max_length': '254'})
|
||||||
|
},
|
||||||
|
u'managemails.mailaddressmailbox': {
|
||||||
|
'Meta': {'unique_together': "(('mailaddress', 'mailbox'),)", 'object_name': 'MailAddressMailbox'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'mailaddress': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['managemails.MailAddress']", 'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'mailbox': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['managemails.Mailbox']"}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||||
|
},
|
||||||
|
u'managemails.mailbox': {
|
||||||
|
'Meta': {'object_name': 'Mailbox'},
|
||||||
|
'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'osuser': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"}),
|
||||||
|
'password': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
|
||||||
|
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
|
||||||
|
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {}),
|
||||||
|
},
|
||||||
|
u'managemails.maildomain': {
|
||||||
|
'Meta': {'object_name': 'MailDomain'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'domain': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '128'}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'})
|
||||||
|
},
|
||||||
|
u'osusers.additionalgroup': {
|
||||||
|
'Meta': {'unique_together': "(('user', 'group'),)", 'object_name': 'AdditionalGroup'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.User']"})
|
||||||
|
},
|
||||||
|
u'osusers.group': {
|
||||||
|
'Meta': {'object_name': 'Group'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'descr': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
|
||||||
|
'gid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'groupname': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '16'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'})
|
||||||
|
},
|
||||||
|
u'osusers.shadow': {
|
||||||
|
'Meta': {'object_name': 'Shadow'},
|
||||||
|
'changedays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'expiredays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
|
||||||
|
'gracedays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'inactdays': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'maxage': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'minage': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'passwd': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
|
||||||
|
'user': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['osusers.User']", 'unique': 'True', 'primary_key': 'True'})
|
||||||
|
},
|
||||||
|
u'osusers.user': {
|
||||||
|
'Meta': {'object_name': 'User'},
|
||||||
|
'created': ('model_utils.fields.AutoCreatedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'gecos': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
|
||||||
|
'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['osusers.Group']"}),
|
||||||
|
'homedir': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
|
||||||
|
'modified': ('model_utils.fields.AutoLastModifiedField', [], {'default': 'datetime.datetime.now'}),
|
||||||
|
'shell': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
|
||||||
|
'uid': ('django.db.models.fields.PositiveSmallIntegerField', [], {'unique': 'True', 'primary_key': 'True'}),
|
||||||
|
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '64'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
complete_apps = ['osusers', 'managemails']
|
|
@ -5,6 +5,8 @@ from django.utils.translation import ugettext as _
|
||||||
from passlib.hash import sha512_crypt
|
from passlib.hash import sha512_crypt
|
||||||
from model_utils.models import TimeStampedModel
|
from model_utils.models import TimeStampedModel
|
||||||
|
|
||||||
|
from osusers.models import User as OsUser
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class MailDomain(TimeStampedModel, models.Model):
|
class MailDomain(TimeStampedModel, models.Model):
|
||||||
|
@ -31,11 +33,9 @@ class ActivateAbleMixin(models.Model):
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model):
|
class Mailbox(ActivateAbleMixin, TimeStampedModel, models.Model):
|
||||||
|
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)
|
||||||
home = models.CharField(max_length=255)
|
|
||||||
uid = models.PositiveSmallIntegerField()
|
|
||||||
gid = models.PositiveSmallIntegerField()
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('Mailbox')
|
verbose_name = _('Mailbox')
|
||||||
|
|
Loading…
Reference in a new issue