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/11 00:25:51 UTC
git commit: [#7406] add option to disable user registration
Repository: allura
Updated Branches:
refs/heads/db/7406 [created] cfb47b762
[#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/cfb47b76
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/cfb47b76
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/cfb47b76
Branch: refs/heads/db/7406
Commit: cfb47b762ece1f5b4ca273a2b7209a183bb46a3c
Parents: 6c540c2
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Tue Jun 10 22:25:41 2014 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Tue Jun 10 22:25:41 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/cfb47b76/Allura/allura/controllers/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/auth.py b/Allura/allura/controllers/auth.py
index ff2d42f..3fb1ca9 100644
--- a/Allura/allura/controllers/auth.py
+++ b/Allura/allura/controllers/auth.py
@@ -115,6 +115,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()
@@ -201,12 +203,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/cfb47b76/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/cfb47b76/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/cfb47b76/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 7fb2ea2..949bb79 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
# In seconds