]> git.ipfire.org Git - pbs.git/commitdiff
hub: Implement listing all uploads
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 15:49:28 +0000 (15:49 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Oct 2022 15:49:28 +0000 (15:49 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/users.py
src/hub/uploads.py

index 4dd2a498cd5586371d2c6b9e97b97d442a9d4e03..65d089482099cf379aef832118380e9a8616ca2b 100644 (file)
@@ -540,6 +540,27 @@ class User(base.DataObject):
                        slug,
                )
 
+       @property
+       def uploads(self):
+               """
+                       Returns all uploads that belong to this user
+               """
+               uploads = self.backend.uploads._get_uploads("""
+                       SELECT
+                               *
+                       FROM
+                               uploads
+                       WHERE
+                               user_id = %s
+                       AND
+                               expires_at > CURRENT_TIMESTAMP
+                       ORDER BY
+                               created_at DESC
+                       """, self.id,
+               )
+
+               return list(uploads)
+
 
 class QuotaExceededError(Exception):
        pass
index 86ab35d7459a19d539600278e856450b984519b4..88797de189937e27b2d9f2baa6515718d6d4992f 100644 (file)
@@ -37,6 +37,25 @@ class IndexHandler(BaseHandler):
                """
                self.buffer.write(data)
 
+       @tornado.web.authenticated
+       def get(self):
+               uploads = []
+
+               for upload in self.current_user.uploads:
+                       uploads.append({
+                               "id"         : upload.uuid,
+                               "filename"   : upload.filename,
+                               "size"       : upload.size,
+
+                               "created_at" : upload.created_at.isoformat(),
+                               "expires_at" : upload.expires_at.isoformat(),
+                       })
+
+               self.finish({
+                       "status"  : "ok",
+                       "uploads" : uploads,
+               })
+
        @tornado.web.authenticated
        async def put(self):
                """