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/07/23 18:26:48 UTC
(allura) branch master updated: [#8613] Add encrypted field for user preferences email address
This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits 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 93857a099 [#8613] Add encrypted field for user preferences email address
93857a099 is described below
commit 93857a099cb1e2c59301d31b5f0b6035fe5b178f
Author: Carlos Cruz <ca...@slashdotmedia.com>
AuthorDate: Tue Jul 7 18:02:23 2026 +0000
[#8613] Add encrypted field for user preferences email address
---
Allura/allura/model/auth.py | 23 ++++++++++++++++++++++-
Allura/allura/tests/model/test_auth.py | 27 +++++++++++++++++++++++++++
2 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 4f526a5ae..1ee866005 100644
--- a/Allura/allura/model/auth.py
+++ b/Allura/allura/model/auth.py
@@ -38,7 +38,7 @@
from tg import tmpl_context as c, app_globals as g
from tg import request
from ming import schema as S
-from ming.odm import session, state
+from ming.odm import session, state, MapperExtension
from ming.odm import FieldProperty, RelationProperty, ForeignIdProperty, DecryptedProperty, DecryptedListProperty
from ming.odm.declarative import MappedClass
from ming.odm.odmsession import ThreadLocalODMSession
@@ -266,6 +266,15 @@ def get_decrypted(self, instance):
return super().__get__(instance, type(instance))
+class UserPreferencesMapperExtension(MapperExtension):
+
+ def before_insert(self, obj, state, sess):
+ obj.sync_preference_email_address_encrypted()
+
+ def before_update(self, obj, state, sess):
+ obj.sync_preference_email_address_encrypted()
+
+
class User(MappedClass, ActivityNode, ActivityObject, SearchIndexable):
SALT_LEN = 8
@@ -274,6 +283,7 @@ class __mongometa__:
session = main_orm_session
indexes = ['tool_data.AuthPasswordReset.hash']
unique_indexes = ['username']
+ extensions = [UserPreferencesMapperExtension]
custom_indexes = [
dict(fields=('tool_data.phone_verification.number_hash',), sparse=True),
]
@@ -302,6 +312,7 @@ class __mongometa__:
preferences = FieldProperty(dict(
results_per_page=int,
email_address=str,
+ email_address_encrypted=S.Binary,
email_format=str,
disable_user_messages=bool,
mention_notifications=bool,
@@ -788,6 +799,16 @@ def set_tool_data(self, tool, **kw):
d.update(kw)
state(self).soil()
+ @classmethod
+ def encrypt_preference_email_address(cls, email_address):
+ return cls.encr(email_address)
+
+ def sync_preference_email_address_encrypted(self):
+ preferences = dict(self.preferences or {})
+ preferences['email_address_encrypted'] = type(self).encrypt_preference_email_address(
+ preferences.get('email_address'))
+ self.preferences = preferences
+
def address_object(self, addr):
return EmailAddress.get(email=addr, claimed_by_user_id=self._id)
diff --git a/Allura/allura/tests/model/test_auth.py b/Allura/allura/tests/model/test_auth.py
index 15a1b20aa..9ac8a0966 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -467,6 +467,33 @@ def test_email_addresses_encrypted_is_synced_on_update(self):
assert 'email_addresses' not in state(user).document
assert state(user).document['email_addresses_encrypted'] == expected_encrypted
+ def test_preference_email_address_encrypted_is_populated_on_creation(self):
+ user = M.User(
+ username='preference-email-address-encrypted-create-test',
+ preferences={'email_address': 'primary@example.com'})
+ ThreadLocalODMSession.flush_all()
+
+ raw_preferences = state(user).document['preferences']
+ assert user.get_pref('email_address') == 'primary@example.com'
+ assert raw_preferences['email_address'] == 'primary@example.com'
+ assert raw_preferences['email_address_encrypted'] == M.User.encr('primary@example.com')
+ assert M.User.decr(raw_preferences['email_address_encrypted']) == 'primary@example.com'
+
+ def test_preference_email_address_encrypted_is_synced_on_update(self):
+ user = M.User(
+ username='preference-email-address-encrypted-update-test',
+ preferences={'email_address': 'old@example.com'})
+ ThreadLocalODMSession.flush_all()
+
+ user.set_pref('email_address', 'new@example.com')
+ ThreadLocalODMSession.flush_all()
+
+ raw_preferences = state(user).document['preferences']
+ assert user.get_pref('email_address') == 'new@example.com'
+ assert raw_preferences['email_address'] == 'new@example.com'
+ assert raw_preferences['email_address_encrypted'] == M.User.encr('new@example.com')
+ assert M.User.decr(raw_preferences['email_address_encrypted']) == 'new@example.com'
+
def test_set_display_name_pref_updates_encrypted_field_and_cache(self):
user = M.User(username='display-name-cache-test',
display_name='Original Display Name')