[Update] 在线/历史/命令model添加org;修复命令记录保存org失败bug (#1584)

* [Update] 修复创建授权规则,显示org_name不是有效UUID的bug

* [Update] 更新org之间隔离授权规则,解决QuerySet与Manager问题;修复创建用户,显示org_name不是有效UUID之bug;

* [Update] 在线/历史/命令model添加org

* [Bugfix] 修复命令记录,保存org不成功bug
pull/1594/head
BaiJiangJie 2018-07-25 15:13:53 +08:00 committed by 老广
parent 36f1165d1b
commit f17727deb9
4 changed files with 8 additions and 4 deletions

View File

@ -21,7 +21,7 @@ class CommandStore(CommandBase):
user=command["user"], asset=command["asset"], user=command["user"], asset=command["asset"],
system_user=command["system_user"], input=command["input"], system_user=command["system_user"], input=command["input"],
output=command["output"], session=command["session"], output=command["output"], session=command["session"],
timestamp=command["timestamp"] org_id=command["org_id"], timestamp=command["timestamp"]
) )
def bulk_save(self, commands): def bulk_save(self, commands):
@ -33,7 +33,7 @@ class CommandStore(CommandBase):
_commands.append(self.model( _commands.append(self.model(
user=c["user"], asset=c["asset"], system_user=c["system_user"], user=c["user"], asset=c["asset"], system_user=c["system_user"],
input=c["input"], output=c["output"], session=c["session"], input=c["input"], output=c["output"], session=c["session"],
timestamp=c["timestamp"] org_id=c["org_id"], timestamp=c["timestamp"]
)) ))
return self.model.objects.bulk_create(_commands) return self.model.objects.bulk_create(_commands)

View File

@ -4,8 +4,10 @@ import uuid
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from orgs.mixins import OrgModelMixin
class AbstractSessionCommand(models.Model):
class AbstractSessionCommand(OrgModelMixin):
id = models.UUIDField(default=uuid.uuid4, primary_key=True) id = models.UUIDField(default=uuid.uuid4, primary_key=True)
user = models.CharField(max_length=64, db_index=True, verbose_name=_("User")) user = models.CharField(max_length=64, db_index=True, verbose_name=_("User"))
asset = models.CharField(max_length=128, db_index=True, verbose_name=_("Asset")) asset = models.CharField(max_length=128, db_index=True, verbose_name=_("Asset"))

View File

@ -12,5 +12,6 @@ class SessionCommandSerializer(serializers.Serializer):
input = serializers.CharField(max_length=128) input = serializers.CharField(max_length=128)
output = serializers.CharField(max_length=1024, allow_blank=True) output = serializers.CharField(max_length=1024, allow_blank=True)
session = serializers.CharField(max_length=36) session = serializers.CharField(max_length=36)
org_id = serializers.CharField(max_length=36)
timestamp = serializers.IntegerField() timestamp = serializers.IntegerField()

View File

@ -8,6 +8,7 @@ from django.utils import timezone
from django.conf import settings from django.conf import settings
from users.models import User from users.models import User
from orgs.mixins import OrgModelMixin
from .backends.command.models import AbstractSessionCommand from .backends.command.models import AbstractSessionCommand
@ -112,7 +113,7 @@ class Status(models.Model):
return self.date_created.strftime("%Y-%m-%d %H:%M:%S") return self.date_created.strftime("%Y-%m-%d %H:%M:%S")
class Session(models.Model): class Session(OrgModelMixin):
LOGIN_FROM_CHOICES = ( LOGIN_FROM_CHOICES = (
('ST', 'SSH Terminal'), ('ST', 'SSH Terminal'),
('WT', 'Web Terminal'), ('WT', 'Web Terminal'),