changeset 3529:698579bedd6f

component file sharing (plugin management): new command to get available quota/used space.
author Goffi <goffi@goffi.org>
date Wed, 05 May 2021 15:37:33 +0200
parents 849374e59178
children fad3b3ffa8fe
files sat/plugins/plugin_comp_file_sharing_management.py sat/plugins/plugin_xep_0050.py
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/sat/plugins/plugin_comp_file_sharing_management.py	Wed May 05 15:37:33 2021 +0200
+++ b/sat/plugins/plugin_comp_file_sharing_management.py	Wed May 05 15:37:33 2021 +0200
@@ -23,6 +23,7 @@
 from sat.core import exceptions
 from sat.core.constants import Const as C
 from sat.core.log import getLogger
+from sat.tools.common import utils
 from wokkel import data_form
 from twisted.internet import defer
 from twisted.words.protocols.jabber import jid
@@ -50,6 +51,7 @@
 NS_FILE_MANAGEMENT_PERM = "https://salut-a-toi.org/protocol/file-management:0#perm"
 NS_FILE_MANAGEMENT_DELETE = "https://salut-a-toi.org/protocol/file-management:0#delete"
 NS_FILE_MANAGEMENT_THUMB = "https://salut-a-toi.org/protocol/file-management:0#thumb"
+NS_FILE_MANAGEMENT_QUOTA = "https://salut-a-toi.org/protocol/file-management:0#quota"
 
 
 class WorkflowError(Exception):
@@ -98,6 +100,11 @@
             node=NS_FILE_MANAGEMENT_THUMB,
             allowed_magics=C.ENTITY_ALL,
         )
+        self._c.addAdHocCommand(
+            client, self._onQuota, "Get Quota",
+            node=NS_FILE_MANAGEMENT_QUOTA,
+            allowed_magics=C.ENTITY_ALL,
+        )
 
     def _delete(self, service_jid_s, path, namespace, profile):
         client = self.host.getClient(profile)
@@ -458,3 +465,24 @@
             payload = None
             note = (self._c.NOTE.INFO, _("thumbnails generated"))
             defer.returnValue((payload, status, None, note))
+
+    async def _onQuota(self, client, command_elt, session_data, action, node):
+        requestor = session_data['requestor']
+        quota = self.host.plugins["file_sharing"].getQuota(client, requestor)
+        try:
+            size_used = await self.host.memory.fileGetUsedSpace(client, requestor)
+        except exceptions.PermissionError:
+            raise WorkflowError(self._err(_("forbidden")))
+        status = self._c.STATUS.COMPLETED
+        payload = None
+        note = (
+            self._c.NOTE.INFO,
+            _("You are currently using {size_used} on {size_quota}").format(
+                size_used = utils.getHumanSize(size_used),
+                size_quota = (
+                    _("unlimited quota") if quota is None
+                    else utils.getHumanSize(quota)
+                )
+            )
+        )
+        return (payload, status, None, note)
--- a/sat/plugins/plugin_xep_0050.py	Wed May 05 15:37:33 2021 +0200
+++ b/sat/plugins/plugin_xep_0050.py	Wed May 05 15:37:33 2021 +0200
@@ -34,7 +34,7 @@
 from sat.core.xmpp import SatXMPPEntity
 from sat.core import exceptions
 from sat.memory.memory import Sessions
-from sat.tools import xml_tools
+from sat.tools import xml_tools, utils
 from sat.tools.common import data_format
 
 
@@ -233,7 +233,7 @@
         if action == XEP_0050.ACTION.CANCEL:
             d = defer.succeed((None, XEP_0050.STATUS.CANCELED, None, None))
         else:
-            d = defer.maybeDeferred(
+            d = utils.asDeferred(
                 self.callback,
                 self.client,
                 command_elt,