forked from KaindorfCTF/ctfd-notifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
49 lines (38 loc) · 1.61 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from flask import render_template
import json
import os
from .blueprint import load_bp
from .models import NotifierConfig
from .hooks import load_hooks
from .db_utils import DBUtils, DBAchievements
from CTFd.utils import config
from CTFd.utils.config.visibility import scores_visible
from CTFd.utils.decorators.visibility import (
check_account_visibility,
check_score_visibility,
)
from CTFd.utils.helpers import get_infos
from CTFd.utils.scores import get_standings
from CTFd.utils.user import is_admin
PLUGIN_PATH = os.path.dirname(__file__)
CONFIG = json.load(open(f"{PLUGIN_PATH}/config.json"))
def load(app):
app.db.create_all() # Create all DB entities
DBUtils.load_default()
bp = load_bp(CONFIG["route"]) # Load blueprint
app.register_blueprint(bp) # Register blueprint to the Flask app
load_hooks()
# override scoreboard to show the "neon" the scoreboard, but with achievements
# TODO: figure out how to make it use the current theme instead of hardcoding "neon"
app.view_functions['scoreboard.listing'] = scoreboard_with_achievements
@check_account_visibility
@check_score_visibility
def scoreboard_with_achievements():
infos = get_infos()
if config.is_scoreboard_frozen():
infos.append("Scoreboard has been frozen")
if is_admin() is True and scores_visible() is False:
infos.append("Scores are not currently visible to users")
user_achievements = DBAchievements.get_all_unlocked_achievements()
standings = get_standings()
return render_template("ctfd_notifier/scoreboard.html", standings=standings, infos=infos, user_achievements=user_achievements)