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 2026/01/20 14:58:57 UTC
(allura) 02/02: only update User.last_access for browser access, so scripts/api/etc don't get in there; make extra sure user reindexing still happens for other changes
This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
commit 9aae5c8094d412ed1bd732691a5aa7804c4c3c6f
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Tue Jan 20 09:58:41 2026 -0500
only update User.last_access for browser access, so scripts/api/etc don't get in there; make extra sure user reindexing still happens for other changes
---
Allura/allura/model/auth.py | 11 ++++++++---
Allura/allura/tests/model/test_auth.py | 10 +++++-----
2 files changed, 13 insertions(+), 8 deletions(-)
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index d4aa4e677..28ee44c5d 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -390,12 +390,14 @@ def track_login(self, req):
def track_active(self, req):
user_ip = utils.ip_address(req)
- user_agent = req.headers.get('User-Agent')
+ user_agent = req.headers.get('User-Agent') or ''
now = datetime.utcnow()
last_date = self.last_access['session_date']
date_changed = last_date is None or last_date.date() != now.date()
ip_changed = user_ip != self.last_access['session_ip']
ua_changed = user_agent != self.last_access['session_ua']
+ if not user_agent.startswith('Mozilla/'):
+ return
if date_changed or ip_changed or ua_changed:
self.last_access['session_date'] = datetime.utcnow()
self.last_access['session_ip'] = user_ip
@@ -583,7 +585,9 @@ def get_pref(self, pref_name):
return plugin.UserPreferencesProvider.get().get_pref(self, pref_name)
def set_pref(self, pref_name, pref_value):
- return plugin.UserPreferencesProvider.get().set_pref(self, pref_name, pref_value)
+ ret = plugin.UserPreferencesProvider.get().set_pref(self, pref_name, pref_value)
+ state(self).soil() # to make sure it gets reindexed in solr (even if pref is not part on the User ming model)
+ return ret
def add_multivalue_pref(self, pref_name, pref_data):
return plugin.UserPreferencesProvider.get().add_multivalue_pref(self, pref_name, pref_data)
@@ -912,7 +916,8 @@ def registration_date(self):
p = plugin.AuthenticationProvider.get(request)
return p.user_registration_date(self)
- # overriding since the old and new values are not being tracked for changes within a dictionary like preferences
+ # overriding since changed values may not be on User object itself, for example on the EmailAddress collection
+ # or preferences stored externally.
# This will ensure any changes get indexed by solr.
def should_update_index(self, old_doc, new_doc):
return True
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index ae9f20d02..2496c8ab1 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -340,12 +340,12 @@ def test_user_track_active(self):
assert c.user.last_access['session_ip'] is None
assert c.user.last_access['session_ua'] is None
- req = Mock(headers={'User-Agent': 'browser'}, remote_addr='addr')
+ req = Mock(headers={'User-Agent': 'Mozilla/browser'}, remote_addr='addr')
c.user.track_active(req)
c.user = M.User.by_username(c.user.username)
assert c.user.last_access['session_date'] is not None
assert c.user.last_access['session_ip'] == 'addr'
- assert c.user.last_access['session_ua'] == 'browser'
+ assert c.user.last_access['session_ua'] == 'Mozilla/browser'
# ensure that session activity tracked with a whole-day granularity
prev_date = c.user.last_access['session_date']
@@ -364,12 +364,12 @@ def test_user_track_active(self):
c.user.track_active(req)
c.user = M.User.by_username(c.user.username)
assert c.user.last_access['session_ip'] == 'new addr'
- assert c.user.last_access['session_ua'] == 'browser'
- req.headers['User-Agent'] = 'new browser'
+ assert c.user.last_access['session_ua'] == 'Mozilla/browser'
+ req.headers['User-Agent'] = 'Mozilla/new browser'
c.user.track_active(req)
c.user = M.User.by_username(c.user.username)
assert c.user.last_access['session_ip'] == 'new addr'
- assert c.user.last_access['session_ua'] == 'new browser'
+ assert c.user.last_access['session_ua'] == 'Mozilla/new browser'
def test_user_index(self):
c.user.email_addresses = ['email1', 'email2']