mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 14:34:21 +01:00
Fix scoreboard links created by update() in user mode (#1034)
* Fixes account links on the scoreboard page created by `update()`. They now correctly point to the user instead of undefined when in user mode. * Add `account_type` and `account_url` field in `/api/v1/scoreboard`
This commit is contained in:
@@ -29,7 +29,7 @@ from CTFd.utils.config.visibility import (
|
|||||||
challenges_visible,
|
challenges_visible,
|
||||||
)
|
)
|
||||||
from CTFd.utils.user import is_admin, authed
|
from CTFd.utils.user import is_admin, authed
|
||||||
from CTFd.utils.modes import get_model, USERS_MODE, TEAMS_MODE
|
from CTFd.utils.modes import get_model, generate_account_url
|
||||||
from CTFd.schemas.tags import TagSchema
|
from CTFd.schemas.tags import TagSchema
|
||||||
from CTFd.schemas.hints import HintSchema
|
from CTFd.schemas.hints import HintSchema
|
||||||
from CTFd.schemas.flags import FlagSchema
|
from CTFd.schemas.flags import FlagSchema
|
||||||
@@ -529,21 +529,13 @@ class ChallengeSolves(Resource):
|
|||||||
dt = datetime.datetime.utcfromtimestamp(freeze)
|
dt = datetime.datetime.utcfromtimestamp(freeze)
|
||||||
solves = solves.filter(Solves.date < dt)
|
solves = solves.filter(Solves.date < dt)
|
||||||
|
|
||||||
endpoint = None
|
|
||||||
if get_config("user_mode") == TEAMS_MODE:
|
|
||||||
endpoint = "teams.public"
|
|
||||||
arg = "team_id"
|
|
||||||
elif get_config("user_mode") == USERS_MODE:
|
|
||||||
endpoint = "users.public"
|
|
||||||
arg = "user_id"
|
|
||||||
|
|
||||||
for solve in solves:
|
for solve in solves:
|
||||||
response.append(
|
response.append(
|
||||||
{
|
{
|
||||||
"account_id": solve.account_id,
|
"account_id": solve.account_id,
|
||||||
"name": solve.account.name,
|
"name": solve.account.name,
|
||||||
"date": isoformat(solve.date),
|
"date": isoformat(solve.date),
|
||||||
"account_url": url_for(endpoint, **{arg: solve.account_id}),
|
"account_url": generate_account_url(account_id=solve.account_id),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from CTFd.models import Solves, Awards, Teams
|
|||||||
from CTFd.cache import cache, make_cache_key
|
from CTFd.cache import cache, make_cache_key
|
||||||
from CTFd.utils.scores import get_standings
|
from CTFd.utils.scores import get_standings
|
||||||
from CTFd.utils import get_config
|
from CTFd.utils import get_config
|
||||||
from CTFd.utils.modes import TEAMS_MODE
|
from CTFd.utils.modes import generate_account_url, get_mode_as_word, TEAMS_MODE
|
||||||
from CTFd.utils.dates import unix_time_to_utc, isoformat
|
from CTFd.utils.dates import unix_time_to_utc, isoformat
|
||||||
from CTFd.utils.decorators.visibility import (
|
from CTFd.utils.decorators.visibility import (
|
||||||
check_account_visibility,
|
check_account_visibility,
|
||||||
@@ -25,6 +25,7 @@ class ScoreboardList(Resource):
|
|||||||
standings = get_standings()
|
standings = get_standings()
|
||||||
response = []
|
response = []
|
||||||
mode = get_config("user_mode")
|
mode = get_config("user_mode")
|
||||||
|
account_type = get_mode_as_word()
|
||||||
|
|
||||||
if mode == TEAMS_MODE:
|
if mode == TEAMS_MODE:
|
||||||
team_ids = []
|
team_ids = []
|
||||||
@@ -37,6 +38,8 @@ class ScoreboardList(Resource):
|
|||||||
entry = {
|
entry = {
|
||||||
"pos": i + 1,
|
"pos": i + 1,
|
||||||
"account_id": x.account_id,
|
"account_id": x.account_id,
|
||||||
|
"account_url": generate_account_url(account_id=x.account_id),
|
||||||
|
"account_type": account_type,
|
||||||
"oauth_id": x.oauth_id,
|
"oauth_id": x.oauth_id,
|
||||||
"name": x.name,
|
"name": x.name,
|
||||||
"score": int(x.score),
|
"score": int(x.score),
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ function updatescores() {
|
|||||||
var row =
|
var row =
|
||||||
"<tr>\n" +
|
"<tr>\n" +
|
||||||
'<th scope="row" class="text-center">{0}</th>'.format(teams[i].pos) +
|
'<th scope="row" class="text-center">{0}</th>'.format(teams[i].pos) +
|
||||||
'<td><a href="{0}/team/{1}">{2}</a></td>'.format(
|
'<td><a href="{0}">{1}</a></td>'.format(
|
||||||
script_root,
|
teams[i].account_url,
|
||||||
teams[i].id,
|
|
||||||
htmlentities(teams[i].name)
|
htmlentities(teams[i].name)
|
||||||
) +
|
) +
|
||||||
"<td>{0}</td>".format(teams[i].score) +
|
"<td>{0}</td>".format(teams[i].score) +
|
||||||
|
|||||||
Reference in New Issue
Block a user