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):
role2.groups[group2].requires_mfa = True
self.assertSetEqual(user.compute_groups(), {group1})
db.session.add(TOTPMethod(user=user))
db.session.commit()
self.assertSetEqual(user.compute_groups(), {group1, group2})
def test_update_groups(self):
......
......@@ -18,6 +18,9 @@ from uffd.utils import nopad_b32decode, nopad_b32encode
from uffd.database import db
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))
class MFAType(enum.Enum):
......@@ -46,7 +49,6 @@ class MFAMethod(db.Model):
class RecoveryCodeMethod(MFAMethod):
code_salt = Column('recovery_salt', String(64))
code_hash = Column('recovery_hash', String(256))
user = relationship('User', backref='mfa_recovery_codes')
__mapper_args__ = {
'polymorphic_identity': MFAType.RECOVERY_CODE
......@@ -80,7 +82,6 @@ def _hotp(counter, key, digits=6):
class TOTPMethod(MFAMethod):
key = Column('totp_key', String(64))
last_counter = Column('totp_last_counter', Integer())
user = relationship('User', backref='mfa_totp_methods')
__mapper_args__ = {
'polymorphic_identity': MFAType.TOTP
......@@ -132,7 +133,6 @@ class TOTPMethod(MFAMethod):
class WebauthnMethod(MFAMethod):
_cred = Column('webauthn_cred', Text())
user = relationship('User', backref='mfa_webauthn_methods')
__mapper_args__ = {
'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