05/22 Enhance codes and fix bugs 2
This commit is contained in:
+10
-3
@@ -29,14 +29,21 @@ def list_emergency():
|
||||
)
|
||||
).order_by(EmergencyAccess.created_at.desc()).all()
|
||||
|
||||
grantor_ids = {ea.grantor_id for ea in access}
|
||||
grantors = (
|
||||
{u.id: u for u in User.query.filter(User.id.in_(grantor_ids)).all()}
|
||||
if grantor_ids else {}
|
||||
)
|
||||
|
||||
return jsonify({
|
||||
'grants': [ea.to_dict(grantor_email=user.email) for ea in grants],
|
||||
'access': [_ea_as_grantee(ea) for ea in access],
|
||||
'access': [_ea_as_grantee(ea, grantors.get(ea.grantor_id)) for ea in access],
|
||||
}), 200
|
||||
|
||||
|
||||
def _ea_as_grantee(ea: EmergencyAccess) -> dict:
|
||||
grantor = db.session.get(User, ea.grantor_id)
|
||||
def _ea_as_grantee(ea: EmergencyAccess, grantor: 'User | None' = None) -> dict:
|
||||
if grantor is None:
|
||||
grantor = db.session.get(User, ea.grantor_id)
|
||||
d = ea.to_dict(grantor_email=grantor.email if grantor else None)
|
||||
d['grantor_public_key'] = grantor.sharing_public_key if grantor else None
|
||||
return d
|
||||
|
||||
Reference in New Issue
Block a user