mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-08-08 09:38:30 +00:00
perf: Resurrection kael
This commit is contained in:
parent
537a9325a3
commit
c345674402
@ -11,6 +11,7 @@ from accounts.const import ChangeSecretRecordStatusChoice
|
|||||||
from accounts.filters import AccountFilterSet, NodeFilterBackend
|
from accounts.filters import AccountFilterSet, NodeFilterBackend
|
||||||
from accounts.mixins import AccountRecordViewLogMixin
|
from accounts.mixins import AccountRecordViewLogMixin
|
||||||
from accounts.models import Account, ChangeSecretRecord
|
from accounts.models import Account, ChangeSecretRecord
|
||||||
|
from assets.const.gpt import create_or_update_chatx_resources
|
||||||
from assets.models import Asset, Node
|
from assets.models import Asset, Node
|
||||||
from authentication.permissions import UserConfirmation, ConfirmType
|
from authentication.permissions import UserConfirmation, ConfirmType
|
||||||
from common.api.mixin import ExtraFilterFieldsMixin
|
from common.api.mixin import ExtraFilterFieldsMixin
|
||||||
@ -18,6 +19,7 @@ from common.drf.filters import AttrRulesFilterBackend
|
|||||||
from common.permissions import IsValidUser
|
from common.permissions import IsValidUser
|
||||||
from common.utils import lazyproperty, get_logger
|
from common.utils import lazyproperty, get_logger
|
||||||
from orgs.mixins.api import OrgBulkModelViewSet
|
from orgs.mixins.api import OrgBulkModelViewSet
|
||||||
|
from orgs.utils import tmp_to_root_org
|
||||||
from rbac.permissions import RBACPermission
|
from rbac.permissions import RBACPermission
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
@ -43,6 +45,7 @@ class AccountViewSet(OrgBulkModelViewSet):
|
|||||||
'clear_secret': 'accounts.change_account',
|
'clear_secret': 'accounts.change_account',
|
||||||
'move_to_assets': 'accounts.create_account',
|
'move_to_assets': 'accounts.create_account',
|
||||||
'copy_to_assets': 'accounts.create_account',
|
'copy_to_assets': 'accounts.create_account',
|
||||||
|
'chat': 'accounts.view_account',
|
||||||
}
|
}
|
||||||
export_as_zip = True
|
export_as_zip = True
|
||||||
|
|
||||||
@ -145,6 +148,13 @@ class AccountViewSet(OrgBulkModelViewSet):
|
|||||||
def copy_to_assets(self, request, *args, **kwargs):
|
def copy_to_assets(self, request, *args, **kwargs):
|
||||||
return self._copy_or_move_to_assets(request, move=False)
|
return self._copy_or_move_to_assets(request, move=False)
|
||||||
|
|
||||||
|
@action(methods=['get'], detail=False, url_path='chat')
|
||||||
|
def chat(self, request, *args, **kwargs):
|
||||||
|
with tmp_to_root_org():
|
||||||
|
account = create_or_update_chatx_resources()
|
||||||
|
serializer = self.get_serializer(account)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
||||||
|
|
||||||
class AccountSecretsViewSet(AccountRecordViewLogMixin, AccountViewSet):
|
class AccountSecretsViewSet(AccountRecordViewLogMixin, AccountViewSet):
|
||||||
"""
|
"""
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from orgs.models import Organization
|
||||||
from .base import BaseType
|
from .base import BaseType
|
||||||
|
|
||||||
|
CHATX_NAME = 'ChatX'
|
||||||
|
|
||||||
|
|
||||||
class GPTTypes(BaseType):
|
class GPTTypes(BaseType):
|
||||||
CHATGPT = 'chatgpt', _('ChatGPT')
|
CHATGPT = 'chatgpt', _('ChatGPT')
|
||||||
@ -52,3 +55,38 @@ class GPTTypes(BaseType):
|
|||||||
return [
|
return [
|
||||||
cls.CHATGPT,
|
cls.CHATGPT,
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def create_or_update_chatx_resources(chatx_name=CHATX_NAME, org_id=Organization.SYSTEM_ID):
|
||||||
|
from django.apps import apps
|
||||||
|
|
||||||
|
platform_model = apps.get_model('assets', 'Platform')
|
||||||
|
asset_model = apps.get_model('assets', 'Asset')
|
||||||
|
account_model = apps.get_model('accounts', 'Account')
|
||||||
|
|
||||||
|
platform, _ = platform_model.objects.update_or_create(
|
||||||
|
name=chatx_name,
|
||||||
|
defaults={
|
||||||
|
'internal': True,
|
||||||
|
'type': chatx_name,
|
||||||
|
'category': 'ai',
|
||||||
|
}
|
||||||
|
)
|
||||||
|
asset, __ = asset_model.objects.update_or_create(
|
||||||
|
address=chatx_name,
|
||||||
|
defaults={
|
||||||
|
'name': chatx_name,
|
||||||
|
'platform': platform,
|
||||||
|
'org_id': org_id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
account, __ = account_model.objects.update_or_create(
|
||||||
|
username=chatx_name,
|
||||||
|
defaults={
|
||||||
|
'name': chatx_name,
|
||||||
|
'asset': asset,
|
||||||
|
'org_id': org_id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
return account
|
||||||
|
19
apps/assets/migrations/0019_auto_20250403_1759.py
Normal file
19
apps/assets/migrations/0019_auto_20250403_1759.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 4.1.13 on 2025-04-03 09:59
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
from assets.const.gpt import create_or_update_chatx_resources
|
||||||
|
|
||||||
|
|
||||||
|
def migrate_chat_platform_asset_account(apps, schema_editor):
|
||||||
|
create_or_update_chatx_resources()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('assets', '0018_rename_domain_zone'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(migrate_chat_platform_asset_account)
|
||||||
|
]
|
@ -65,6 +65,7 @@ class PrivateSettingSerializer(PublicSettingSerializer):
|
|||||||
CHAT_AI_ENABLED = serializers.BooleanField()
|
CHAT_AI_ENABLED = serializers.BooleanField()
|
||||||
CHAT_AI_TYPE = serializers.CharField()
|
CHAT_AI_TYPE = serializers.CharField()
|
||||||
GPT_MODEL = serializers.CharField()
|
GPT_MODEL = serializers.CharField()
|
||||||
|
DEEPSEEK_MODEL = serializers.CharField()
|
||||||
FILE_UPLOAD_SIZE_LIMIT_MB = serializers.IntegerField()
|
FILE_UPLOAD_SIZE_LIMIT_MB = serializers.IntegerField()
|
||||||
FTP_FILE_MAX_STORE = serializers.IntegerField()
|
FTP_FILE_MAX_STORE = serializers.IntegerField()
|
||||||
LOKI_LOG_ENABLED = serializers.BooleanField()
|
LOKI_LOG_ENABLED = serializers.BooleanField()
|
||||||
|
Loading…
Reference in New Issue
Block a user