mirror of https://github.com/jumpserver/jumpserver
pref: 修改 accounts
commit
7f0744961d
|
@ -1,7 +1,12 @@
|
||||||
from django.shortcuts import get_object_or_404
|
from django.shortcuts import get_object_or_404
|
||||||
from rest_framework.generics import ListAPIView, get_object_or_404
|
from rest_framework.generics import ListAPIView, get_object_or_404
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
from common.utils import get_logger, lazyproperty
|
from common.utils import get_logger, lazyproperty
|
||||||
|
=======
|
||||||
|
from common.exceptions import JMSObjectDoesNotExist
|
||||||
|
from common.utils import get_logger, lazyproperty, is_uuid
|
||||||
|
>>>>>>> 0d3c5dddf9c838c5dcd28c20b6a8498088e45ce2
|
||||||
from perms import serializers
|
from perms import serializers
|
||||||
from perms.hands import Asset
|
from perms.hands import Asset
|
||||||
from perms.utils import PermAccountUtil
|
from perms.utils import PermAccountUtil
|
||||||
|
@ -17,10 +22,25 @@ __all__ = [
|
||||||
class UserGrantedAssetAccountsApi(SelfOrPKUserMixin, ListAPIView):
|
class UserGrantedAssetAccountsApi(SelfOrPKUserMixin, ListAPIView):
|
||||||
serializer_class = serializers.AccountsGrantedSerializer
|
serializer_class = serializers.AccountsGrantedSerializer
|
||||||
rbac_perms = (
|
rbac_perms = (
|
||||||
|
('GET', 'perms.view_userassets'),
|
||||||
('list', 'perms.view_userassets'),
|
('list', 'perms.view_userassets'),
|
||||||
)
|
)
|
||||||
|
|
||||||
@lazyproperty
|
@lazyproperty
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
def user(self) -> User:
|
||||||
|
query_user = self.kwargs.get('user')
|
||||||
|
if is_uuid(query_user):
|
||||||
|
user = User.objects.get(id=query_user)
|
||||||
|
elif query_user == 'my':
|
||||||
|
user = self.request.user
|
||||||
|
else:
|
||||||
|
raise JMSObjectDoesNotExist(object_name=_('User'))
|
||||||
|
return user
|
||||||
|
|
||||||
|
@lazyproperty
|
||||||
|
>>>>>>> 0d3c5dddf9c838c5dcd28c20b6a8498088e45ce2
|
||||||
def asset(self):
|
def asset(self):
|
||||||
asset_id = self.kwargs.get('asset_id')
|
asset_id = self.kwargs.get('asset_id')
|
||||||
kwargs = {'id': asset_id, 'is_active': True}
|
kwargs = {'id': asset_id, 'is_active': True}
|
||||||
|
|
|
@ -49,6 +49,7 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
instance = serializer.save()
|
instance = serializer.save()
|
||||||
task = run_applet_host_deployment.delay(instance.id)
|
task = run_applet_host_deployment.delay(instance.id)
|
||||||
|
instance.save_task(task.id)
|
||||||
return Response({'task': str(task.id)}, status=201)
|
return Response({'task': str(task.id)}, status=201)
|
||||||
|
|
||||||
@action(methods=['post'], detail=False, serializer_class=AppletHostDeployAppletSerializer)
|
@action(methods=['post'], detail=False, serializer_class=AppletHostDeployAppletSerializer)
|
||||||
|
@ -58,4 +59,5 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||||
applet_id = serializer.validated_data.get('applet_id')
|
applet_id = serializer.validated_data.get('applet_id')
|
||||||
instance = serializer.save()
|
instance = serializer.save()
|
||||||
task = run_applet_host_deployment_install_applet.delay(instance.id, applet_id)
|
task = run_applet_host_deployment_install_applet.delay(instance.id, applet_id)
|
||||||
|
instance.save_task(task.id)
|
||||||
return Response({'task': str(task.id)}, status=201)
|
return Response({'task': str(task.id)}, status=201)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2.14 on 2022-11-15 05:53
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('terminal', '0058_auto_20221103_1624'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='applethostdeployment',
|
||||||
|
name='task',
|
||||||
|
field=models.UUIDField(null=True, verbose_name='Task'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -105,6 +105,7 @@ class AppletHostDeployment(JMSBaseModel):
|
||||||
date_start = models.DateTimeField(null=True, verbose_name=_('Date start'), db_index=True)
|
date_start = models.DateTimeField(null=True, verbose_name=_('Date start'), db_index=True)
|
||||||
date_finished = models.DateTimeField(null=True, verbose_name=_("Date finished"))
|
date_finished = models.DateTimeField(null=True, verbose_name=_("Date finished"))
|
||||||
comment = models.TextField(default='', blank=True, verbose_name=_('Comment'))
|
comment = models.TextField(default='', blank=True, verbose_name=_('Comment'))
|
||||||
|
task = models.UUIDField(null=True, verbose_name=_('Task'))
|
||||||
|
|
||||||
def start(self, **kwargs):
|
def start(self, **kwargs):
|
||||||
from ...automations.deploy_applet_host import DeployAppletHostManager
|
from ...automations.deploy_applet_host import DeployAppletHostManager
|
||||||
|
@ -120,3 +121,7 @@ class AppletHostDeployment(JMSBaseModel):
|
||||||
applet = None
|
applet = None
|
||||||
manager = DeployAppletHostManager(self, applet=applet)
|
manager = DeployAppletHostManager(self, applet=applet)
|
||||||
manager.install_applet(**kwargs)
|
manager.install_applet(**kwargs)
|
||||||
|
|
||||||
|
def save_task(self, task):
|
||||||
|
self.task = task
|
||||||
|
self.save(update_fields=['task'])
|
||||||
|
|
|
@ -86,7 +86,7 @@ class HostAppletSerializer(AppletSerializer):
|
||||||
class AppletHostDeploymentSerializer(serializers.ModelSerializer):
|
class AppletHostDeploymentSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = AppletHostDeployment
|
model = AppletHostDeployment
|
||||||
fields_mini = ['id', 'host', 'status']
|
fields_mini = ['id', 'host', 'status', 'task']
|
||||||
read_only_fields = [
|
read_only_fields = [
|
||||||
'status', 'date_created', 'date_updated',
|
'status', 'date_created', 'date_updated',
|
||||||
'date_start', 'date_finished'
|
'date_start', 'date_finished'
|
||||||
|
|
Loading…
Reference in New Issue