add config option to lock pages explicitly

This commit is contained in:
Matthew Scragg 2014-09-10 13:58:47 -05:00
parent f0bce6c8d5
commit 1b433f1762
4 changed files with 23 additions and 2 deletions

View file

@ -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:

View file

@ -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 = '<div>' + content + '</div>'
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)

View file

@ -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'],

View file

@ -89,7 +89,11 @@
<li><a tabindex="-1" href="#" data-value="ace/theme/twilight" >Twilight</a></li>
<li><a tabindex="-1" href="#" data-value="ace/theme/vibrant_ink" >Vibrant Ink</a></li>
</ul>
<a id="save-native" class="btn btn-primary btn-sm"><i class="icon-save"></i> Save</a>
{% if name in config.LOCKED %}
<a class="btn btn-danger btn-sm"><i class="icon-lock"></i> Locked</a>
{% else %}
<a id="save-native" class="btn btn-primary btn-sm"><i class="icon-save"></i> Save</a>
{% endif %}
</div>
</div>
</div>