This is an automated email from the ASF dual-hosted git repository.
kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new 5208f9a Have a field to track user registration date, not just rely
on _id
5208f9a is described below
commit 5208f9a295503bb9c5fea4e03c5655e91ec7b85c
Author: Dave Brondsema <[email protected]>
AuthorDate: Tue Nov 2 17:30:53 2021 -0400
Have a field to track user registration date, not just rely on _id
---
Allura/allura/lib/plugin.py | 15 +++++++--------
Allura/allura/model/auth.py | 10 ++++------
Allura/allura/tests/model/test_auth.py | 1 +
Allura/allura/tests/test_plugin.py | 1 +
Allura/allura/tests/unit/test_ldap_auth_provider.py | 1 +
5 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/Allura/allura/lib/plugin.py b/Allura/allura/lib/plugin.py
index 0d46a8a..ce842ad 100644
--- a/Allura/allura/lib/plugin.py
+++ b/Allura/allura/lib/plugin.py
@@ -518,6 +518,8 @@ class LocalAuthenticationProvider(AuthenticationProvider):
u = M.User(**user_doc)
if 'password' in user_doc:
u.set_password(user_doc['password'])
+ if 'reg_date' not in user_doc:
+ u.reg_date = datetime.utcnow()
return u
def _login(self):
@@ -618,23 +620,20 @@ class LocalAuthenticationProvider(AuthenticationProvider):
return ''
def user_registration_date(self, user):
+ if user.reg_date:
+ return user.reg_date
if user._id:
- return user._id.generation_time
+ d = user._id.generation_time
+ # generation_time returns tz-aware datetime (in UTC) but we're
using naive UTC time everywhere
+ return datetime.utcfromtimestamp(calendar.timegm(d.utctimetuple()))
return datetime.utcnow()
def get_last_password_updated(self, user):
d = user.last_password_updated
if d is None:
d = self.user_registration_date(user)
- # _id.generation_time returns aware datetime (in UTC)
- # but we're using naive UTC time everywhere
- 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):
'''
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index dd47515..7df4c8a 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -259,7 +259,8 @@ class User(MappedClass, ActivityNode, ActivityObject,
SearchIndexable):
username = FieldProperty(str)
email_addresses = FieldProperty([str])
password = FieldProperty(str)
- last_password_updated = FieldProperty(datetime)
+ last_password_updated = FieldProperty(datetime) # to access, use
AuthProvider's get_last_password_updated
+ reg_date = FieldProperty(datetime) # to access, use
user.registration_date()
projects = FieldProperty(S.Deprecated)
# full mount point: prefs dict
tool_preferences = FieldProperty(S.Deprecated)
@@ -360,6 +361,7 @@ class User(MappedClass, ActivityNode, ActivityObject,
SearchIndexable):
last_access_session_date_dt=self.last_access['session_date'],
last_access_session_ip_s=self.last_access['session_ip'],
last_access_session_ua_t=self.last_access['session_ua'],
+ user_registration_date_dt=self.registration_date(),
)
return dict(provider.index_user(self), **fields)
@@ -831,11 +833,7 @@ class User(MappedClass, ActivityNode, ActivityObject,
SearchIndexable):
def registration_date(self):
p = plugin.AuthenticationProvider.get(request)
- d = p.user_registration_date(self)
- # provider's user_registration_date returns aware datetime (in UTC)
- # but we're using naive UTC time everywhere
- d = datetime.utcfromtimestamp(calendar.timegm(d.utctimetuple()))
- return d
+ return p.user_registration_date(self)
class ProjectRole(MappedClass):
diff --git a/Allura/allura/tests/model/test_auth.py
b/Allura/allura/tests/model/test_auth.py
index a9b9d35..6752eb3 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -147,6 +147,7 @@ def test_user():
u = M.User.register(dict(
username='nosetest-user'))
ThreadLocalORMSession.flush_all()
+ assert u.reg_date
assert_equal(u.private_project().shortname, 'u/nosetest-user')
roles = g.credentials.user_roles(
u._id, project_id=u.private_project().root_project._id)
diff --git a/Allura/allura/tests/test_plugin.py
b/Allura/allura/tests/test_plugin.py
index 51f4345..ce9645a 100644
--- a/Allura/allura/tests/test_plugin.py
+++ b/Allura/allura/tests/test_plugin.py
@@ -671,6 +671,7 @@ class TestLocalAuthenticationProvider(object):
user = Mock()
user._id = ObjectId()
user.last_password_updated = None
+ user.reg_date = None
upd = self.provider.get_last_password_updated(user)
gen_time = dt.datetime.utcfromtimestamp(
calendar.timegm(user._id.generation_time.utctimetuple()))
diff --git a/Allura/allura/tests/unit/test_ldap_auth_provider.py
b/Allura/allura/tests/unit/test_ldap_auth_provider.py
index d3a37d5..27c6dcd 100644
--- a/Allura/allura/tests/unit/test_ldap_auth_provider.py
+++ b/Allura/allura/tests/unit/test_ldap_auth_provider.py
@@ -148,6 +148,7 @@ class TestLdapAuthenticationProvider(object):
user = Mock()
user._id = ObjectId()
user.last_password_updated = None
+ user.reg_date = None
upd = self.provider.get_last_password_updated(user)
gen_time = datetime.utcfromtimestamp(
calendar.timegm(user._id.generation_time.utctimetuple()))