diff --git a/CTFd/admin/__init__.py b/CTFd/admin/__init__.py index c85ddd5..9bec4d7 100644 --- a/CTFd/admin/__init__.py +++ b/CTFd/admin/__init__.py @@ -86,7 +86,7 @@ def plugin(plugin): continue set_config(k, v) with app.app_context(): - cache.clear() + clear_config() return '1' diff --git a/CTFd/api/v1/challenges.py b/CTFd/api/v1/challenges.py index 72a8d84..6d75ebf 100644 --- a/CTFd/api/v1/challenges.py +++ b/CTFd/api/v1/challenges.py @@ -173,7 +173,7 @@ class Challenge(Resource): prereqs = set(requirements.get('prerequisites', [])) anonymize = requirements.get('anonymize') - if solve_ids >= prereqs: + if solve_ids >= prereqs or is_admin(): pass else: if anonymize: diff --git a/CTFd/api/v1/pages.py b/CTFd/api/v1/pages.py index 72d458a..60a2ad1 100644 --- a/CTFd/api/v1/pages.py +++ b/CTFd/api/v1/pages.py @@ -2,7 +2,7 @@ from flask import session, request from flask_restplus import Namespace, Resource from CTFd.models import db, Pages from CTFd.schemas.pages import PageSchema -from CTFd.utils.events import socketio +from CTFd.cache import clear_pages from CTFd.utils.decorators import ( admins_only @@ -47,6 +47,8 @@ class PageList(Resource): response = schema.dump(response.data) db.session.close() + clear_pages() + return { 'success': True, 'data': response.data @@ -91,6 +93,8 @@ class PageDetail(Resource): response = schema.dump(response.data) db.session.close() + clear_pages() + return { 'success': True, 'data': response.data @@ -103,6 +107,8 @@ class PageDetail(Resource): db.session.commit() db.session.close() + clear_pages() + return { 'success': True } diff --git a/CTFd/cache/__init__.py b/CTFd/cache/__init__.py index 209ca8b..9f0fb89 100644 --- a/CTFd/cache/__init__.py +++ b/CTFd/cache/__init__.py @@ -12,3 +12,9 @@ def clear_config(): def clear_standings(): from CTFd.utils.scores import get_standings cache.delete_memoized(get_standings) + + +def clear_pages(): + from CTFd.utils.config.pages import get_page, get_pages + cache.delete_memoized(get_pages) + cache.delete_memoized(get_page) diff --git a/CTFd/config.py b/CTFd/config.py index f71c1f3..930e4d5 100644 --- a/CTFd/config.py +++ b/CTFd/config.py @@ -73,6 +73,7 @@ class Config(object): else: CACHE_TYPE = 'filesystem' CACHE_DIR = os.path.join(os.path.dirname(__file__), os.pardir, '.data', 'filesystem_cache') + CACHE_THRESHOLD = 0 # Override the threshold of cached values on the filesystem. The default is 500. Don't change unless you know what you're doing. ''' === SECURITY === @@ -210,4 +211,5 @@ class TestingConfig(Config): UPDATE_CHECK = False REDIS_URL = None CACHE_TYPE = 'simple' + CACHE_THRESHOLD = 500 SAFE_MODE = True diff --git a/CTFd/schemas/pages.py b/CTFd/schemas/pages.py index cb891ca..21a7077 100644 --- a/CTFd/schemas/pages.py +++ b/CTFd/schemas/pages.py @@ -1,6 +1,6 @@ from sqlalchemy.sql.expression import union_all from marshmallow import fields, post_load -from marshmallow import validate, ValidationError +from marshmallow import validate, ValidationError, pre_load from marshmallow_sqlalchemy import field_for from CTFd.models import ma, Pages @@ -11,6 +11,12 @@ class PageSchema(ma.ModelSchema): include_fk = True dump_only = ('id', ) + @pre_load + def validate_route(self, data): + route = data.get('route') + if route and route.startswith('/'): + data['route'] = route.strip('/') + def __init__(self, view=None, *args, **kwargs): if view: if type(view) == str: diff --git a/CTFd/themes/admin/static/js/pages/editor.js b/CTFd/themes/admin/static/js/pages/editor.js index f36f99b..a365269 100644 --- a/CTFd/themes/admin/static/js/pages/editor.js +++ b/CTFd/themes/admin/static/js/pages/editor.js @@ -9,6 +9,7 @@ var editor = CodeMirror.fromTextArea( function show_files(data) { var list = $('#media-library-list'); + list.empty(); for (var i = 0; i < data.length; i++) { var f = data[i]; @@ -107,8 +108,7 @@ function submit_form() { button: 'Okay' }); } else { - console.log(data); - window.location = script_root + '/admin/pages/' + data.id; + window.location = script_root + '/admin/pages/' + response.data.id; } }); } @@ -122,7 +122,7 @@ function preview_page() { function upload_media() { upload_files($('#media-library-upload'), function (data) { - console.log(data); + refresh_files(); }); } @@ -146,12 +146,6 @@ $(document).ready(function () { insert_at_cursor(editor, entry); }); - - $('#publish-page').click(function (e) { - e.preventDefault(); - submit_form(); - }); - $('#save-page').click(function (e) { e.preventDefault(); submit_form(); diff --git a/CTFd/themes/admin/templates/editor.html b/CTFd/themes/admin/templates/editor.html index d680817..6090313 100644 --- a/CTFd/themes/admin/templates/editor.html +++ b/CTFd/themes/admin/templates/editor.html @@ -93,8 +93,10 @@