feat: 会话分享可设置1、5分钟时限,且可分享给指定人 (#8227)

* perf: 完成会话分享可设置1、5分钟时限,且可分享给指定人

* perf: 完成会话分享可设置1、5分钟时限,且可分享给指定人

* perf: 完成会话分享可设置1、5分钟时限,且可分享给指定人

* feat: 完成会话分享可设置1、5分钟时限,且可分享给指定人
pull/8514/head
jiangweidong 2022-06-30 11:21:26 +08:00 committed by GitHub
parent 067a90ff9a
commit 5d80933e7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 3 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1.14 on 2022-05-17 00:52
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('terminal', '0049_endpoint_redis_port'),
]
operations = [
migrations.AddField(
model_name='sessionsharing',
name='users',
field=models.CharField(default=list, max_length=1024, verbose_name='User'),
),
]

View File

@ -28,6 +28,7 @@ class SessionSharing(CommonModelMixin, OrgModelMixin):
expired_time = models.IntegerField(
default=0, verbose_name=_('Expired time (min)'), db_index=True
)
users = models.CharField(max_length=1024, verbose_name=_("User"), default=list)
class Meta:
ordering = ('-date_created', )
@ -49,11 +50,13 @@ class SessionSharing(CommonModelMixin, OrgModelMixin):
return False
return True
def can_join(self):
def can_join(self, joiner):
if not self.is_active:
return False, _('Link not active')
if not self.is_expired:
return False, _('Link expired')
if self.users and str(joiner.id) not in self.users.split(','):
return False, _('User not allowed to join')
return True, ''
@ -110,7 +113,7 @@ class SessionJoinRecord(CommonModelMixin, OrgModelMixin):
def can_join(self):
# sharing
sharing_can_join, reason = self.sharing.can_join()
sharing_can_join, reason = self.sharing.can_join(self.joiner)
if not sharing_can_join:
return False, reason
# self

View File

@ -8,17 +8,26 @@ __all__ = ['SessionSharingSerializer', 'SessionJoinRecordSerializer']
class SessionSharingSerializer(OrgResourceModelSerializerMixin):
users = serializers.ListSerializer(
child=serializers.CharField(max_length=36), write_only=True, default=list, allow_null=True
)
class Meta:
model = SessionSharing
fields_mini = ['id']
fields_small = fields_mini + [
'verify_code', 'is_active', 'expired_time', 'created_by',
'date_created', 'date_updated'
'date_created', 'date_updated', 'users'
]
fields_fk = ['session', 'creator']
fields = fields_small + fields_fk
read_only_fields = ['verify_code']
def save(self, **kwargs):
users = self.validated_data.get('users', [])
self.validated_data['users'] = ','.join(users)
return super().save(**kwargs)
def create(self, validated_data):
validated_data['verify_code'] = random_string(4)
session = validated_data.get('session')