mirror of https://github.com/jumpserver/jumpserver
parent
dc742d1281
commit
81000953e2
|
@ -48,7 +48,7 @@ class UserLoginOtpView(mixins.AuthMixin, FormView):
|
|||
{
|
||||
'name': 'sms',
|
||||
'label': _('SMS'),
|
||||
'enable': bool(user.phone) and settings.AUTH_SMS,
|
||||
'enable': bool(user.phone) and settings.SMS_ENABLED and settings.XPACK_ENABLED,
|
||||
'selected': False,
|
||||
},
|
||||
]
|
||||
|
|
|
@ -243,7 +243,7 @@ class Config(dict):
|
|||
'LOGIN_REDIRECT_TO_BACKEND': '', # 'OPENID / CAS
|
||||
'LOGIN_REDIRECT_MSG_ENABLED': True,
|
||||
|
||||
'AUTH_SMS': False,
|
||||
'SMS_ENABLED': False,
|
||||
'SMS_BACKEND': '',
|
||||
'SMS_TEST_PHONE': '',
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ FEISHU_APP_ID = CONFIG.FEISHU_APP_ID
|
|||
FEISHU_APP_SECRET = CONFIG.FEISHU_APP_SECRET
|
||||
|
||||
# SMS auth
|
||||
AUTH_SMS = CONFIG.AUTH_SMS
|
||||
SMS_ENABLED = CONFIG.SMS_ENABLED
|
||||
SMS_BACKEND = CONFIG.SMS_BACKEND
|
||||
SMS_TEST_PHONE = CONFIG.SMS_TEST_PHONE
|
||||
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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),
|
||||
),
|
||||
]
|
|
@ -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 = [
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -7,7 +7,7 @@ __all__ = ['AlibabaSMSSettingSerializer', 'TencentSMSSettingSerializer']
|
|||
|
||||
|
||||
class BaseSMSSettingSerializer(serializers.Serializer):
|
||||
AUTH_SMS = serializers.BooleanField(default=False, label=_('Enable SMS'))
|
||||
SMS_ENABLED = serializers.BooleanField(default=False, label=_('Enable SMS'))
|
||||
SMS_TEST_PHONE = serializers.CharField(max_length=256, required=False, label=_('Test phone'))
|
||||
|
||||
def to_representation(self, instance):
|
||||
|
|
|
@ -565,9 +565,17 @@ class MFAMixin:
|
|||
def mfa_enabled_but_not_set(self):
|
||||
if not self.mfa_enabled:
|
||||
return False, None
|
||||
if self.mfa_is_otp() and not self.otp_secret_key and not self.phone:
|
||||
return True, reverse('authentication:user-otp-enable-start')
|
||||
return False, None
|
||||
|
||||
if not self.mfa_is_otp():
|
||||
return False, None
|
||||
|
||||
if self.mfa_is_otp() and self.otp_secret_key:
|
||||
return False, None
|
||||
|
||||
if self.phone and settings.SMS_ENABLED and settings.XPACK_ENABLED:
|
||||
return False, None
|
||||
|
||||
return True, reverse('authentication:user-otp-enable-start')
|
||||
|
||||
|
||||
class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser):
|
||||
|
@ -661,6 +669,10 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser):
|
|||
group_ids = list(group_ids)
|
||||
return group_ids
|
||||
|
||||
@property
|
||||
def receive_backends(self):
|
||||
return self.user_msg_subscription.receive_backends
|
||||
|
||||
@property
|
||||
def is_wecom_bound(self):
|
||||
return bool(self.wecom_id)
|
||||
|
|
|
@ -101,16 +101,17 @@ class UserProfileSerializer(UserSerializer):
|
|||
)
|
||||
mfa_level = serializers.ChoiceField(choices=MFA_LEVEL_CHOICES, label=_('MFA'), required=False)
|
||||
guide_url = serializers.SerializerMethodField()
|
||||
receive_backends = serializers.ListField(child=serializers.CharField())
|
||||
|
||||
class Meta(UserSerializer.Meta):
|
||||
fields = UserSerializer.Meta.fields + [
|
||||
'public_key_comment', 'public_key_hash_md5',
|
||||
'admin_or_audit_orgs', 'current_org_roles',
|
||||
'guide_url', 'user_all_orgs', 'is_org_admin',
|
||||
'is_superuser'
|
||||
'is_superuser', 'receive_backends',
|
||||
]
|
||||
read_only_fields = [
|
||||
'date_joined', 'last_login', 'created_by', 'source'
|
||||
'date_joined', 'last_login', 'created_by', 'source', 'receive_backends',
|
||||
]
|
||||
extra_kwargs = dict(UserSerializer.Meta.extra_kwargs)
|
||||
extra_kwargs.update({
|
||||
|
|
Loading…
Reference in New Issue