From 02ca8c3139949168368a2b6ea7a8416304db1cd8 Mon Sep 17 00:00:00 2001 From: ibuler Date: Mon, 23 Apr 2018 11:32:46 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E6=9B=B4=E6=96=B0session=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api.py | 5 +++++ apps/terminal/models.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/apps/terminal/api.py b/apps/terminal/api.py index e625e17bc..027793313 100644 --- a/apps/terminal/api.py +++ b/apps/terminal/api.py @@ -182,6 +182,11 @@ class SessionViewSet(viewsets.ModelViewSet): self.queryset = terminal.session_set.all() return self.queryset + def perform_create(self, serializer): + if self.request.user.terminal: + serializer.validated_data["terminal"] = self.request.user.terminal + return super().perform_create(serializer) + class TaskViewSet(BulkModelViewSet): queryset = Task.objects.all() diff --git a/apps/terminal/models.py b/apps/terminal/models.py index 5829fa2e1..21fb49300 100644 --- a/apps/terminal/models.py +++ b/apps/terminal/models.py @@ -117,6 +117,10 @@ class Session(models.Model): ('ST', 'SSH Terminal'), ('WT', 'Web Terminal'), ) + PROTOCOL_CHOICES = ( + ('ssh', 'ssh'), + ('rdp', 'rdp') + ) id = models.UUIDField(default=uuid.uuid4, primary_key=True) user = models.CharField(max_length=128, verbose_name=_("User")) @@ -128,6 +132,7 @@ class Session(models.Model): has_replay = models.BooleanField(default=False, verbose_name=_("Replay")) has_command = models.BooleanField(default=False, verbose_name=_("Command")) terminal = models.ForeignKey(Terminal, null=True, on_delete=models.SET_NULL) + protocol = models.CharField(choices=PROTOCOL_CHOICES, default='ssh') date_last_active = models.DateTimeField(verbose_name=_("Date last active"), default=timezone.now) date_start = models.DateTimeField(verbose_name=_("Date start"), db_index=True) date_end = models.DateTimeField(verbose_name=_("Date end"), null=True)