allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [12/49] git commit: [#5404] use auth provider methods to determine user-project name when registering it
Date Fri, 07 Dec 2012 22:26:35 GMT
[#5404] use auth provider methods to determine user-project name when registering it

Also, renamed method to user_by_project_shortname to reflect what it
is actually doing.  And modified user_project_shortname name and
functionality to match its peer, user_by_project_shortname


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

Branch: refs/heads/db/4803
Commit: 49edd6b41f514d6f1c060c986e246a8c1ab64300
Parents: 919f6b0
Author: Dave Brondsema <dbrondsema@geek.net>
Authored: Tue Dec 4 21:08:01 2012 +0000
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Tue Dec 4 21:08:01 2012 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py |    4 +-
 Allura/allura/lib/plugin.py          |  120 ++++++++++++++--------------
 Allura/allura/model/auth.py          |   15 ++--
 Allura/allura/model/project.py       |    2 +-
 Allura/development.ini               |    2 +-
 5 files changed, 74 insertions(+), 69 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/49edd6b4/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 0f2e400..9c3c5c5 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -69,7 +69,9 @@ class NeighborhoodController(object):
             # create user-project if it is missing
             user = M.User.query.get(username=pname)
             if user:
-                project = self.neighborhood.register_project('u/' + user.username, user=user,
user_project=True)
+                project = self.neighborhood.register_project(
+                    plugin.AuthenticationProvider.get(request).user_project_shortname(user),
+                    user=user, user_project=True)
         if project is None:
             # look for neighborhood tools matching the URL
             project = self.neighborhood.neighborhood_project

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/49edd6b4/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 0c2aca4..f18ee99 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -144,19 +144,19 @@ class AuthenticationProvider(object):
             },
         ]
 
-    def project_url(self, user):
+    def user_project_shortname(self, user):
         '''
         :param user: a :class:`User <allura.model.auth.User>`
         :rtype: str
         '''
-        raise NotImplementedError, 'project_url'
+        raise NotImplementedError, 'user_project_shortname'
 
-    def user_by_project_url(self, shortname):
+    def user_by_project_shortname(self, shortname):
         '''
         :param str: shortname
         :rtype: user: a :class:`User <allura.model.auth.User>`
         '''
-        raise NotImplementedError, 'user_by_project_url'
+        raise NotImplementedError, 'user_by_project_shortname'
 
     def update_notifications(self, user):
         raise NotImplemented, 'update_notifications'
@@ -207,10 +207,10 @@ class LocalAuthenticationProvider(AuthenticationProvider):
         hashpass = sha256(salt + password.encode('utf-8')).digest()
         return 'sha256' + salt + b64encode(hashpass)
 
-    def project_url(self, user):
-        return '/u/' + user.username.replace('_', '-') + '/'
+    def user_project_shortname(self, user):
+        return 'u/' + user.username.replace('_', '-')
 
-    def user_by_project_url(self, shortname):
+    def user_by_project_shortname(self, shortname):
         from allura import model as M
         return M.User.query.get(username=shortname)
 
@@ -625,101 +625,101 @@ class ThemeProvider(object):
         from allura.lib.widgets.forms import PasswordChangeForm
         return PasswordChangeForm(action='/auth/prefs/change_password')
 
-    @LazyProperty 
-    def personal_data_form(self): 
-        ''' 
-        :return: None, or an easywidgets Form to render on the user preferences page 
-        ''' 
-        from allura.lib.widgets.forms import PersonalDataForm 
+    @LazyProperty
+    def personal_data_form(self):
+        '''
+        :return: None, or an easywidgets Form to render on the user preferences page
+        '''
+        from allura.lib.widgets.forms import PersonalDataForm
         return PersonalDataForm()
 
-    @LazyProperty 
-    def add_telnumber_form(self): 
-        ''' 
-        :return: None, or an easywidgets Form to render on the user preferences page to 
+    @LazyProperty
+    def add_telnumber_form(self):
+        '''
+        :return: None, or an easywidgets Form to render on the user preferences page to
                  allow adding a telephone number.
-        ''' 
-        from allura.lib.widgets.forms import AddTelNumberForm 
+        '''
+        from allura.lib.widgets.forms import AddTelNumberForm
         return AddTelNumberForm()
 
-    @LazyProperty 
-    def add_website_form(self): 
-        ''' 
-        :return: None, or an easywidgets Form to render on the user preferences page to 
+    @LazyProperty
+    def add_website_form(self):
+        '''
+        :return: None, or an easywidgets Form to render on the user preferences page to
                  allow adding a personal website url.
-        ''' 
-        from allura.lib.widgets.forms import AddWebsiteForm 
+        '''
+        from allura.lib.widgets.forms import AddWebsiteForm
         return AddWebsiteForm()
 
-    @LazyProperty 
-    def skype_account_form(self): 
-        ''' 
-        :return: None, or an easywidgets Form to render on the user preferences page to 
+    @LazyProperty
+    def skype_account_form(self):
+        '''
+        :return: None, or an easywidgets Form to render on the user preferences page to
                  allow setting the user's Skype account.
-        ''' 
-        from allura.lib.widgets.forms import SkypeAccountForm 
+        '''
+        from allura.lib.widgets.forms import SkypeAccountForm
         return SkypeAccountForm()
 
-    @LazyProperty 
-    def remove_textvalue_form(self): 
-        ''' 
-        :return: None, or an easywidgets Form to render on the user preferences page to 
+    @LazyProperty
+    def remove_textvalue_form(self):
+        '''
+        :return: None, or an easywidgets Form to render on the user preferences page to
                  allow removing a single text value from a list.
-        ''' 
-        from allura.lib.widgets.forms import RemoveTextValueForm 
+        '''
+        from allura.lib.widgets.forms import RemoveTextValueForm
         return RemoveTextValueForm()
 
-    @LazyProperty 
+    @LazyProperty
     def add_socialnetwork_form(self):
         '''
-        :return: None, or an easywidgets Form to render on  the user preferences page to

+        :return: None, or an easywidgets Form to render on  the user preferences page to
                  allow adding a social network account.
         '''
         from allura.lib.widgets.forms import AddSocialNetworkForm
         return AddSocialNetworkForm(action='/auth/prefs/add_social_network')
 
-    @LazyProperty 
+    @LazyProperty
     def remove_socialnetwork_form(self):
         '''
-        :return: None, or an easywidgets Form to render on  the user preferences page to

+        :return: None, or an easywidgets Form to render on  the user preferences page to
                  allow removing a social network account.
         '''
         from allura.lib.widgets.forms import RemoveSocialNetworkForm
         return RemoveSocialNetworkForm(action='/auth/prefs/remove_social_network')
 
-    @LazyProperty 
-    def add_timeslot_form(self): 
-        ''' 
+    @LazyProperty
+    def add_timeslot_form(self):
+        '''
         :return: None, or an easywidgets Form to render on the user preferences page
                  to allow creating a new availability timeslot
-        ''' 
-        from allura.lib.widgets.forms import AddTimeSlotForm 
+        '''
+        from allura.lib.widgets.forms import AddTimeSlotForm
         return AddTimeSlotForm()
 
-    @LazyProperty 
-    def remove_timeslot_form(self): 
-        ''' 
+    @LazyProperty
+    def remove_timeslot_form(self):
+        '''
         :return: None, or an easywidgets Form to render on the user preferences page
                  to remove a timeslot
-        ''' 
-        from allura.lib.widgets.forms import RemoveTimeSlotForm 
+        '''
+        from allura.lib.widgets.forms import RemoveTimeSlotForm
         return RemoveTimeSlotForm()
 
-    @LazyProperty 
-    def add_inactive_period_form(self): 
-        ''' 
+    @LazyProperty
+    def add_inactive_period_form(self):
+        '''
         :return: None, or an easywidgets Form to render on the user preferences page
                  to allow creating a new period of inactivity
