From a43c8d29b2501222cf519be5c21c449e4b4b5317 Mon Sep 17 00:00:00 2001 From: James B Date: Thu, 7 Sep 2023 08:36:17 +0100 Subject: [PATCH] Organisation public data - adds flags to API https://github.com/INDIGO-Initiative/database-app/issues/180 Adds flags to API only Ideally would add to other data sources - eg spreadsheet downloads But there is no current place in code to easily do that can't add to updatedata.py as we are at risk of introducing a circular update path (we would need to make updates to projects & pipelines also update orgs but updates to orgs can already also update projects!) Adding to API for now, as this satisfies immediate user need: to be able to distingusish in public https://golab.bsg.ox.ac.uk/ website --- indigo/models.py | 18 ++++++++++++++++++ indigo/views_api1.py | 2 ++ 2 files changed, 20 insertions(+) diff --git a/indigo/models.py b/indigo/models.py index 7cba638..99901c5 100755 --- a/indigo/models.py +++ b/indigo/models.py @@ -82,6 +82,24 @@ class Meta: class Organisation(BaseModel): type_id = TYPE_ORGANISATION_PUBLIC_ID + def is_in_any_public_projects(self): + """Note this includes if the organisation reference is private but the project is public. + https://github.com/INDIGO-Initiative/database-app/issues/180""" + return bool( + self.included_by_projects.filter( + project__status_public=True, in_current_data=True + ) + ) + + def is_in_any_public_pipelines(self): + """Note this includes if the organisation reference is private but the pipeline is public. + https://github.com/INDIGO-Initiative/database-app/issues/180""" + return bool( + self.included_by_pipelines.filter( + pipeline__status_public=True, in_current_data=True + ) + ) + class ProjectManager(models.Manager): def filter_by_admin_user_can_access(self, user): diff --git a/indigo/views_api1.py b/indigo/views_api1.py index c2c0828..23602be 100755 --- a/indigo/views_api1.py +++ b/indigo/views_api1.py @@ -76,6 +76,8 @@ def api1_organisation_index(request, public_id): "organisation": { "id": organisation.public_id, "data": organisation.data_public, + "is_in_any_public_projects": organisation.is_in_any_public_projects(), + "is_in_any_public_pipelines": organisation.is_in_any_public_pipelines(), } } return JsonResponse(data)