2019-12-05 07:09:25 +00:00
|
|
|
from rest_framework import serializers
|
|
|
|
|
2020-06-02 12:02:22 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2019-12-05 07:09:25 +00:00
|
|
|
from orgs.mixins.serializers import BulkOrgResourceModelSerializer
|
2021-01-01 23:25:23 +00:00
|
|
|
from common.drf.serializers import AdaptedBulkListSerializer
|
2019-12-05 07:09:25 +00:00
|
|
|
from ..models import Session
|
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
__all__ = [
|
|
|
|
'SessionSerializer', 'SessionDisplaySerializer',
|
2020-04-07 04:26:47 +00:00
|
|
|
'ReplaySerializer', 'SessionJoinValidateSerializer',
|
2020-03-12 08:24:38 +00:00
|
|
|
]
|
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
|
|
class SessionSerializer(BulkOrgResourceModelSerializer):
|
|
|
|
org_id = serializers.CharField(allow_blank=True)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Session
|
|
|
|
list_serializer_class = AdaptedBulkListSerializer
|
|
|
|
fields = [
|
2020-03-12 08:24:38 +00:00
|
|
|
"id", "user", "asset", "system_user",
|
|
|
|
"user_id", "asset_id", "system_user_id",
|
|
|
|
"login_from", "login_from_display", "remote_addr",
|
|
|
|
"is_success", "is_finished", "has_replay", "can_replay",
|
2020-11-11 11:06:46 +00:00
|
|
|
"can_join", "can_terminate", "protocol", "date_start", "date_end",
|
2020-03-12 08:24:38 +00:00
|
|
|
"terminal",
|
2019-12-05 07:09:25 +00:00
|
|
|
]
|
2020-06-02 12:02:22 +00:00
|
|
|
extra_kwargs = {
|
|
|
|
"protocol": {'label': _('Protocol')},
|
2020-11-11 02:27:18 +00:00
|
|
|
'user_id': {'label': _('User ID')},
|
|
|
|
'asset_id': {'label': _('Asset ID')},
|
|
|
|
'system_user_id': {'label': _('System user ID')},
|
|
|
|
'login_from_display': {'label': _('Login from for display')},
|
|
|
|
'is_success': {'label': _('Is success')},
|
|
|
|
'can_replay': {'label': _('Can replay')},
|
|
|
|
'can_join': {'label': _('Can join')},
|
|
|
|
'terminal': {'label': _('Terminal')},
|
|
|
|
'is_finished': {'label': _('Is finished')},
|
2020-06-02 12:02:22 +00:00
|
|
|
}
|
2019-12-05 07:09:25 +00:00
|
|
|
|
|
|
|
|
2020-03-12 08:24:38 +00:00
|
|
|
class SessionDisplaySerializer(SessionSerializer):
|
|
|
|
command_amount = serializers.IntegerField(read_only=True)
|
|
|
|
|
|
|
|
class Meta(SessionSerializer.Meta):
|
|
|
|
fields = SessionSerializer.Meta.fields + ['command_amount']
|
|
|
|
|
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
class ReplaySerializer(serializers.Serializer):
|
|
|
|
file = serializers.FileField(allow_empty_file=True)
|
2020-04-07 04:26:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SessionJoinValidateSerializer(serializers.Serializer):
|
|
|
|
user_id = serializers.UUIDField()
|
|
|
|
session_id = serializers.UUIDField()
|