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 b8de78dbb [#8606] Add encrypted field for email from the EmailAddress
model
b8de78dbb is described below
commit b8de78dbbc909380f4c454ef4cf3885a11e0ca7e
Author: Carlos Cruz <[email protected]>
AuthorDate: Wed May 13 10:53:46 2026 -0600
[#8606] Add encrypted field for email from the EmailAddress model
---
Allura/allura/model/auth.py | 18 +++++++++++++++++-
Allura/allura/tests/model/test_auth.py | 8 ++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/model/auth.py b/Allura/allura/model/auth.py
index 8fdbcc600..22eee8722 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
from ming.odm.declarative import MappedClass
from ming.odm.odmsession import ThreadLocalODMSession
@@ -74,6 +74,20 @@ def __init__(self, **kwargs):
super().__init__(User, allow_none=True, **kwargs)
+class EmailAddressMapperExtension(MapperExtension):
+
+ def before_insert(self, instance, state, sess):
+ self._set_email_encrypted(instance, state)
+
+ def before_update(self, instance, state, sess):
+ self._set_email_encrypted(instance, state)
+
+ @staticmethod
+ def _set_email_encrypted(instance, state):
+ email = state.document.get('email')
+ state.document['email_encrypted'] = instance.encr(email)
+
+
class EmailAddress(MappedClass):
re_format = re.compile(r'^.*\s+<(.*)>\s*$')
@@ -82,11 +96,13 @@ class __mongometa__:
session = main_orm_session
indexes = ['nonce', ]
unique_indexes = [('email', 'claimed_by_user_id'), ]
+ extensions = [EmailAddressMapperExtension]
query: Query[EmailAddress]
_id = FieldProperty(S.ObjectId)
email = FieldProperty(str)
+ email_encrypted = FieldProperty(S.Binary)
claimed_by_user_id = FieldProperty(S.ObjectId, if_missing=None)
confirmed = FieldProperty(bool, if_missing=False)
confirmed_date = FieldProperty(datetime)
diff --git a/Allura/allura/tests/model/test_auth.py
b/Allura/allura/tests/model/test_auth.py
index 2496c8ab1..839b9912e 100644
--- a/Allura/allura/tests/model/test_auth.py
+++ b/Allura/allura/tests/model/test_auth.py
@@ -64,6 +64,14 @@ def test_email_address(self):
c.user.claim_address('[email protected]')
assert '[email protected]' in c.user.email_addresses
+ def test_email_address_stores_encrypted_email(self):
+ addr = M.EmailAddress.create('[email protected]')
+ direct_addr = M.EmailAddress(email='[email protected]')
+ ThreadLocalODMSession.flush_all()
+
+ assert addr.email_encrypted == M.EmailAddress.encr('[email protected]')
+ assert direct_addr.email_encrypted ==
M.EmailAddress.encr('[email protected]')
+
def selftest_email_address_lookup_helpers():
addr = M.EmailAddress.create('[email protected]')
nobody = M.EmailAddress.create('[email protected]')