allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [01/26] git commit: [#7589] ticket:622 Make User indexable
Date Fri, 19 Sep 2014 20:04:15 GMT
Repository: allura
Updated Branches:
  refs/heads/master 3edcba7f0 -> a9883cd23


[#7589] ticket:622 Make User indexable


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

Branch: refs/heads/master
Commit: 55be3103b7a57a57d8379db18eda2d0cc7547e7c
Parents: 3edcba7
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Aug 4 14:16:46 2014 +0300
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Sep 19 19:35:37 2014 +0000

----------------------------------------------------------------------
 Allura/allura/lib/plugin.py |  8 ++++++++
 Allura/allura/model/auth.py | 38 ++++++++++++++++++++++++++++++++++++--
 2 files changed, 44 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/55be3103/Allura/allura/lib/plugin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 8537f63..ccdf62c 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -284,6 +284,10 @@ class AuthenticationProvider(object):
             return True
         return False
 
+    def index_user(self, user):
+        """Put here additional fields for user index in SOLR."""
+        return {}
+
 
 class LocalAuthenticationProvider(AuthenticationProvider):
 
@@ -374,6 +378,10 @@ class LocalAuthenticationProvider(AuthenticationProvider):
             d = datetime.utcfromtimestamp(calendar.timegm(d.utctimetuple()))
         return d
 
+    def index_user(self, user):
+        fields = super(LocalAuthenticationProvider, self).index_user(user)
+        return dict(user_registration_date_dt=self.user_registration_date(user), **fields)
+
 
 def ldap_conn(who=None, cred=None):
     '''

http://git-wip-us.apache.org/repos/asf/allura/blob/55be3103/Allura/allura/model/auth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 827c6fc..9ceb341 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -46,6 +46,7 @@ import allura.tasks.mail_tasks
 from allura.lib import helpers as h
 from allura.lib import plugin
 from allura.lib.decorators import memoize
+from allura.lib.search import SearchIndexable
 
 from .session import main_orm_session, main_doc_session
 from .session import project_orm_session
@@ -210,7 +211,7 @@ class FieldPropertyDisplayName(FieldProperty):
         return display_name
 
 
-class User(MappedClass, ActivityNode, ActivityObject):
+class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
     SALT_LEN = 8
 
     class __mongometa__:
@@ -219,6 +220,8 @@ class User(MappedClass, ActivityNode, ActivityObject):
         indexes = ['tool_data.sfx.userid', 'tool_data.AuthPasswordReset.hash']
         unique_indexes = ['username']
 
+    type_s = 'User'
+
     _id = FieldProperty(S.ObjectId)
     sfx_userid = FieldProperty(S.Deprecated)
     username = FieldProperty(str)
@@ -227,7 +230,7 @@ class User(MappedClass, ActivityNode, ActivityObject):
     last_password_updated = FieldProperty(datetime)
     projects = FieldProperty(S.Deprecated)
     # full mount point: prefs dict
-    tool_preferences = FieldProperty({str: {str: None}})
+    tool_preferences = FieldProperty(S.Deprecated)
     tool_data = FieldProperty({str: {str: None}})  # entry point: prefs dict
     disabled = FieldProperty(bool, if_missing=False)
 
@@ -280,6 +283,37 @@ class User(MappedClass, ActivityNode, ActivityObject):
         session_ip=str,
         session_ua=str))
 
+    def index(self):
+        provider = plugin.AuthenticationProvider.get(None)  # no need in request here
+        localization = '%s/%s' % (
+            self.get_pref('localization')['country'],
+            self.get_pref('localization')['city'])
+        fields = dict(
+            id=self.index_id(),
+            title='User %s' % self.username,
+            type_s=self.type_s,
+            username_s=self.username,
+            email_addresses=self.email_addresses,
+            last_password_updated_dt=self.last_password_updated,
+            disabled_b=self.disabled,
+            results_per_page_i=self.get_pref('results_per_page'),
+            email_address_s=self.get_pref('email_address'),
+            email_format_s=self.get_pref('email_format'),
+            disable_user_messages_b=self.get_pref('disable_user_messages'),
+            display_name_s=self.get_pref('display_name'),
+            sex_s=self.get_pref('sex'),
+            birthday_dt=self.get_pref('birthday'),
+            localization_s=localization,
+            timezone_s=self.get_pref('timezone'),
+            socialnetworks=self.get_pref('socialnetworks'),
+            telnumbers=self.get_pref('telnumbers'),
+            skypeaccount_s=self.get_pref('skypeaccount'),
+            webpages=self.get_pref('webpages'),
+            skills=self.get_skills(),
+            last_access=self.last_access,
+        )
+        return dict(provider.index_user(self), **fields)
+
     def track_login(self, req):
         user_ip = req.headers.get('X_FORWARDED_FOR', req.remote_addr)
         user_agent = req.headers.get('User-Agent')


Mime
View raw message