From 1b433f1762f0faeb6dd163e47c6344b300bb0657 Mon Sep 17 00:00:00 2001 From: Matthew Scragg Date: Wed, 10 Sep 2014 13:58:47 -0500 Subject: [PATCH] add config option to lock pages explicitly --- realms/config/__init__.py | 3 +++ realms/modules/wiki/models.py | 3 ++- realms/modules/wiki/views.py | 13 +++++++++++++ realms/templates/wiki/edit.html | 6 +++++- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/realms/config/__init__.py b/realms/config/__init__.py index b781a2f..6d0e059 100644 --- a/realms/config/__init__.py +++ b/realms/config/__init__.py @@ -42,6 +42,9 @@ WIKI_HOME = 'home' ALLOW_ANON = True LOGIN_DISABLED = ALLOW_ANON +# Page names that can't be modified +LOCKED = [] + ROOT_ENDPOINT = 'wiki.page' try: diff --git a/realms/modules/wiki/models.py b/realms/modules/wiki/models.py index f72de1a..96000a9 100644 --- a/realms/modules/wiki/models.py +++ b/realms/modules/wiki/models.py @@ -86,6 +86,8 @@ class Wiki(): if m.group(1): return "```" + unescape(m.group(1)) + "```" + cname = to_canonical(name) + # prevents p tag from being added, we remove this later content = '
' + content + '
' content = re.sub(r"```(.*?)```", escape_repl, content, flags=re.DOTALL) @@ -115,7 +117,6 @@ class Wiki(): content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL) - cname = to_canonical(name) filename = self.cname_to_filename(cname) with open(self.path + "/" + filename, 'w') as f: f.write(content) diff --git a/realms/modules/wiki/views.py b/realms/modules/wiki/views.py index a665171..7cb478f 100644 --- a/realms/modules/wiki/views.py +++ b/realms/modules/wiki/views.py @@ -51,6 +51,10 @@ def edit(name): cname = to_canonical(name) if request.method == 'POST': edit_cname = to_canonical(request.form['name']) + + if edit_cname in config.LOCKED: + return redirect(url_for(config.ROOT_ENDPOINT)) + if edit_cname.lower() != cname.lower(): wiki.rename_page(cname, edit_cname) @@ -61,6 +65,7 @@ def edit(name): else: if data: name = remove_ext(data['name']) + content = data.get('data') g.assets['js'].append('editor.js') return render_template('wiki/edit.html', name=name, content=content, partials=data.get('partials')) @@ -79,6 +84,14 @@ def delete(name): @login_required def create(name): if request.method == 'POST': + cname = to_canonical(request.form['name']) + + if cname in config.LOCKED: + return redirect(url_for("wiki.create")) + + if not cname: + return redirect(url_for("wiki.create")) + wiki.write_page(request.form['name'], request.form['content'], message=request.form['message'], diff --git a/realms/templates/wiki/edit.html b/realms/templates/wiki/edit.html index 0559e2b..2dba153 100644 --- a/realms/templates/wiki/edit.html +++ b/realms/templates/wiki/edit.html @@ -89,7 +89,11 @@
  • Twilight
  • Vibrant Ink
  • - Save + {% if name in config.LOCKED %} + Locked + {% else %} + Save + {% endif %}