mirror of https://github.com/jumpserver/jumpserver
perf: 修改 session 字段,添加 Comment
parent
615a1ddc96
commit
d040162d86
|
@ -7,14 +7,19 @@ def migrate_del_macos(apps, schema_editor):
|
||||||
db_alias = schema_editor.connection.alias
|
db_alias = schema_editor.connection.alias
|
||||||
asset_model = apps.get_model('assets', 'Asset')
|
asset_model = apps.get_model('assets', 'Asset')
|
||||||
platform_model = apps.get_model('assets', 'Platform')
|
platform_model = apps.get_model('assets', 'Platform')
|
||||||
old_macos = platform_model.objects.using(db_alias).get(
|
old_macos = platform_model.objects.using(db_alias).filter(
|
||||||
name='MacOS', type='macos'
|
name='MacOS', type='macos'
|
||||||
)
|
).first()
|
||||||
new_macos = platform_model.objects.using(db_alias).get(
|
new_macos = platform_model.objects.using(db_alias).filter(
|
||||||
name='macOS', type='unix'
|
name='macOS', type='unix'
|
||||||
)
|
).first()
|
||||||
|
|
||||||
|
if not old_macos or not new_macos:
|
||||||
|
return
|
||||||
|
|
||||||
asset_model.objects.using(db_alias).filter(
|
asset_model.objects.using(db_alias).filter(
|
||||||
platform=old_macos).update(platform=new_macos)
|
platform=old_macos
|
||||||
|
).update(platform=new_macos)
|
||||||
|
|
||||||
platform_model.objects.using(db_alias).filter(id=old_macos.id).delete()
|
platform_model.objects.using(db_alias).filter(id=old_macos.id).delete()
|
||||||
|
|
||||||
|
|
|
@ -4,25 +4,24 @@ from urllib.parse import parse_qsl
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db.models import F, Value, CharField
|
from django.db.models import F, Value, CharField
|
||||||
from rest_framework.generics import ListAPIView
|
from rest_framework.generics import ListAPIView
|
||||||
|
from rest_framework.generics import get_object_or_404
|
||||||
from rest_framework.request import Request
|
from rest_framework.request import Request
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.generics import get_object_or_404
|
|
||||||
|
|
||||||
|
from assets.api import SerializeToTreeNodeMixin
|
||||||
from assets.models import Asset, Account
|
from assets.models import Asset, Account
|
||||||
from assets.utils import KubernetesTree
|
from assets.utils import KubernetesTree
|
||||||
from assets.api import SerializeToTreeNodeMixin
|
from common.utils import get_object_or_none, lazyproperty
|
||||||
|
from common.utils.common import timeit
|
||||||
from perms.hands import Node
|
from perms.hands import Node
|
||||||
from perms.models import PermNode
|
from perms.models import PermNode
|
||||||
|
from perms.utils import PermAccountUtil
|
||||||
|
from perms.utils.permission import AssetPermissionUtil
|
||||||
from perms.utils.user_permission import (
|
from perms.utils.user_permission import (
|
||||||
UserGrantedNodesQueryUtils, UserGrantedAssetsQueryUtils,
|
UserGrantedNodesQueryUtils, UserGrantedAssetsQueryUtils,
|
||||||
)
|
)
|
||||||
from perms.utils import PermAccountUtil
|
|
||||||
from perms.utils.permission import AssetPermissionUtil
|
|
||||||
from common.utils import get_object_or_none, lazyproperty
|
|
||||||
from common.utils.common import timeit
|
|
||||||
|
|
||||||
from ..mixin import SelfOrPKUserMixin
|
|
||||||
from .mixin import RebuildTreeMixin
|
from .mixin import RebuildTreeMixin
|
||||||
|
from ..mixin import SelfOrPKUserMixin
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
'UserGrantedK8sAsTreeApi',
|
'UserGrantedK8sAsTreeApi',
|
||||||
|
@ -31,8 +30,10 @@ __all__ = [
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class BaseUserNodeWithAssetAsTreeApi(SelfOrPKUserMixin, RebuildTreeMixin, SerializeToTreeNodeMixin,
|
class BaseUserNodeWithAssetAsTreeApi(
|
||||||
ListAPIView):
|
SelfOrPKUserMixin, RebuildTreeMixin,
|
||||||
|
SerializeToTreeNodeMixin, ListAPIView
|
||||||
|
):
|
||||||
|
|
||||||
def list(self, request, *args, **kwargs):
|
def list(self, request, *args, **kwargs):
|
||||||
nodes, assets = self.get_nodes_assets()
|
nodes, assets = self.get_nodes_assets()
|
||||||
|
@ -129,10 +130,7 @@ class UserPermedNodeChildrenWithAssetsAsTreeApi(BaseUserNodeWithAssetAsTreeApi):
|
||||||
return self.query_node_key
|
return self.query_node_key
|
||||||
|
|
||||||
|
|
||||||
class UserGrantedK8sAsTreeApi(
|
class UserGrantedK8sAsTreeApi(SelfOrPKUserMixin, ListAPIView):
|
||||||
SelfOrPKUserMixin,
|
|
||||||
ListAPIView
|
|
||||||
):
|
|
||||||
""" 用户授权的K8s树 """
|
""" 用户授权的K8s树 """
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 3.2.14 on 2022-12-16 07:29
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('terminal', '0061_rename_system_user_command_account'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='session',
|
||||||
|
name='comment',
|
||||||
|
field=models.TextField(blank=True, null=True, verbose_name='Comment'),
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='session',
|
||||||
|
name='type',
|
||||||
|
field=models.CharField(db_index=True, default='normal', max_length=16),
|
||||||
|
),
|
||||||
|
]
|
|
@ -3,24 +3,23 @@ from __future__ import unicode_literals
|
||||||
import os
|
import os
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from django.db import models
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from django.utils import timezone
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.files.storage import default_storage
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
from django.core.files.storage import default_storage
|
||||||
|
from django.db import models
|
||||||
|
from django.utils import timezone
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from assets.models import Asset
|
|
||||||
from assets.const import Protocol
|
from assets.const import Protocol
|
||||||
from users.models import User
|
from assets.models import Asset
|
||||||
from orgs.mixins.models import OrgModelMixin
|
|
||||||
from django.db.models import TextChoices
|
|
||||||
from common.utils import get_object_or_none, lazyproperty
|
from common.utils import get_object_or_none, lazyproperty
|
||||||
|
from orgs.mixins.models import OrgModelMixin
|
||||||
from terminal.backends import get_multi_command_storage
|
from terminal.backends import get_multi_command_storage
|
||||||
|
from users.models import User
|
||||||
|
|
||||||
|
|
||||||
class Session(OrgModelMixin):
|
class Session(OrgModelMixin):
|
||||||
class LOGIN_FROM(TextChoices):
|
class LOGIN_FROM(models.TextChoices):
|
||||||
ST = 'ST', 'SSH Terminal'
|
ST = 'ST', 'SSH Terminal'
|
||||||
RT = 'RT', 'RDP Terminal'
|
RT = 'RT', 'RDP Terminal'
|
||||||
WT = 'WT', 'Web Terminal'
|
WT = 'WT', 'Web Terminal'
|
||||||
|
@ -34,6 +33,7 @@ class Session(OrgModelMixin):
|
||||||
account = models.CharField(max_length=128, verbose_name=_("Account"), db_index=True)
|
account = models.CharField(max_length=128, verbose_name=_("Account"), db_index=True)
|
||||||
protocol = models.CharField(default='ssh', max_length=16, db_index=True)
|
protocol = models.CharField(default='ssh', max_length=16, db_index=True)
|
||||||
login_from = models.CharField(max_length=2, choices=LOGIN_FROM.choices, default="ST", verbose_name=_("Login from"))
|
login_from = models.CharField(max_length=2, choices=LOGIN_FROM.choices, default="ST", verbose_name=_("Login from"))
|
||||||
|
type = models.CharField(max_length=16, default='normal', db_index=True)
|
||||||
remote_addr = models.CharField(max_length=128, verbose_name=_("Remote addr"), blank=True, null=True)
|
remote_addr = models.CharField(max_length=128, verbose_name=_("Remote addr"), blank=True, null=True)
|
||||||
is_success = models.BooleanField(default=True, db_index=True)
|
is_success = models.BooleanField(default=True, db_index=True)
|
||||||
is_finished = models.BooleanField(default=False, db_index=True)
|
is_finished = models.BooleanField(default=False, db_index=True)
|
||||||
|
@ -42,6 +42,7 @@ class Session(OrgModelMixin):
|
||||||
terminal = models.ForeignKey('terminal.Terminal', null=True, on_delete=models.DO_NOTHING, db_constraint=False)
|
terminal = models.ForeignKey('terminal.Terminal', null=True, on_delete=models.DO_NOTHING, db_constraint=False)
|
||||||
date_start = models.DateTimeField(verbose_name=_("Date start"), db_index=True, default=timezone.now)
|
date_start = models.DateTimeField(verbose_name=_("Date start"), db_index=True, default=timezone.now)
|
||||||
date_end = models.DateTimeField(verbose_name=_("Date end"), null=True)
|
date_end = models.DateTimeField(verbose_name=_("Date end"), null=True)
|
||||||
|
comment = models.TextField(blank=True, null=True, verbose_name=_("Comment"))
|
||||||
|
|
||||||
upload_to = 'replay'
|
upload_to = 'replay'
|
||||||
ACTIVE_CACHE_KEY_PREFIX = 'SESSION_ACTIVE_{}'
|
ACTIVE_CACHE_KEY_PREFIX = 'SESSION_ACTIVE_{}'
|
||||||
|
|
Loading…
Reference in New Issue