mirror of
https://github.com/aljazceru/CTFd.git
synced 2025-12-17 14:04:20 +01:00
* Closes #1897 * Adds Topics to Challenges where Topics are admin-only visible tags about challenges * Adds `/api/v1/topics` and `/api/v1/challenges/[challenge_id]/topics` to API * Challenge comments have been moved into a modal
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from CTFd.models import ChallengeTopics, Topics, ma
|
|
from CTFd.utils import string_types
|
|
|
|
|
|
class TopicSchema(ma.ModelSchema):
|
|
class Meta:
|
|
model = Topics
|
|
include_fk = True
|
|
dump_only = ("id",)
|
|
|
|
views = {"admin": ["id", "value"]}
|
|
|
|
def __init__(self, view=None, *args, **kwargs):
|
|
if view:
|
|
if isinstance(view, string_types):
|
|
kwargs["only"] = self.views[view]
|
|
elif isinstance(view, list):
|
|
kwargs["only"] = view
|
|
|
|
super(TopicSchema, self).__init__(*args, **kwargs)
|
|
|
|
|
|
class ChallengeTopicSchema(ma.ModelSchema):
|
|
class Meta:
|
|
model = ChallengeTopics
|
|
include_fk = True
|
|
dump_only = ("id",)
|
|
|
|
views = {"admin": ["id", "challenge_id", "topic_id"]}
|
|
|
|
def __init__(self, view=None, *args, **kwargs):
|
|
if view:
|
|
if isinstance(view, string_types):
|
|
kwargs["only"] = self.views[view]
|
|
elif isinstance(view, list):
|
|
kwargs["only"] = view
|
|
|
|
super(ChallengeTopicSchema, self).__init__(*args, **kwargs)
|