From 76deb56aad57ae213f01338f3a7b389f4120f05f Mon Sep 17 00:00:00 2001 From: valyo <582646+valyo@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:36:03 +0200 Subject: [PATCH 1/5] add Is Active to project info --- dds_web/api/project.py | 1 + 1 file changed, 1 insertion(+) diff --git a/dds_web/api/project.py b/dds_web/api/project.py index 1bd40111b..dc0745c70 100644 --- a/dds_web/api/project.py +++ b/dds_web/api/project.py @@ -480,6 +480,7 @@ def format_project_dict(self, current_user): "PI": p.pi, "Status": p.current_status, "Last updated": p.date_updated if p.date_updated else p.date_created, + "Is Active": p.is_active } # Get proj size and update total size From 24b2c57d545c416a71fb59f9ea069b391d9fcfb6 Mon Sep 17 00:00:00 2001 From: valyo <582646+valyo@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:38:26 +0200 Subject: [PATCH 2/5] black --- dds_web/api/project.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dds_web/api/project.py b/dds_web/api/project.py index dc0745c70..d8187d7d3 100644 --- a/dds_web/api/project.py +++ b/dds_web/api/project.py @@ -480,7 +480,7 @@ def format_project_dict(self, current_user): "PI": p.pi, "Status": p.current_status, "Last updated": p.date_updated if p.date_updated else p.date_created, - "Is Active": p.is_active + "Is Active": p.is_active, } # Get proj size and update total size From 35711a7f518cf6ca7d5a939b475f016f783ee75a Mon Sep 17 00:00:00 2001 From: valyo <582646+valyo@users.noreply.github.com> Date: Fri, 14 Oct 2022 09:19:02 +0200 Subject: [PATCH 3/5] Ina's review suggestion --- dds_web/api/project.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/dds_web/api/project.py b/dds_web/api/project.py index d8187d7d3..ca151df9f 100644 --- a/dds_web/api/project.py +++ b/dds_web/api/project.py @@ -472,15 +472,26 @@ def format_project_dict(self, current_user): "Unit Personnel", ] + # Get info for projects + get_all = flask.request.json.get("show_all", False) if flask.request.json else False + all_filters = ( + [] if get_all else [models.Project.is_active == True] + ) # Default is to only get active projects + all_filters.append( + models.Project.public_id.in_([x.public_id for x in current_user.projects]) + ) + + # Apply the filters + user_projects = models.Project.query.filter(sqlalchemy.and_(*all_filters)).all() + # Get info for all projects - for p in current_user.projects: + for p in user_projects: project_info = { "Project ID": p.public_id, "Title": p.title, "PI": p.pi, "Status": p.current_status, "Last updated": p.date_updated if p.date_updated else p.date_created, - "Is Active": p.is_active, } # Get proj size and update total size From 06f6d6863b25d7d22da80b08e84762cd1d8edb3f Mon Sep 17 00:00:00 2001 From: valyo <582646+valyo@users.noreply.github.com> Date: Wed, 19 Oct 2022 10:14:42 +0200 Subject: [PATCH 4/5] tests --- tests/test_project_listing.py | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/test_project_listing.py b/tests/test_project_listing.py index 1f4e71cdf..1c17fcfaa 100644 --- a/tests/test_project_listing.py +++ b/tests/test_project_listing.py @@ -5,6 +5,7 @@ import unittest # Own +from dds_web import db from dds_web.database import models import tests @@ -57,6 +58,46 @@ def test_list_proj_unit_user(client): assert "Usage" in public_project.keys() and public_project["Usage"] is not None +def test_list_only_active_projects_unit_user(client): + """Unit admin should be able to list only active projects without --show-all flag""" + + # set one of the project as inactive + inactive_project: models.Project = models.Project.query.first() + inactive_project.is_active = False + db.session.commit() + + token = tests.UserAuth(tests.USER_CREDENTIALS["unitadmin"]).token(client) + response = client.get( + tests.DDSEndpoint.LIST_PROJ, + headers=token, + json={"usage": True}, + content_type="application/json", + ) + + assert response.status_code == http.HTTPStatus.OK + assert len(response.json.get("project_info")) == 4 + + +def test_list_all_projects_unit_user(client): + """Unit admin should be able to list inactive projects with the --show-all flag""" + + # set one of the project as inactive + inactive_project: models.Project = models.Project.query.first() + inactive_project.is_active = False + db.session.commit() + + token = tests.UserAuth(tests.USER_CREDENTIALS["unitadmin"]).token(client) + response = client.get( + tests.DDSEndpoint.LIST_PROJ, + headers=token, + json={"usage": True, "show_all": True}, + content_type="application/json", + ) + + assert response.status_code == http.HTTPStatus.OK + assert len(response.json.get("project_info")) == 5 + + def test_proj_private_successful(client): """Successfully get the private key""" From f6c434c36bade337e478fb0547b6851c3609316c Mon Sep 17 00:00:00 2001 From: valyo <582646+valyo@users.noreply.github.com> Date: Wed, 19 Oct 2022 10:34:14 +0200 Subject: [PATCH 5/5] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c6ba7b8f..8f8999c3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -156,3 +156,7 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe - Bug fix: Fix the Invite.projects database model ([#1290](https://github.com/ScilifelabDataCentre/dds_web/pull/1290)) - New endpoint: ListInvites - list invites ([#1294](https://github.com/ScilifelabDataCentre/dds_web/pull/1294)) + +## Sprint (2022-10-14 - 2022-10-28) + +- Limit projects listing to active projects only; a `--show-all` flag can be used for listing all projects, active and inactive ([#1302](https://github.com/ScilifelabDataCentre/dds_web/pull/1302))