321 comments functionality (#1596)

* Add a comments functionality for admins to discuss challenges, users, teams, pages
* Adds `/api/v1/comments`
* Adds a `CommentBox.vue` component for the Admin Panel
* Closes #321
This commit is contained in:
Kevin Chung
2020-08-12 19:55:47 -04:00
committed by GitHub
parent 6559846452
commit b73433e1c9
23 changed files with 1095 additions and 30 deletions

View File

@@ -17,21 +17,26 @@ from CTFd.cache import cache, clear_standings
from CTFd.config import TestingConfig
from CTFd.models import (
Awards,
ChallengeComments,
ChallengeFiles,
Challenges,
Comments,
Fails,
Files,
Flags,
Hints,
Notifications,
PageComments,
PageFiles,
Pages,
Solves,
Tags,
TeamComments,
Teams,
Tokens,
Tracking,
Unlocks,
UserComments,
Users,
)
@@ -435,6 +440,24 @@ def gen_token(db, type="user", user_id=None, expiration=None):
return token
def gen_comment(db, content="comment", author_id=None, type="challenge", **kwargs):
if type == "challenge":
model = ChallengeComments
elif type == "user":
model = UserComments
elif type == "team":
model = TeamComments
elif type == "page":
model = PageComments
else:
model = Comments
comment = model(content=content, author_id=author_id, type=type, **kwargs)
db.session.add(comment)
db.session.commit()
return comment
def simulate_user_activity(db, user):
gen_tracking(db, user_id=user.id)
gen_award(db, user_id=user.id)