diff --git a/CHANGELOG.md b/CHANGELOG.md index 75a59ef4d..77ced2089 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -134,3 +134,7 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe - Add Technical Overview page with links to Confluence and to a PDF download ([#1250](https://github.com/ScilifelabDataCentre/dds_web/pull/1250)) - Technical Overview moved to repository ([#1250](https://github.com/ScilifelabDataCentre/dds_web/pull/1253)) - Troubleshooting document moved to repository and buttons added to web to link and download ([#1255](https://github.com/ScilifelabDataCentre/dds_web/pull/1255)) + +## Sprint (2022-09-02 - 2022-09-16) + +- Add storage usage information in the Units listing table for Super Admin ([#1264](https://github.com/ScilifelabDataCentre/dds_web/pull/1264)) diff --git a/dds_web/api/superadmin_only.py b/dds_web/api/superadmin_only.py index 45fa12a9f..b9c67e591 100644 --- a/dds_web/api/superadmin_only.py +++ b/dds_web/api/superadmin_only.py @@ -46,6 +46,7 @@ def get(self): "Safespring Endpoint": u.safespring_endpoint, "Days In Available": u.days_in_available, "Days In Expired": u.days_in_expired, + "Size": u.size, } for u in all_units ] @@ -60,6 +61,7 @@ def get(self): "Days In Expired", "Safespring Endpoint", "Contact Email", + "Size", ], } diff --git a/dds_web/database/models.py b/dds_web/database/models.py index 25abfe2db..1459f23a3 100644 --- a/dds_web/database/models.py +++ b/dds_web/database/models.py @@ -209,6 +209,12 @@ def __repr__(self): """Called by print, creates representation of object""" return f"" + @property + def size(self): + """Calculate size of unit - current total storage usage.""" + + return sum([p.size for p in self.projects]) + class Project(db.Model): """ diff --git a/tests/api/test_superadmin_only.py b/tests/api/test_superadmin_only.py index c83a62c64..428a2acfc 100644 --- a/tests/api/test_superadmin_only.py +++ b/tests/api/test_superadmin_only.py @@ -73,6 +73,7 @@ def test_list_units_as_super_admin(client: flask.testing.FlaskClient) -> None: "Days In Expired", "Safespring Endpoint", "Contact Email", + "Size", ] assert len(all_units) == len(units) @@ -85,7 +86,14 @@ def test_list_units_as_super_admin(client: flask.testing.FlaskClient) -> None: "Safespring Endpoint": unit.safespring_endpoint, "Days In Available": unit.days_in_available, "Days In Expired": unit.days_in_expired, + "Size": unit.size, } + + correct_size: int = 0 + for project in unit.projects: + for file in project.files: + correct_size += file.size_stored + assert correct_size == unit.size assert expected in units