You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2014/06/13 20:34:51 UTC

[09/17] git commit: [#7406] add option to disable user registration

[#7406] add option to disable user registration


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/1b3b6931
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/1b3b6931
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/1b3b6931

Branch: refs/heads/db/7406
Commit: 1b3b69313a020e74a629710b4f1efefd0b3c4ec4
Parents: f80727e
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Tue Jun 10 22:25:41 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Jun 12 20:46:15 2014 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/auth.py               |  6 +++-
 .../templates/jinja_master/theme_macros.html    |  4 ++-
 Allura/allura/tests/functional/test_auth.py     | 36 ++++++++++++++++----
 Allura/development.ini                          |  1 +
 4 files changed, 39 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/1b3b6931/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index 92b618b..892cb3b 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -118,6 +118,8 @@ class AuthController(BaseController):
 
     @expose('jinja:allura:templates/create_account.html')
     def create_account(self, **kw):
+        if not asbool(config.get('auth.allow_user_registration', True)):
+            raise wexc.HTTPNotFound()
         c.form = F.registration_form
         return dict()
 
@@ -204,12 +206,14 @@ class AuthController(BaseController):
     @require_post()
     @validate(F.registration_form, error_handler=create_account)
     def save_new(self, display_name=None, username=None, pw=None, **kw):
+        if not asbool(config.get('auth.allow_user_registration', True)):
+            raise wexc.HTTPNotFound()
         user = M.User.register(
             dict(username=username,
                  display_name=display_name,
                  password=pw))
         plugin.AuthenticationProvider.get(request).login(user)
-        flash('User "%s" registered' % user.get_pref('display_name'))
+        flash('User "%s" registered' % username)
         redirect('/')
 
     @expose()

http://git-wip-us.apache.org/repos/asf/allura/blob/1b3b6931/Allura/allura/templates/jinja_master/theme_macros.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/theme_macros.html b/Allura/allura/templates/jinja_master/theme_macros.html
index 6033fe8..b828718 100644
--- a/Allura/allura/templates/jinja_master/theme_macros.html
+++ b/Allura/allura/templates/jinja_master/theme_macros.html
@@ -25,7 +25,9 @@
             <a href="{{c.user.url()}}">{{name}}</a>
             <a href="{{logout_url}}">Log Out</a>
           {% else %}
-            <a href="/auth/create_account">Register</a>
+            {% if h.asbool(config.get('auth.allow_user_registration', True)) %}
+              <a href="/auth/create_account">Register</a>
+            {% endif %}
             <a href="{{login_url}}">Log In</a>
           {% endif %}
         </nav>

http://git-wip-us.apache.org/repos/asf/allura/blob/1b3b6931/Allura/allura/tests/functional/test_auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_auth.py b/Allura/allura/tests/functional/test_auth.py
index 73641e4..6415f69 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -18,9 +18,13 @@
 from datetime import datetime, time, timedelta
 import re
 import json
-from bson import ObjectId
 from urlparse import urlparse, parse_qs
 
+from ming.orm.ormsession import ThreadLocalORMSession, session
+from bson import ObjectId
+from pylons import tmpl_context as c
+from tg import config, expose
+from mock import patch
 import mock
 from nose.tools import (
     assert_equal,
@@ -30,15 +34,13 @@ from nose.tools import (
     assert_in,
     assert_true
 )
-from pylons import tmpl_context as c
+
 from allura.tests import TestController
 from allura.tests import decorators as td
 from alluratest.controller import setup_trove_categories
 from allura import model as M
-from ming.orm.ormsession import ThreadLocalORMSession, session
-from tg import config, expose
-from mock import patch
 from allura.lib import plugin
+from allura.lib import helpers as h
 
 
 def unentity(s):
@@ -210,7 +212,7 @@ class TestAuth(TestController):
                 pw2='12345678',
                 display_name='Test Me'))
         r = r.follow()
-        assert 'User "Test Me" registered' in unentity(r.body)
+        assert 'User "aaa" registered' in unentity(r.body)
         r = self.app.post(
             '/auth/save_new',
             params=dict(
@@ -225,6 +227,28 @@ class TestAuth(TestController):
             params=dict(username='aaa', password='12345678'),
             status=302)
 
+    def test_create_account_disabled_header_link(self):
+        with h.push_config(config, **{'auth.allow_user_registration': 'false'}):
+            r = self.app.get('/')
+            assert not 'Register' in r
+
+    def test_create_account_disabled_form_gone(self):
+        with h.push_config(config, **{'auth.allow_user_registration': 'false'}):
+            r = self.app.get('/auth/create_account', status=404)
+            assert not 'Create an Account' in r
+
+    def test_create_account_disabled_submit_fails(self):
+        with h.push_config(config, **{'auth.allow_user_registration': 'false'}):
+            self.app.post(
+                '/auth/save_new',
+                params=dict(
+                    username='aaa',
+                    pw='12345678',
+                    pw2='12345678',
+                    display_name='Test Me'),
+                status=404,
+            )
+
     def test_one_project_role(self):
         """Make sure when a user goes to a new project only one project role is created.
            There was an issue with extra project roles getting created if a user went directly to

http://git-wip-us.apache.org/repos/asf/allura/blob/1b3b6931/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 8cc60c1..0470f67 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -86,6 +86,7 @@ auth.ldap.password.algorithm = 6
 auth.ldap.password.rounds = 6000
 auth.ldap.password.salt_len = 16
 
+auth.allow_user_registration = true
 auth.allow_user_to_disable_account = true
 auth.allow_edit_prefs = true
 auth.allow_password_change = true