# HG changeset patch # User Steve Losh # Date 1276445482 14400 # Node ID 1262a21153ac9b5b3bf7ea6118e496e773fe0f27 # Parent b0458ebb77ddaa2288de44389fe0aa9b3be9efa7 web: add anonymous commenting diff -r b0458ebb77dd -r 1262a21153ac contrib/deploy/wsgi.py --- a/contrib/deploy/wsgi.py Sun Jun 13 11:56:37 2010 -0400 +++ b/contrib/deploy/wsgi.py Sun Jun 13 12:11:22 2010 -0400 @@ -8,7 +8,7 @@ REPO = '/path/to/your/repo' READ_ONLY = True -ALLOW_ANON_COMMENTS = True +ALLOW_ANON_COMMENTS = False ANON_USER = 'Anonymous ' from mercurial import hg, ui @@ -20,6 +20,7 @@ repo = hg.repository(_ui, REPO) app.read_only = READ_ONLY +app.allow_anon = ALLOW_ANON_COMMENTS app.debug = False app.datastore = ReviewDatastore(_ui, repo) diff -r b0458ebb77dd -r 1262a21153ac review/extension_ui.py --- a/review/extension_ui.py Sun Jun 13 11:56:37 2010 -0400 +++ b/review/extension_ui.py Sun Jun 13 12:11:22 2010 -0400 @@ -15,11 +15,12 @@ def _web_command(ui, repo, **opts): ui.note(messages.WEB_START) read_only = opts.pop('read_only') + allow_anon = opts.pop('allow_anon') address = opts.pop('address') port = int(opts.pop('port')) import web_ui - web_ui.load_interface(ui, repo, read_only=read_only, + web_ui.load_interface(ui, repo, read_only=read_only, allow_anon=allow_anon, address=address, port=port, open=False) def _init_command(ui, repo, **opts): @@ -343,6 +344,7 @@ ('w', 'web', False, 'launch the web interface'), ('', 'read-only', False, 'make the web interface read-only'), + ('', 'allow-anon', False, 'allow anonymous comments on the web interface'), ('', 'address', '127.0.0.1', 'run the web interface on the specified address'), ('', 'port', '8080', 'run the web interface on the specified port'), ], diff -r b0458ebb77dd -r 1262a21153ac review/templates/changeset.html --- a/review/templates/changeset.html Sun Jun 13 11:56:37 2010 -0400 +++ b/review/templates/changeset.html Sun Jun 13 12:11:22 2010 -0400 @@ -20,7 +20,7 @@ {{ macros.gravatar(comment, utils) }}
{{ comment.message }}
@@ -33,7 +33,7 @@ {% endif %} {% endwith %} - {% if not read_only %} + {% if not read_only or allow_anon %}
Add a comment on this changeset
@@ -61,7 +61,7 @@
- {{ utils['templatefilters'].person(signoff.author) }} + {{ utils['templatefilters'].person(signoff.author) }} signed off as {{ signoff.opinion or "neutral" }} on this changeset, saying:
{{ signoff.message }}
@@ -134,7 +134,7 @@
{% endif %} {% endwith %} - {% if not read_only %} + {% if not read_only or allow_anon %}
Add a comment on this file diff -r b0458ebb77dd -r 1262a21153ac review/templates/diff.html --- a/review/templates/diff.html Sun Jun 13 11:56:37 2010 -0400 +++ b/review/templates/diff.html Sun Jun 13 12:11:22 2010 -0400 @@ -35,7 +35,7 @@ {% with %} {% set line_type = utils['line_type'](line['content']) %} - + {{ line['number'] }} {% if line_type == 'add' %}+{% elif line_type == 'rem' %}-{% endif %} {{ line['content'][1:]|escape }} diff -r b0458ebb77dd -r 1262a21153ac review/web_ui.py --- a/review/web_ui.py Sun Jun 13 11:56:37 2010 -0400 +++ b/review/web_ui.py Sun Jun 13 12:11:22 2010 -0400 @@ -60,8 +60,8 @@ } def _render(template, **kwargs): - return render_template(template, read_only=app.read_only, utils=utils, - datastore=app.datastore, **kwargs) + return render_template(template, read_only=app.read_only, + allow_anon=app.allow_anon, utils=utils, datastore=app.datastore, **kwargs) @app.route('/') @@ -102,11 +102,11 @@ @app.route('/changeset//', methods=['GET', 'POST']) def changeset(revhash): - if request.method == 'POST' and not app.read_only: + if request.method == 'POST': signoff = request.form.get('signoff', None) - if signoff: + if signoff and not app.read_only: return _handle_signoff(revhash) - else: + elif not app.read_only or app.allow_anon: return _handle_comment(revhash) rcset = app.datastore[revhash] @@ -136,15 +136,20 @@ return redirect('/') -def load_interface(ui, repo, read_only=False, open=False, - address='127.0.0.1', port=8080): +def load_interface(ui, repo, read_only=False, allow_anon=False, + open=False, address='127.0.0.1', port=8080): if open: import webbrowser webbrowser.open('http://localhost:%d/' % port) - app.datastore = api.ReviewDatastore(ui, repo) app.read_only = read_only app.debug = ui.debugflag + app.allow_anon = allow_anon + + if app.allow_anon: + ui.setconfig('ui', 'username', 'Anonymous ') + + app.datastore = api.ReviewDatastore(ui, repo) if app.debug: from flaskext.lesscss import lesscss