mirror of https://github.com/jumpserver/jumpserver
pref: applet detail api 支持 slug name
parent
f6fe673b28
commit
956367cfed
|
@ -1,19 +1,18 @@
|
|||
import shutil
|
||||
import zipfile
|
||||
from typing import Callable
|
||||
|
||||
import yaml
|
||||
import os.path
|
||||
from typing import Callable
|
||||
|
||||
from rest_framework import viewsets
|
||||
from django.http import HttpResponse
|
||||
from django.core.files.storage import default_storage
|
||||
from django.db.models import Prefetch
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.request import Request
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.serializers import ValidationError
|
||||
|
||||
from common.utils import is_uuid
|
||||
from terminal import serializers
|
||||
from terminal.models import AppletPublication, Applet
|
||||
from terminal.serializers import AppletUploadSerializer
|
||||
|
@ -98,6 +97,13 @@ class AppletViewSet(DownloadUploadMixin, viewsets.ModelViewSet):
|
|||
'download': 'terminal.view_applet',
|
||||
}
|
||||
|
||||
def get_object(self):
|
||||
pk = self.kwargs.get('pk')
|
||||
if not is_uuid(pk):
|
||||
return self.queryset.get(name=pk)
|
||||
else:
|
||||
return self.queryset.get(pk=pk)
|
||||
|
||||
def perform_destroy(self, instance):
|
||||
if not instance.name:
|
||||
raise ValidationError('Applet is not null')
|
||||
|
|
|
@ -21,7 +21,7 @@ class Migration(migrations.Migration):
|
|||
('date_created', models.DateTimeField(auto_now_add=True, null=True, verbose_name='Date created')),
|
||||
('date_updated', models.DateTimeField(auto_now=True, verbose_name='Date updated')),
|
||||
('id', models.UUIDField(default=uuid.uuid4, primary_key=True, serialize=False)),
|
||||
('name', models.CharField(max_length=128, unique=True, verbose_name='Name')),
|
||||
('name', models.SlugField(max_length=128, unique=True, verbose_name='Name')),
|
||||
('display_name', models.CharField(max_length=128, verbose_name='Display name')),
|
||||
('version', models.CharField(max_length=16, verbose_name='Version')),
|
||||
('author', models.CharField(max_length=128, verbose_name='Author')),
|
||||
|
|
|
@ -6,7 +6,6 @@ from django.core.files.storage import default_storage
|
|||
from django.db import models
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from common.utils import lazyproperty
|
||||
from common.db.models import JMSBaseModel
|
||||
|
||||
|
||||
|
@ -18,7 +17,7 @@ class Applet(JMSBaseModel):
|
|||
general = 'general', _('General')
|
||||
web = 'web', _('Web')
|
||||
|
||||
name = models.CharField(max_length=128, verbose_name=_('Name'), unique=True)
|
||||
name = models.SlugField(max_length=128, verbose_name=_('Name'), unique=True)
|
||||
display_name = models.CharField(max_length=128, verbose_name=_('Display name'))
|
||||
version = models.CharField(max_length=16, verbose_name=_('Version'))
|
||||
author = models.CharField(max_length=128, verbose_name=_('Author'))
|
||||
|
|
|
@ -68,7 +68,8 @@ class TicketApproveSerializer(TicketSerializer):
|
|||
|
||||
class TicketApplySerializer(TicketSerializer):
|
||||
org_id = serializers.CharField(
|
||||
required=True, max_length=36, allow_blank=True, label=_("Organization")
|
||||
required=True, max_length=36,
|
||||
allow_blank=True, label=_("Organization")
|
||||
)
|
||||
|
||||
class Meta:
|
||||
|
@ -92,7 +93,8 @@ class TicketApplySerializer(TicketSerializer):
|
|||
|
||||
ticket_type = attrs.get('type')
|
||||
org_id = attrs.get('org_id')
|
||||
flow = TicketFlow.get_org_related_flows(org_id=org_id).filter(type=ticket_type).first()
|
||||
flow = TicketFlow.get_org_related_flows(org_id=org_id)\
|
||||
.filter(type=ticket_type).first()
|
||||
if flow:
|
||||
attrs['flow'] = flow
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue