Skip to content
Snippets Groups Projects
Commit 4736d5a3 authored by Julian's avatar Julian
Browse files

Fix ORM relationship conflict warnings

SQLAlchemy v1.4 (Debian Bookworm) annoyingly warns about overlapping
user/mfa_method relationships.

Fixes #146
parent a662ceb2
No related branches found
No related tags found
No related merge requests found
...@@ -57,6 +57,7 @@ class TestUserRoleAttributes(UffdTestCase): ...@@ -57,6 +57,7 @@ class TestUserRoleAttributes(UffdTestCase):
role2.groups[group2].requires_mfa = True role2.groups[group2].requires_mfa = True
self.assertSetEqual(user.compute_groups(), {group1}) self.assertSetEqual(user.compute_groups(), {group1})
db.session.add(TOTPMethod(user=user)) db.session.add(TOTPMethod(user=user))
db.session.commit()
self.assertSetEqual(user.compute_groups(), {group1, group2}) self.assertSetEqual(user.compute_groups(), {group1, group2})
def test_update_groups(self): def test_update_groups(self):
......
...@@ -18,6 +18,9 @@ from uffd.utils import nopad_b32decode, nopad_b32encode ...@@ -18,6 +18,9 @@ from uffd.utils import nopad_b32decode, nopad_b32encode
from uffd.database import db from uffd.database import db
from .user import User from .user import User
User.mfa_recovery_codes = relationship('RecoveryCodeMethod', viewonly=True)
User.mfa_totp_methods = relationship('TOTPMethod', viewonly=True)
User.mfa_webauthn_methods = relationship('WebauthnMethod', viewonly=True)
User.mfa_enabled = property(lambda user: bool(user.mfa_totp_methods or user.mfa_webauthn_methods)) User.mfa_enabled = property(lambda user: bool(user.mfa_totp_methods or user.mfa_webauthn_methods))
class MFAType(enum.Enum): class MFAType(enum.Enum):
...@@ -46,7 +49,6 @@ class MFAMethod(db.Model): ...@@ -46,7 +49,6 @@ class MFAMethod(db.Model):
class RecoveryCodeMethod(MFAMethod): class RecoveryCodeMethod(MFAMethod):
code_salt = Column('recovery_salt', String(64)) code_salt = Column('recovery_salt', String(64))
code_hash = Column('recovery_hash', String(256)) code_hash = Column('recovery_hash', String(256))
user = relationship('User', backref='mfa_recovery_codes')
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': MFAType.RECOVERY_CODE 'polymorphic_identity': MFAType.RECOVERY_CODE
...@@ -80,7 +82,6 @@ def _hotp(counter, key, digits=6): ...@@ -80,7 +82,6 @@ def _hotp(counter, key, digits=6):
class TOTPMethod(MFAMethod): class TOTPMethod(MFAMethod):
key = Column('totp_key', String(64)) key = Column('totp_key', String(64))
last_counter = Column('totp_last_counter', Integer()) last_counter = Column('totp_last_counter', Integer())
user = relationship('User', backref='mfa_totp_methods')
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': MFAType.TOTP 'polymorphic_identity': MFAType.TOTP
...@@ -132,7 +133,6 @@ class TOTPMethod(MFAMethod): ...@@ -132,7 +133,6 @@ class TOTPMethod(MFAMethod):
class WebauthnMethod(MFAMethod): class WebauthnMethod(MFAMethod):
_cred = Column('webauthn_cred', Text()) _cred = Column('webauthn_cred', Text())
user = relationship('User', backref='mfa_webauthn_methods')
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': MFAType.WEBAUTHN 'polymorphic_identity': MFAType.WEBAUTHN
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment