You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2014/02/27 23:32:58 UTC

[6/6] git commit: [#7029] Added auto-discovery of new user preference pages

[#7029] Added auto-discovery of new user preference pages

Signed-off-by: Cory Johns <cj...@slashdotmedia.com>


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

Branch: refs/heads/master
Commit: af77bf36e5ca56871fb4a8852e20afd2fb94a7c7
Parents: a738f1b
Author: Cory Johns <cj...@slashdotmedia.com>
Authored: Thu Feb 27 22:32:11 2014 +0000
Committer: Cory Johns <cj...@slashdotmedia.com>
Committed: Thu Feb 27 22:32:11 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py                 | 32 ++++++++++++++++++------
 Allura/allura/tests/functional/test_auth.py | 18 ++++++++++++-
 2 files changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af77bf36/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index cfd9170..d61f35f 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -987,14 +987,30 @@ class UserPreferencesProvider(object):
         '''
         Returns list of additional routes for AuthProvider.
 
-        No additional routes by default. Subclasses migth override this.
-
-        For example: [('newroute', newroute_handler), ] will add
-        'newroute' attribute to AuthProvider, which will be set to newroute_handler.
-
-        newroutehandler is a usual controller method (decorated with @exposed and other stuff).
-        '''
-        return []
+        By default, scans the provider for @expose()ed methods, which are
+        added as pages with the same name as the method.  Note that if you
+        want the new pages to show up in the menu on the various auth pages,
+        you will also need to add it to the list returned by
+        `AuthenticationProvider.account_navigation`.
+
+        If you want to override this behavior, you can override this method
+        and manually return a list of (page_name, handler) tuple pairs.  Note,
+        however, that this could break future subclasses of your providers'
+        ability to extend the list.
+
+        For example: `[('newroute', newroute_handler)]` will add 'newroute'
+        attribute to the auth controller, which will be set to `newroute_handler`.
+
+        `newroute_handler` must be decorated with @expose(), but does not have
+        to live on the provider.
+        '''
+        urls = []
+        for attr_name in dir(self):
+            attr_value = getattr(self, attr_name)
+            decoration = getattr(attr_value, 'decoration', None)
+            if getattr(decoration, 'exposed', False):
+                urls.append((attr_name, attr_value))
+        return urls
 
 
 class LocalUserPreferencesProvider(UserPreferencesProvider):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/af77bf36/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 bd6a4e2..8e36f5e 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -35,7 +35,7 @@ from allura.tests import TestController
 from allura.tests import decorators as td
 from allura import model as M
 from ming.orm.ormsession import ThreadLocalORMSession, session
-from tg import config
+from tg import config, expose
 from mock import patch
 from allura.lib import plugin
 
@@ -605,6 +605,22 @@ class TestPreferences(TestController):
             username='test-admin').get_pref('disable_user_messages')
 
 
+    @td.with_user_project('test-admin')
+    def test_additional_page(self):
+        class MyPP(plugin.UserPreferencesProvider):
+            def not_page(self):
+                return 'not page'
+            @expose()
+            def new_page(self):
+                return 'new page'
+
+        with mock.patch.object(plugin.UserPreferencesProvider, 'get') as upp_get:
+            upp_get.return_value = MyPP()
+            r = self.app.get('/auth/new_page')
+            assert_equal(r.body, 'new page')
+            self.app.get('/auth/not_page', status=404)
+
+
 class TestPasswordReset(TestController):
 
     @patch('allura.tasks.mail_tasks.sendmail')