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 ALLOW_ANON = True
LOGIN_DISABLED = ALLOW_ANON LOGIN_DISABLED = ALLOW_ANON
# Page names that can't be modified
LOCKED = []
ROOT_ENDPOINT = 'wiki.page' ROOT_ENDPOINT = 'wiki.page'
try: try:

View file

@ -86,6 +86,8 @@ class Wiki():
if m.group(1): if m.group(1):
return "```" + unescape(m.group(1)) + "```" return "```" + unescape(m.group(1)) + "```"
cname = to_canonical(name)
# prevents p tag from being added, we remove this later # prevents p tag from being added, we remove this later
content = '<div>' + content + '</div>' content = '<div>' + content + '</div>'
content = re.sub(r"```(.*?)```", escape_repl, content, flags=re.DOTALL) 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) content = re.sub(r"```(.*?)```", unescape_repl, content, flags=re.DOTALL)
cname = to_canonical(name)
filename = self.cname_to_filename(cname) filename = self.cname_to_filename(cname)
with open(self.path + "/" + filename, 'w') as f: with open(self.path + "/" + filename, 'w') as f:
f.write(content) f.write(content)

View file

@ -51,6 +51,10 @@ def edit(name):
cname = to_canonical(name) cname = to_canonical(name)
if request.method == 'POST': if request.method == 'POST':
edit_cname = to_canonical(request.form['name']) 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(): if edit_cname.lower() != cname.lower():
wiki.rename_page(cname, edit_cname) wiki.rename_page(cname, edit_cname)
@ -61,6 +65,7 @@ def edit(name):
else: else:
if data: if data:
name = remove_ext(data['name']) name = remove_ext(data['name'])
content = data.get('data') content = data.get('data')
g.assets['js'].append('editor.js') g.assets['js'].append('editor.js')
return render_template('wiki/edit.html', name=name, content=content, partials=data.get('partials')) return render_template('wiki/edit.html', name=name, content=content, partials=data.get('partials'))
@ -79,6 +84,14 @@ def delete(name):
@login_required @login_required
def create(name): def create(name):
if request.method == 'POST': 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'], wiki.write_page(request.form['name'],
request.form['content'], request.form['content'],
message=request.form['message'], 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/twilight" >Twilight</a></li>
<li><a tabindex="-1" href="#" data-value="ace/theme/vibrant_ink" >Vibrant Ink</a></li> <li><a tabindex="-1" href="#" data-value="ace/theme/vibrant_ink" >Vibrant Ink</a></li>
</ul> </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> </div>
</div> </div>