mirror of https://github.com/jumpserver/jumpserver
perf: 修改账号生成
parent
4000986d1d
commit
240f700b92
|
@ -19,6 +19,9 @@ class AppletHostViewSet(JMSBulkModelViewSet):
|
||||||
serializer_class = AppletHostSerializer
|
serializer_class = AppletHostSerializer
|
||||||
queryset = AppletHost.objects.all()
|
queryset = AppletHost.objects.all()
|
||||||
search_fields = ['asset_ptr__name', 'asset_ptr__address', ]
|
search_fields = ['asset_ptr__name', 'asset_ptr__address', ]
|
||||||
|
rbac_perms = {
|
||||||
|
'generate_accounts': 'terminal.change_applethost',
|
||||||
|
}
|
||||||
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
def dispatch(self, request, *args, **kwargs):
|
||||||
with tmp_to_builtin_org(system=1):
|
with tmp_to_builtin_org(system=1):
|
||||||
|
@ -37,6 +40,12 @@ class AppletHostViewSet(JMSBulkModelViewSet):
|
||||||
instance.check_terminal_binding(request)
|
instance.check_terminal_binding(request)
|
||||||
return Response({'msg': 'ok'})
|
return Response({'msg': 'ok'})
|
||||||
|
|
||||||
|
@action(methods=['put'], detail=True, url_path='generate-accounts')
|
||||||
|
def generate_accounts(self, request, *args, **kwargs):
|
||||||
|
instance = self.get_object()
|
||||||
|
instance.generate_accounts()
|
||||||
|
return Response({'msg': 'ok'})
|
||||||
|
|
||||||
|
|
||||||
class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = AppletHostDeploymentSerializer
|
serializer_class = AppletHostDeploymentSerializer
|
||||||
|
|
|
@ -125,6 +125,7 @@ class AppletHost(Host):
|
||||||
.filter(is_active=True, is_service_account=False) \
|
.filter(is_active=True, is_service_account=False) \
|
||||||
.values_list('username', flat=True)
|
.values_list('username', flat=True)
|
||||||
account_usernames = self.accounts.all().values_list('username', flat=True)
|
account_usernames = self.accounts.all().values_list('username', flat=True)
|
||||||
|
account_usernames = [username[3:] for username in account_usernames if username.startswith('js_')]
|
||||||
not_exist_users = set(usernames) - set(account_usernames)
|
not_exist_users = set(usernames) - set(account_usernames)
|
||||||
self.generate_private_accounts_by_usernames(not_exist_users)
|
self.generate_private_accounts_by_usernames(not_exist_users)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue