2021-09-09 12:12:52 +00:00
|
|
|
# Generated by Django 3.1.12 on 2021-09-09 11:46
|
2021-08-24 06:20:54 +00:00
|
|
|
|
|
|
|
from django.conf import settings
|
|
|
|
from django.db import migrations, models
|
|
|
|
import django.db.models.deletion
|
|
|
|
|
|
|
|
|
2021-09-09 13:11:26 +00:00
|
|
|
def init_user_msg_subscription(apps, schema_editor):
|
|
|
|
UserMsgSubscription = apps.get_model('notifications', 'UserMsgSubscription')
|
|
|
|
User = apps.get_model('users', 'User')
|
|
|
|
|
|
|
|
to_create = []
|
|
|
|
users = User.objects.all()
|
|
|
|
for user in users:
|
|
|
|
receive_backends = []
|
|
|
|
|
|
|
|
receive_backends.append('site_msg')
|
|
|
|
|
|
|
|
if user.email:
|
|
|
|
receive_backends.append('email')
|
|
|
|
|
|
|
|
if user.wecom_id:
|
|
|
|
receive_backends.append('wecom')
|
|
|
|
|
|
|
|
if user.dingtalk_id:
|
|
|
|
receive_backends.append('dingtalk')
|
|
|
|
|
|
|
|
if user.feishu_id:
|
|
|
|
receive_backends.append('feishu')
|
|
|
|
|
|
|
|
to_create.append(UserMsgSubscription(user=user, receive_backends=receive_backends))
|
|
|
|
UserMsgSubscription.objects.bulk_create(to_create)
|
|
|
|
print(f'\n Init user message subscription: {len(to_create)}')
|
|
|
|
|
|
|
|
|
2021-08-24 06:20:54 +00:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
|
|
|
dependencies = [
|
|
|
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
|
|
|
('notifications', '0001_initial'),
|
2021-09-09 13:11:26 +00:00
|
|
|
('users', '0036_user_feishu_id'),
|
2021-08-24 06:20:54 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.RemoveField(
|
|
|
|
model_name='usermsgsubscription',
|
|
|
|
name='message_type',
|
|
|
|
),
|
|
|
|
migrations.AlterField(
|
|
|
|
model_name='usermsgsubscription',
|
|
|
|
name='user',
|
2021-09-09 12:12:52 +00:00
|
|
|
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='user_msg_subscription', to=settings.AUTH_USER_MODEL),
|
2021-08-24 06:20:54 +00:00
|
|
|
),
|
2021-09-09 13:11:26 +00:00
|
|
|
migrations.RunPython(init_user_msg_subscription)
|
2021-08-24 06:20:54 +00:00
|
|
|
]
|