Repository: CTFd/CTFd
Pull request #2494 (2024-03-15 08:23:20)

Return more fields in ScoreboardDetail
Linked to issue https://github.com/CTFd/CTFd/issues/2493

When using CTFd API, I would expect `ScoreboardDetail` to return more information than `ScoreboardList`. JavaScript codes need to query twice the API then merge information.

This patch proposes to expose more fields for each standing in `ScoreboardDetail`.

*Note: renaming `id` to `account_id` would be nice, but it would break backward compatibility, so I'm not proposing that.*

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/CTFd/CTFd/pull/2494?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CTFd) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 85.32%. Comparing base [(`fde98ce`)](https://app.codecov.io/gh/CTFd/CTFd/commit/fde98ce6f7e3e0a5f0a750374e8263d8f7f4054a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CTFd) to head [(`7ae1c78`)](https://app.codecov.io/gh/CTFd/CTFd/pull/2494?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CTFd).


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #2494      +/-   ##
==========================================
- Coverage   87.73%   85.32%   -2.42%     
==========================================
  Files         155      153       -2     
  Lines        9610     9558      -52     
==========================================
- Hits         8431     8155     -276     
- Misses       1179     1403     +224     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/CTFd/CTFd/pull/2494?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CTFd).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=CTFd).

ColdHeat: Thanks for catching this. I think this endpoint just got missed during Brackets implementation. 
ColdHeat: You could possibly consider adding the account_id field instead of replacing the id field. Perhaps in a seperate PR. 

Patch:
diff --git a/CTFd/api/v1/scoreboard.py b/CTFd/api/v1/scoreboard.py
index e9ac05b9..b81702d7 100644
--- a/CTFd/api/v1/scoreboard.py
+++ b/CTFd/api/v1/scoreboard.py
@@ -142,10 +142,14 @@ class ScoreboardDetail(Resource):
                 solves_mapper[team_id], key=lambda k: k["date"]
             )
 
-        for i, _team in enumerate(team_ids):
+        for i, x in enumerate(standings):
             response[i + 1] = {
-                "id": standings[i].account_id,
-                "name": standings[i].name,
-                "solves": solves_mapper.get(standings[i].account_id, []),
+                "id": x.account_id,
+                "account_url": generate_account_url(account_id=x.account_id),
+                "name": x.name,
+                "score": int(x.score),
+                "bracket_id": x.bracket_id,
+                "bracket_name": x.bracket_name,
+                "solves": solves_mapper.get(x.account_id, []),
             }
         return {"success": True, "data": response}


Test patch:
diff --git a/tests/users/test_scoreboard.py b/tests/users/test_scoreboard.py
index 8c8fadad..87cb7569 100644
--- a/tests/users/test_scoreboard.py
+++ b/tests/users/test_scoreboard.py
@@ -114,6 +114,11 @@ def test_top_10():
         saved = {
             "1": {
                 "id": 2,
+                "account_url": "/users/2",
+                "name": "user1",
+                "score": 200,
+                "bracket_id": None,
+                "bracket_name": None,
                 "solves": [
                     {
                         "date": "2017-10-03T03:21:34Z",
@@ -132,10 +137,14 @@ def test_top_10():
                         "value": 100,
                     },
                 ],
-                "name": "user1",
             },
             "2": {
                 "id": 3,
+                "account_url": "/users/3",
+                "name": "user2",
+                "score": 100,
+                "bracket_id": None,
+                "bracket_name": None,
                 "solves": [
                     {
                         "date": "2017-10-03T03:21:34Z",
@@ -146,7 +155,6 @@ def test_top_10():
                         "value": 100,
                     }
                 ],
-                "name": "user2",
             },
         }
         assert saved == response