Skip to content

Commit

Permalink
Bugfix for incorrect numbers for services
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Jan 21, 2022
1 parent 6e41bec commit 499ba2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
19 changes: 15 additions & 4 deletions server/api/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,21 @@ def override_func():
result_set = db.engine.execute(sql)
services_colls = [{"service_id": row[0], "collaboration_id": row[1]} for row in result_set]
services_json = jsonify(services).json
for index, service in enumerate(services):
service_json = services_json[index]
service_json["collaborations_count"] = len([s for s in services_colls if s["service_id"] == service.id])
service_json["organisations_count"] = len([s for s in service_orgs if s["service_id"] == service.id])
for service_json in services_json:
service_json["collaborations_count"] = len([s for s in services_colls if s["service_id"] == service_json["id"]])
service_json["organisations_count"] = 0
for s in service_orgs:
if s["service_id"] == service_json["id"]:
service_json["organisations_count"] += 1
count_query = f"SELECT id FROM collaborations WHERE organisation_id = {s['organisation_id']}"
result_set = db.engine.execute(text(count_query))
for row in result_set:
# Prevent double counts for directly linked collaborations
col_directly_linked = [c for c in services_colls
if
c["collaboration_id"] == row["id"] and c["service_id"] == service_json["id"]]
if not col_directly_linked:
service_json["collaborations_count"] += 1
return services_json, 200


Expand Down
4 changes: 4 additions & 0 deletions server/test/api/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ def test_services_all(self):
self.assertEqual(1, service_uuc["organisations_count"])
self.assertEqual(1, len(service_uuc["allowed_organisations"]))

service_wiki = self.find_by_name(services, service_wiki_name)
self.assertEqual(1, service_wiki["organisations_count"])
self.assertEqual(3, service_wiki["collaborations_count"])

def test_services_mine(self):
self.login("urn:service_admin")
services = self.get("/api/services/mine", with_basic_auth=False)
Expand Down

0 comments on commit 499ba2b

Please sign in to comment.