Merge pull request #9356 from jumpserver/pr@dev@perf_readme

perf: 优化 applet api
pull/9362/head
老广 2023-01-30 13:23:09 +08:00 committed by GitHub
commit 3f4814a392
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 11 additions and 2 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

View File

@ -87,6 +87,7 @@ class DownloadUploadMixin:
class AppletViewSet(DownloadUploadMixin, JMSBulkModelViewSet):
queryset = Applet.objects.all()
serializer_class = serializers.AppletSerializer
filterset_fields = ['name', 'version', 'builtin', 'is_active']
search_fields = ['name', 'display_name', 'author']
rbac_perms = {
'upload': 'terminal.add_applet',

View File

@ -1,4 +1,3 @@
## Navicat Premium
- 需要先手动导入License激活

View File

@ -11,6 +11,7 @@ from django.utils.translation import gettext_lazy as _
from rest_framework.serializers import ValidationError
from common.db.models import JMSBaseModel
from common.utils import lazyproperty
__all__ = ['Applet', 'AppletPublication']
@ -48,6 +49,14 @@ class Applet(JMSBaseModel):
else:
return default_storage.path('applets/{}'.format(self.name))
@lazyproperty
def readme(self):
readme_file = os.path.join(self.path, 'README.md')
if os.path.isfile(readme_file):
with open(readme_file, 'r') as f:
return f.read()
return ''
@property
def manifest(self):
path = os.path.join(self.path, 'manifest.yml')

View File

@ -31,7 +31,7 @@ class AppletSerializer(serializers.ModelSerializer):
model = Applet
fields_mini = ['id', 'name', 'display_name', 'is_active']
read_only_fields = [
'icon', 'date_created', 'date_updated',
'icon', 'readme', 'date_created', 'date_updated',
]
fields = fields_mini + [
'version', 'author', 'type', 'protocols',