mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-31 11:49:58 -04:00
Refactor User.webauthn_credentials into a ModelList
This saves a bit of repetition, and lets us attach other methods to the collection, rather than having multiple methods on the user object prefixed with the same name, or random functions floating about.
This commit is contained in:
@@ -10,7 +10,7 @@ from app.models.roles_and_permissions import (
|
||||
all_permissions,
|
||||
translate_permissions_from_db_to_admin_roles,
|
||||
)
|
||||
from app.models.webauthn_credential import WebAuthnCredential
|
||||
from app.models.webauthn_credential import WebAuthnCredentials
|
||||
from app.notify_client import InviteTokenError
|
||||
from app.notify_client.invite_api_client import invite_api_client
|
||||
from app.notify_client.org_invite_api_client import org_invite_api_client
|
||||
@@ -350,15 +350,7 @@ class User(JSONModel, UserMixin):
|
||||
|
||||
@property
|
||||
def webauthn_credentials(self):
|
||||
return [WebAuthnCredential(json) for json in
|
||||
user_api_client.get_webauthn_credentials_for_user(self.id)]
|
||||
|
||||
@property
|
||||
def webauthn_credentials_as_cbor(self):
|
||||
return [
|
||||
credential.to_credential_data()
|
||||
for credential in self.webauthn_credentials
|
||||
]
|
||||
return WebAuthnCredentials(self.id)
|
||||
|
||||
def create_webauthn_credential(self, credential):
|
||||
user_api_client.create_webauthn_credential_for_user(
|
||||
|
||||
@@ -6,7 +6,8 @@ from fido2.cose import UnsupportedKey
|
||||
from fido2.ctap2 import AttestationObject, AttestedCredentialData
|
||||
from flask import current_app
|
||||
|
||||
from app.models import JSONModel
|
||||
from app.models import JSONModel, ModelList
|
||||
from app.notify_client.user_api_client import user_api_client
|
||||
|
||||
|
||||
class RegistrationError(Exception):
|
||||
@@ -60,3 +61,16 @@ class WebAuthnCredential(JSONModel):
|
||||
'credential_data': self.credential_data,
|
||||
'registration_response': self.registration_response,
|
||||
}
|
||||
|
||||
|
||||
class WebAuthnCredentials(ModelList):
|
||||
|
||||
model = WebAuthnCredential
|
||||
client_method = user_api_client.get_webauthn_credentials_for_user
|
||||
|
||||
@property
|
||||
def as_cbor(self):
|
||||
return [credential.to_credential_data() for credential in self]
|
||||
|
||||
def by_id(self, key_id):
|
||||
return next((key for key in self if key.id == key_id), None)
|
||||
|
||||
Reference in New Issue
Block a user