mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-18 22:44:24 +01:00
Change /api/v1/config/<config_key> to return structured data (#1516)
* Change `/api/v1/config/<config_key>` to return properly structured data * Closes #1506
This commit is contained in:
@@ -11,7 +11,7 @@ from CTFd.cache import clear_config, clear_standings
|
|||||||
from CTFd.constants import RawEnum
|
from CTFd.constants import RawEnum
|
||||||
from CTFd.models import Configs, db
|
from CTFd.models import Configs, db
|
||||||
from CTFd.schemas.config import ConfigSchema
|
from CTFd.schemas.config import ConfigSchema
|
||||||
from CTFd.utils import get_config, set_config
|
from CTFd.utils import set_config
|
||||||
from CTFd.utils.decorators import admins_only
|
from CTFd.utils.decorators import admins_only
|
||||||
|
|
||||||
configs_namespace = Namespace("configs", description="Endpoint to retrieve Configs")
|
configs_namespace = Namespace("configs", description="Endpoint to retrieve Configs")
|
||||||
@@ -121,13 +121,33 @@ class ConfigList(Resource):
|
|||||||
@configs_namespace.route("/<config_key>")
|
@configs_namespace.route("/<config_key>")
|
||||||
class Config(Resource):
|
class Config(Resource):
|
||||||
@admins_only
|
@admins_only
|
||||||
# TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506
|
@configs_namespace.doc(
|
||||||
|
description="Endpoint to get a specific Config object",
|
||||||
|
responses={
|
||||||
|
200: ("Success", "ConfigDetailedSuccessResponse"),
|
||||||
|
400: (
|
||||||
|
"An error occured processing the provided or stored data",
|
||||||
|
"APISimpleErrorResponse",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
def get(self, config_key):
|
def get(self, config_key):
|
||||||
|
config = Configs.query.filter_by(key=config_key).first_or_404()
|
||||||
return {"success": True, "data": get_config(config_key)}
|
schema = ConfigSchema()
|
||||||
|
response = schema.dump(config)
|
||||||
|
return {"success": True, "data": response.data}
|
||||||
|
|
||||||
@admins_only
|
@admins_only
|
||||||
# TODO: This returns weirdly structured data. It should more closely match ConfigDetailedSuccessResponse #1506
|
@configs_namespace.doc(
|
||||||
|
description="Endpoint to edit a specific Config object",
|
||||||
|
responses={
|
||||||
|
200: ("Success", "ConfigDetailedSuccessResponse"),
|
||||||
|
400: (
|
||||||
|
"An error occured processing the provided or stored data",
|
||||||
|
"APISimpleErrorResponse",
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
def patch(self, config_key):
|
def patch(self, config_key):
|
||||||
config = Configs.query.filter_by(key=config_key).first()
|
config = Configs.query.filter_by(key=config_key).first()
|
||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
|
|||||||
Reference in New Issue
Block a user