1262a21153ac

web: add anonymous commenting
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 13 Jun 2010 12:11:22 -0400
parents b0458ebb77dd
children 69015b8a626f
branches/tags (none)
files contrib/deploy/wsgi.py review/extension_ui.py review/templates/changeset.html review/templates/diff.html review/web_ui.py

Changes

--- 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 <anonymous@example.com>'
 
 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)
 
--- 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'),
     ],
--- 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) }}
                         <div>
                             <div class="author">
-                                <a href="mailto:${ email(comment.author) }">{{ utils['templatefilters'].person(comment.author) }}</a>
+                                <a href="mailto:{{ utils['email'](comment.author) }}">{{ utils['templatefilters'].person(comment.author) }}</a>
                                 said:
                             </div>
                             <div class="message">{{ comment.message }}</div>
@@ -33,7 +33,7 @@
         {% endif %}
     {% endwith %}
 
-    {% if not read_only %}
+    {% if not read_only or allow_anon %}
         <div class="add-review-comment togglebox group">
             <span class="activate"><a class="button" href="#"><span>Add a comment on this changeset</span></a></span>
             <form class="disabled" id="comment-review-form" method="POST" action="">
@@ -61,7 +61,7 @@
                         
                         <div>
                             <div class="author">
-                                <a href="mailto:${ email(signoff.author) }">{{ utils['templatefilters'].person(signoff.author) }}</a>
+                                <a href="mailto:{{ email(signoff.author) }}">{{ utils['templatefilters'].person(signoff.author) }}</a>
                                 signed off as <span class="opinion">{{ signoff.opinion or "neutral" }}</span> on this changeset, saying:
                             </div>
                             <div class="message">{{ signoff.message }}</div>
@@ -134,7 +134,7 @@
                         </div>
                     {% endif %}
                 {% endwith %}
-                {% if not read_only %}
+                {% if not read_only or allow_anon %}
                     <div class="add-file-comment togglebox group">
                         <span class="activate"><a class="button" href=""><span>Add a comment on this file</span></a></span>
 
--- 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']) %}
 
-                    <tr class="{{ line_type }} {% if not read_only %} commentable {% endif %} line-{{ line['number'] }}">
+                    <tr class="{{ line_type }} {% if not read_only or allow_anon %} commentable {% endif %} line-{{ line['number'] }}">
                         <td class="linenumber">{{ line['number'] }}</td>
                         <td class="addrem-{{ line_type }}">{% if line_type == 'add' %}+{% elif line_type == 'rem' %}-{% endif %}</td>
                         <td class="code"><code>{{ line['content'][1:]|escape }}</code></td>
--- 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/<revhash>/', 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 <anonymous@example.com>')
+
+    app.datastore = api.ReviewDatastore(ui, repo)
 
     if app.debug:
         from flaskext.lesscss import lesscss