mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-03 00:15:20 +00:00
perf: connection token
This commit is contained in:
@@ -29,9 +29,9 @@ from terminal.models import EndpointRule, Endpoint
|
||||
from users.const import FileNameConflictResolution
|
||||
from users.const import RDPSmartSize, RDPColorQuality
|
||||
from users.models import Preference
|
||||
from ..models import ConnectionToken, AdminConnectionToken, date_expired_default
|
||||
from .face import FaceMonitorContext
|
||||
from ..mixins import AuthFaceMixin
|
||||
from ..models import ConnectionToken, AdminConnectionToken, date_expired_default
|
||||
from ..serializers import (
|
||||
ConnectionTokenSerializer, ConnectionTokenSecretSerializer,
|
||||
SuperConnectionTokenSerializer, ConnectTokenAppletOptionSerializer,
|
||||
@@ -442,9 +442,12 @@ class ConnectionTokenViewSet(AuthFaceMixin, ExtraActionApiMixin, RootOrgViewMixi
|
||||
return data
|
||||
|
||||
@staticmethod
|
||||
def _validate_perm(user, asset, account_name, protocol):
|
||||
def get_permed_account(user, asset, account_name, protocol):
|
||||
from perms.utils.asset_perm import PermAssetDetailUtil
|
||||
account = PermAssetDetailUtil(user, asset).validate_permission(account_name, protocol)
|
||||
return PermAssetDetailUtil(user, asset).validate_permission(account_name, protocol)
|
||||
|
||||
def _validate_perm(self, user, asset, account_name, protocol):
|
||||
account = self.get_permed_account(user, asset, account_name, protocol)
|
||||
if not account or not account.actions:
|
||||
msg = _('Account not found')
|
||||
raise JMSException(code='perm_account_invalid', detail=msg)
|
||||
@@ -675,3 +678,10 @@ class AdminConnectionTokenViewSet(ConnectionTokenViewSet):
|
||||
|
||||
def get_queryset(self):
|
||||
return AdminConnectionToken.objects.all()
|
||||
|
||||
def get_permed_account(self, user, asset, account_name, protocol):
|
||||
with tmp_to_org(asset.org):
|
||||
account = asset.accounts.all().active().get(name=account_name)
|
||||
account.actions = ActionChoices.all()
|
||||
account.date_expired = timezone.now() + timezone.timedelta(days=365)
|
||||
return account
|
||||
|
@@ -19,6 +19,7 @@ from common.utils import lazyproperty, pretty_string, bulk_get
|
||||
from common.utils.timezone import as_current_tz
|
||||
from orgs.mixins.models import JMSOrgBaseModel
|
||||
from orgs.utils import tmp_to_org
|
||||
from perms.const import ActionChoices
|
||||
from terminal.models import Applet, VirtualApp
|
||||
|
||||
|
||||
@@ -306,3 +307,14 @@ class AdminConnectionToken(ConnectionToken):
|
||||
class Meta:
|
||||
proxy = True
|
||||
verbose_name = _("Admin connection token")
|
||||
|
||||
@lazyproperty
|
||||
def actions(self):
|
||||
return ActionChoices.all()
|
||||
|
||||
@lazyproperty
|
||||
def expire_at(self):
|
||||
return (timezone.now() + timezone.timedelta(days=365)).timestamp()
|
||||
|
||||
def is_valid(self):
|
||||
return True
|
||||
|
Reference in New Issue
Block a user