mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-11-16 09:34:03 +01:00
Few updates
This commit is contained in:
@@ -291,7 +291,10 @@ class IdPossibleActionsSerializer(serializers.Serializer):
|
||||
name = serializers.CharField()
|
||||
icon = serializers.CharField()
|
||||
label = serializers.CharField()
|
||||
body = serializers.DictField()
|
||||
type = serializers.CharField()
|
||||
content_type = serializers.CharField(required=False)
|
||||
url = serializers.CharField(required=False)
|
||||
filename = serializers.CharField(required=False)
|
||||
|
||||
|
||||
class IdentitySerializer(serializers.Serializer):
|
||||
|
||||
@@ -66,4 +66,4 @@ class GetAccountCredentialsSerializer(serializers.Serializer):
|
||||
self.context["content"] = decrypt_file(fname)
|
||||
if param_tools.get_global_parameter("delete_first_dl"):
|
||||
os.remove(fname)
|
||||
self.context["fname"] = fname
|
||||
self.context["fname"] = os.path.basename(fname)
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""PDF Credentials API v2 views."""
|
||||
|
||||
import os
|
||||
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.http import HttpResponse
|
||||
|
||||
@@ -26,14 +28,15 @@ class PDFCredentialView(APIView):
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""View to download a document."""
|
||||
data = {"account_id": kwargs["account_id"]}
|
||||
serializer = GetAccountCredentialsSerializer(data=data, context={'request': request})
|
||||
serializer = GetAccountCredentialsSerializer(
|
||||
data=data, context={'request': request})
|
||||
serializer.is_valid(raise_exception=True)
|
||||
serializer.save()
|
||||
|
||||
content = serializer.context["content"]
|
||||
fname = serializer.context["fname"]
|
||||
resp = HttpResponse(content)
|
||||
resp["Content-Type"] = "application/pdf;base64"
|
||||
resp["Content-Type"] = "application/pdf"
|
||||
resp["Content-Length"] = len(content)
|
||||
resp["Content-Disposition"] = f"attachment; filename={fname};"
|
||||
return resp
|
||||
|
||||
@@ -63,9 +63,14 @@ def extra_identities_actions(sender, account, **kwargs):
|
||||
fname = get_creds_filename(account)
|
||||
if not os.path.exists(fname):
|
||||
return []
|
||||
url: str = reverse("v2:get-credentials", args=[account.pk])
|
||||
url = url.replace("/api/v2", "")
|
||||
return {
|
||||
"name": "get_credentials",
|
||||
"body": {"type": "pdfcredentials"},
|
||||
"icon": "mdi-file-download-outline",
|
||||
"label": _("Download PDF credentials")
|
||||
"label": _("Download PDF credentials"),
|
||||
"type": "download",
|
||||
"content_type": "application/pdf",
|
||||
"url": url,
|
||||
"filename": os.path.basename(fname)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user