|
1 | | -from flask import send_file, jsonify |
| 1 | +from flask import send_file, jsonify, request |
2 | 2 | from werkzeug.utils import safe_join |
3 | 3 | from CTFd.models import Challenges, Solves, Pages, db |
| 4 | +from CTFd.models import TeamFields, UserFields |
4 | 5 | from CTFd.schemas.pages import PageSchema |
5 | 6 | from CTFd.utils import get_config |
6 | 7 | from CTFd.utils.modes import get_model |
@@ -54,6 +55,44 @@ def rules(): |
54 | 55 |
|
55 | 56 | return {"success": True, "data": response.data} |
56 | 57 |
|
| 58 | + @app.route("/api/v1/fields", methods=["GET"]) |
| 59 | + def list_fields(): |
| 60 | + t = (request.args.get("type") or "").lower() |
| 61 | + |
| 62 | + if t in ("team", "teams"): |
| 63 | + q = TeamFields.query |
| 64 | + elif t in ("user", "users"): |
| 65 | + q = UserFields.query |
| 66 | + else: |
| 67 | + return ( |
| 68 | + jsonify( |
| 69 | + { |
| 70 | + "success": False, |
| 71 | + "data": None, |
| 72 | + "errors": { |
| 73 | + "type": "Missing or invalid ?type (team|user)" |
| 74 | + }, |
| 75 | + } |
| 76 | + ), |
| 77 | + 400, |
| 78 | + ) |
| 79 | + |
| 80 | + fields = q.all() |
| 81 | + |
| 82 | + response = [] |
| 83 | + for f in fields: |
| 84 | + response.append( |
| 85 | + { |
| 86 | + "id": f.id, |
| 87 | + "name": getattr(f, "name", None), |
| 88 | + "field_type": getattr(f, "field_type", None), |
| 89 | + "description": getattr(f, "description", None), |
| 90 | + "required": bool(getattr(f, "required", False)), |
| 91 | + } |
| 92 | + ) |
| 93 | + |
| 94 | + return jsonify({"success": True, "data": response}) |
| 95 | + |
57 | 96 | @app.route("/api/v1/challenges/solves", methods=["GET"]) |
58 | 97 | @during_ctf_time_only |
59 | 98 | def solves(): |
|
0 commit comments