diff sat/memory/memory.py @ 3523:30779935c0aa

core (memory, sqlite): new `fileGetUsedSpace` method
author Goffi <goffi@goffi.org>
date Wed, 05 May 2021 15:37:21 +0200
parents a83a04b7394b
children f9a5b810f14d
line wrap: on
line diff
--- a/sat/memory/memory.py	Wed May 05 12:58:11 2021 +0200
+++ b/sat/memory/memory.py	Wed May 05 15:37:21 2021 +0200
@@ -1456,8 +1456,8 @@
             client,
             owner: Optional[jid.JID],
             peer_jid: Optional[jid.JID],
-            file_id: Optional[str],
-            parent: Optional[str]
+            file_id: Optional[str] = None,
+            parent: Optional[str] = None
     ) -> jid.JID:
         """Get owner to use for a file operation
 
@@ -1709,6 +1709,24 @@
             extra=extra,
         )
 
+    async def fileGetUsedSpace(
+        self,
+        client,
+        peer_jid: jid.JID,
+        owner: Optional[jid.JID] = None
+    ) -> int:
+        """Get space taken by all files owned by an entity
+
+        @param peer_jid: entity requesting the size
+        @param owner: entity owning the file to check. If None, will be determined by
+            getFilesOwner
+        @return: size of total space used by files of this owner
+        """
+        owner = self.getFilesOwner(client, owner, peer_jid)
+        if peer_jid.userhostJID() != owner and client.profile not in self.admins:
+            raise exceptions.PermissionError("You are not allowed to check this size")
+        return await self.storage.fileGetUsedSpace(client, owner)
+
     def fileUpdate(self, file_id, column, update_cb):
         """Update a file column taking care of race condition