added the ability to make wiki private (resolves #54)

This commit is contained in:
cybrwushl93 2015-07-18 11:02:59 +02:00
parent ceec6b6789
commit c9308b25e3
2 changed files with 16 additions and 0 deletions

View file

@ -122,6 +122,7 @@ WIKI_HOME = 'home'
ALLOW_ANON = True ALLOW_ANON = True
REGISTRATION_ENABLED = True REGISTRATION_ENABLED = True
PRIVATE_WIKI = False
# None, firepad, and/or togetherjs # None, firepad, and/or togetherjs
COLLABORATION = 'togetherjs' COLLABORATION = 'togetherjs'

View file

@ -8,6 +8,9 @@ blueprint = Blueprint('wiki', __name__)
@blueprint.route("/_commit/<sha>/<name>") @blueprint.route("/_commit/<sha>/<name>")
def commit(name, sha): def commit(name, sha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name) cname = to_canonical(name)
data = g.current_wiki.get_page(cname, sha=sha) data = g.current_wiki.get_page(cname, sha=sha)
@ -20,6 +23,9 @@ def commit(name, sha):
@blueprint.route("/_compare/<name>/<regex('[^.]+'):fsha><regex('\.{2,3}'):dots><regex('.+'):lsha>") @blueprint.route("/_compare/<name>/<regex('[^.]+'):fsha><regex('\.{2,3}'):dots><regex('.+'):lsha>")
def compare(name, fsha, dots, lsha): def compare(name, fsha, dots, lsha):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
diff = g.current_wiki.compare(name, fsha, lsha) diff = g.current_wiki.compare(name, fsha, lsha)
return render_template('wiki/compare.html', return render_template('wiki/compare.html',
name=name, diff=diff, old=fsha, new=lsha) name=name, diff=diff, old=fsha, new=lsha)
@ -55,6 +61,9 @@ def revert():
@blueprint.route("/_history/<name>") @blueprint.route("/_history/<name>")
def history(name): def history(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
return render_template('wiki/history.html', name=name, history=g.current_wiki.get_history(name)) return render_template('wiki/history.html', name=name, history=g.current_wiki.get_history(name))
@ -96,6 +105,9 @@ def create(name):
@blueprint.route("/_index") @blueprint.route("/_index")
def index(): def index():
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
return render_template('wiki/index.html', index=g.current_wiki.get_index()) return render_template('wiki/index.html', index=g.current_wiki.get_index())
@ -154,6 +166,9 @@ def page_write(name):
@blueprint.route("/", defaults={'name': 'home'}) @blueprint.route("/", defaults={'name': 'home'})
@blueprint.route("/<name>") @blueprint.route("/<name>")
def page(name): def page(name):
if current_app.config.get('PRIVATE_WIKI') and current_user.is_anonymous():
return current_app.login_manager.unauthorized()
cname = to_canonical(name) cname = to_canonical(name)
if cname != name: if cname != name:
return redirect(url_for('wiki.page', name=cname)) return redirect(url_for('wiki.page', name=cname))