-        ''' 
+        '''
         from allura.lib.widgets.forms import AddInactivePeriodForm
         return AddInactivePeriodForm()
 
-    @LazyProperty 
-    def remove_inactive_period_form(self): 
-        ''' 
+    @LazyProperty
+    def remove_inactive_period_form(self):
+        '''
         :return: None, or an easywidgets Form to render on the user preferences page
                  to allow removing an existing period of inactivity
-        ''' 
+        '''
         from allura.lib.widgets.forms import RemoveInactivePeriodForm
         return RemoveInactivePeriodForm()
 
@@ -735,7 +735,7 @@ class ThemeProvider(object):
     @LazyProperty
     def remove_trove_category(self):
         '''
-        :return: None, or an easywidgets Form to render on the page to remove 
+        :return: None, or an easywidgets Form to render on the page to remove
                  an existing trove_category
         '''
         from allura.lib.widgets.forms import RemoveTroveCategoryForm

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/49edd6b4/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 7a6d366..1493400 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -476,7 +476,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
         return retval
 
     def url(self):
-        return plugin.AuthenticationProvider.get(request).project_url(self)
+        return '/%s/' % plugin.AuthenticationProvider.get(request).user_project_shortname(self)
 
     @memoize
     def icon_url(self):
@@ -568,13 +568,14 @@ class User(MappedClass, ActivityNode, ActivityObject):
     @classmethod
     def register(cls, doc, make_project=True):
         from allura import model as M
-        from forgewiki import model as WM
-        user = plugin.AuthenticationProvider.get(request).register_user(doc)
+        auth_provider = plugin.AuthenticationProvider.get(request)
+        user = auth_provider.register_user(doc)
         if user and 'display_name' in doc:
             user.set_pref('display_name', doc['display_name'])
         if user and make_project:
             n = M.Neighborhood.query.get(name='Users')
-            p = n.register_project('u/' + user.username, user=user, user_project=True)
+            n.register_project(auth_provider.user_project_shortname(user),
+                               user=user, user_project=True)
         return user
 
     def private_project(self):
@@ -582,12 +583,14 @@ class User(MappedClass, ActivityNode, ActivityObject):
         Returns the personal user-project for the user
         '''
         from .project import Project
-        p = Project.query.get(shortname='u/%s' % self.username, deleted=False)
+        auth_provider = plugin.AuthenticationProvider.get(request)
+        project_shortname = auth_provider.user_project_shortname(self)
+        p = Project.query.get(shortname=project_shortname, deleted=False)
         if not p and self != User.anonymous():
             # create user-project on demand if it is missing
             from allura import model as M
             n = M.Neighborhood.query.get(name='Users')
-            p = n.register_project('u/' + self.username, user=self, user_project=True)
+            p = n.register_project(project_shortname, user=self, user_project=True)
         return p
 
     @property

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/49edd6b4/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index de54e76..7861243 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -292,7 +292,7 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         '''
         user = None
         if self.is_user_project:
-            user = plugin.AuthenticationProvider.get(request).user_by_project_url(self.shortname[2:])
+            user = plugin.AuthenticationProvider.get(request).user_by_project_shortname(self.shortname[2:])
         return user
 
     @LazyProperty

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/49edd6b4/Allura/development.ini
----------------------------------------------------------------------
diff --git a/Allura/development.ini b/Allura/development.ini
index 0ad6a52..a543b30 100644
--- a/Allura/development.ini
+++ b/Allura/development.ini
@@ -173,7 +173,7 @@ forgemail.return_path = noreply@sf.net
 
 # Specify the number of projects allowed to be created by a user
 # depending on the age of their user account.
-# Keys are number of seconds, values are max number of projects allowed 
+# Keys are number of seconds, values are max number of projects allowed
 # (including the default user-project, so you probably want to add 1)
 # This example allows for 1 project if the account is less than an hour old
 # and 5 projects if the account is less than a day old.  No limits after that


Mime
View raw message