fix: 修改消息订阅 (#6789)

Co-authored-by: xinwen <coderWen@126.com>
This commit is contained in:
fit2bot
2021-09-09 20:12:52 +08:00
committed by GitHub
parent dc742d1281
commit 81000953e2
12 changed files with 31 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ from .base import BackendBase
class SMS(BackendBase):
account_field = 'phone'
is_enable_field_in_settings = 'AUTH_SMS'
is_enable_field_in_settings = 'SMS_ENABLED'
def __init__(self):
"""

View File

@@ -44,7 +44,7 @@ class Migration(migrations.Migration):
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
('message_type', models.CharField(max_length=128)),
('receive_backends', models.JSONField(default=list)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_msg_subscriptions', to=settings.AUTH_USER_MODEL)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_msg_subscription', to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,

View File

@@ -1,4 +1,4 @@
# Generated by Django 3.1.12 on 2021-08-23 08:19
# Generated by Django 3.1.12 on 2021-09-09 11:46
from django.conf import settings
from django.db import migrations, models
@@ -20,6 +20,6 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='usermsgsubscription',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='user_msg_subscriptions', to=settings.AUTH_USER_MODEL, unique=True),
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='user_msg_subscription', to=settings.AUTH_USER_MODEL),
),
]

View File

@@ -35,7 +35,7 @@ class Migration(migrations.Migration):
dependencies = [
('users', '0036_user_feishu_id'),
('notifications', '0002_auto_20210823_1619'),
('notifications', '0002_auto_20210909_1946'),
]
operations = [

View File

@@ -6,7 +6,7 @@ __all__ = ('SystemMsgSubscription', 'UserMsgSubscription')
class UserMsgSubscription(JMSModel):
user = models.OneToOneField('users.User', related_name='user_msg_subscriptions', on_delete=models.CASCADE)
user = models.OneToOneField('users.User', related_name='user_msg_subscription', on_delete=models.CASCADE)
receive_backends = models.JSONField(default=list)
def __str__(self):

View File

@@ -68,6 +68,9 @@ class Message(metaclass=MessageType):
raise NotImplementedError
def send_msg(self, users: Iterable, backends: Iterable = BACKEND):
backends = set(backends)
backends.add(BACKEND.SITE_MSG) # 站内信必须发
for backend in backends:
try:
backend = BACKEND(backend)