Navbar links (#427)

* Adding config.json concept in lieu of config.html
* Add links to the admin menubar from a plugin
* Add links to the user navigation menubar from plugin
* Add tests for navbar links
* Closes #423
This commit is contained in:
Kevin Chung
2017-10-25 00:05:27 -04:00
committed by GitHub
parent 710ce6d500
commit b5a383a2e1
6 changed files with 162 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ import glob
import importlib
import os
from collections import namedtuple
from flask.helpers import safe_join
from flask import current_app as app, send_file, send_from_directory, abort
from CTFd.utils import (
@@ -12,6 +13,11 @@ from CTFd.utils import (
)
Menu = namedtuple('Menu', ['name', 'route'])
ADMIN_PLUGIN_MENU_BAR = []
USER_PAGE_MENU_BAR = []
def register_plugin_assets_directory(app, base_path, admins_only=False):
"""
Registers a directory to serve assets
@@ -76,6 +82,48 @@ def register_plugin_stylesheet(*args, **kwargs):
utils_register_plugin_stylesheet(*args, **kwargs)
def register_admin_plugin_menu_bar(name, route):
"""
Registers links on the Admin Panel menubar/navbar
:param name: A string that is shown on the navbar HTML
:param route: A string that is the href used by the link
:return:
"""
am = Menu(name=name, route=route)
ADMIN_PLUGIN_MENU_BAR.append(am)
def get_admin_plugin_menu_bar():
"""
Access the list used to store the plugin menu bar
:return: Returns a list of Menu namedtuples. They have name, and route attributes.
"""
return ADMIN_PLUGIN_MENU_BAR
def register_user_page_menu_bar(name, route):
"""
Registers links on the User side menubar/navbar
:param name: A string that is shown on the navbar HTML
:param route: A string that is the href used by the link
:return:
"""
p = Menu(name=name, route=route)
USER_PAGE_MENU_BAR.append(p)
def get_user_page_menu_bar():
"""
Access the list used to store the user page menu bar
:return: Returns a list of Menu namedtuples. They have name, and route attributes.
"""
return USER_PAGE_MENU_BAR
def init_plugins(app):
"""
Searches for the load function in modules in the CTFd/plugins folder. This function is called with the current CTFd
@@ -93,3 +141,6 @@ def init_plugins(app):
module = importlib.import_module(module, package='CTFd.plugins')
module.load(app)
print(" * Loaded module, %s" % module)
app.jinja_env.globals.update(get_admin_plugin_menu_bar=get_admin_plugin_menu_bar)
app.jinja_env.globals.update(get_user_page_menu_bar=get_user_page_menu_bar)