Skip to content

Commit bcc5a9b

Browse files
clean up
1 parent 21e2c24 commit bcc5a9b

File tree

3 files changed

+49
-288
lines changed

3 files changed

+49
-288
lines changed

src/quart_sqlalchemy/sim/handle.py

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,13 @@ def get_or_create_by_email_and_client_id(
173173
)
174174
return auth_user
175175

176-
def get_by_id_and_validate_exists(self, auth_user_id):
177-
"""This function helps formalize how a non-existent auth user should be handled."""
178-
auth_user = self.logic.AuthUser.get_by_id(self.session_factory(), auth_user_id)
179-
if auth_user is None:
180-
raise RuntimeError('resource_name="auth_user"')
181-
return auth_user
182-
183-
# This function is reserved for consolidating into a canonical user. Do not
184-
# call this function under other circumstances as it will automatically set
185-
# the user as verified. See ch-25343 for additional details.
186176
def create_verified_user(
187177
self,
188178
client_id,
189179
email,
190180
user_type=EntityType.FORTMATIC.value,
191181
**kwargs,
192182
):
193-
# with self.session_factory() as session:
194-
# with self.logic.begin(ro=False) as session:
195183
session = self.session_factory()
196184
with session.begin_nested():
197185
auid = self.logic.AuthUser.add_by_email_and_client_id(
@@ -231,21 +219,6 @@ def get_by_client_id_and_user_type(
231219
limit=limit,
232220
)
233221

234-
def get_by_client_ids_and_user_type(
235-
self,
236-
client_ids,
237-
user_type,
238-
offset=None,
239-
limit=None,
240-
):
241-
return self.logic.AuthUser.get_by_client_ids_and_user_type(
242-
self.session_factory(),
243-
client_ids,
244-
user_type,
245-
offset=offset,
246-
limit=limit,
247-
)
248-
249222
def exist_by_email_client_id_and_user_type(self, email, client_id, user_type):
250223
return self.logic.AuthUser.exist_by_email_and_client_id(
251224
self.session_factory(),
@@ -257,11 +230,6 @@ def exist_by_email_client_id_and_user_type(self, email, client_id, user_type):
257230
def update_email_by_id(self, model_id, email):
258231
return self.logic.AuthUser.update_by_id(self.session_factory(), model_id, email=email)
259232

260-
def update_phone_number_by_id(self, model_id, phone_number):
261-
return self.logic.AuthUser.update_by_id(
262-
self.session_factory(), model_id, phone_number=phone_number
263-
)
264-
265233
def get_by_email_client_id_and_user_type(self, email, client_id, user_type):
266234
return self.logic.AuthUser.get_by_email_and_client_id(
267235
self.session_factory(),
@@ -299,68 +267,17 @@ def set_role_by_email_magic_client_id(self, email, magic_client_id, role):
299267

300268
return self.logic.AuthUser.update_by_id(session, auth_user.id, **{role: True})
301269

302-
def search_by_client_id_and_substring(
303-
self,
304-
client_id,
305-
substring,
306-
offset=None,
307-
limit=10,
308-
):
309-
if not isinstance(substring, str) or len(substring) < 3:
310-
raise InvalidSubstringError()
311-
312-
auth_users = self.logic.AuthUser.get_by_client_id_with_substring_search(
313-
self.session_factory(),
314-
client_id,
315-
substring,
316-
offset=offset,
317-
limit=limit,
318-
)
319-
320-
return auth_users
321-
322-
def is_magic_connect_enabled(self, auth_user_id=None, auth_user=None):
323-
if auth_user is None and auth_user_id is None:
324-
raise Exception("At least one argument needed: auth_user_id or auth_user.")
325-
326-
if auth_user is None:
327-
auth_user = self.get_by_id(auth_user_id)
328-
329-
return auth_user.user_type == EntityType.CONNECT.value
330-
331270
def mark_as_inactive(self, auth_user_id):
332271
self.logic.AuthUser.update_by_id(self.session_factory(), auth_user_id, is_active=False)
333272

334-
def get_by_email_and_wallet_type_for_interop(self, email, wallet_type, network):
335-
"""
336-
Opinionated method for fetching AuthWallets by email address, wallet_type and network.
337-
"""
338-
return self.logic.AuthUser.get_by_email_for_interop(
339-
self.session_factory(),
340-
email=email,
341-
wallet_type=wallet_type,
342-
network=network,
343-
)
344-
345-
def get_magic_connect_auth_user(self, auth_user_id):
346-
auth_user = self.get_by_id_and_validate_exists(auth_user_id)
347-
if not auth_user.is_magic_connect_user:
348-
raise RuntimeError("RequestForbidden")
349-
return auth_user
350-
351273

352274
@signals.auth_user_duplicate.connect
353275
def handle_duplicate_auth_users(
354276
app: Quart,
355277
original_auth_user_id: ObjectID,
356278
duplicate_auth_user_ids: t.Sequence[ObjectID],
357279
) -> None:
358-
logger.info(f"{len(duplicate_auth_user_ids)} dupe(s) found for {original_auth_user_id}")
359-
360280
for dupe_id in duplicate_auth_user_ids:
361-
logger.info(
362-
f"marking auth_user_id {dupe_id} as inactive, in favor of original {original_auth_user_id}",
363-
)
364281
app.container.logic().AuthUser.update_by_id(dupe_id, is_active=False)
365282

366283

src/quart_sqlalchemy/sim/logic.py

Lines changed: 0 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -226,43 +226,6 @@ def get_by_session_token(
226226
)
227227
)
228228

229-
@provide_global_contextual_session
230-
def get_or_add_by_phone_number_and_client_id(
231-
self,
232-
session,
233-
client_id,
234-
phone_number,
235-
user_type=EntityType.FORTMATIC.value,
236-
):
237-
if phone_number is None:
238-
raise MissingPhoneNumber()
239-
240-
row = self.get_by_phone_number_and_client_id(
241-
session=session,
242-
phone_number=phone_number,
243-
client_id=client_id,
244-
user_type=user_type,
245-
)
246-
247-
if row:
248-
return row
249-
250-
row = self._repository.add(
251-
session=session,
252-
phone_number=phone_number,
253-
client_id=client_id,
254-
user_type=user_type,
255-
provenance=Provenance.SMS,
256-
)
257-
logger.info(
258-
"New auth user (id: {}) created by phone number (client_id: {})".format(
259-
row.id,
260-
client_id,
261-
),
262-
)
263-
264-
return row
265-
266229
@provide_global_contextual_session
267230
def get_by_active_identifier_and_client_id(
268231
self,
@@ -319,25 +282,6 @@ def get_by_email_and_client_id(
319282
for_update=for_update,
320283
)
321284

322-
@provide_global_contextual_session
323-
def get_by_phone_number_and_client_id(
324-
self,
325-
session,
326-
phone_number,
327-
client_id,
328-
user_type=EntityType.FORTMATIC.value,
329-
):
330-
if phone_number is None:
331-
raise MissingPhoneNumber()
332-
333-
return self.get_by_active_identifier_and_client_id(
334-
session=session,
335-
identifier_field=auth_user_model.phone_number,
336-
identifier_value=phone_number,
337-
client_id=client_id,
338-
user_type=user_type,
339-
)
340-
341285
@provide_global_contextual_session
342286
def exist_by_email_and_client_id(
343287
self,
@@ -392,17 +336,6 @@ def get_user_count_by_client_id_and_user_type(self, session, client_id, user_typ
392336

393337
return session.execute(query).scalar()
394338

395-
@provide_global_contextual_session
396-
def get_by_client_id_and_global_auth_user(self, session, client_id, global_auth_user_id):
397-
return self._repository.get_by(
398-
session=session,
399-
filters=[
400-
auth_user_model.client_id == client_id,
401-
auth_user_model.user_type == EntityType.CONNECT.value,
402-
auth_user_model.global_auth_user_id == global_auth_user_id,
403-
],
404-
)
405-
406339
@provide_global_contextual_session
407340
def get_by_client_id_and_user_type(
408341
self,
@@ -420,61 +353,6 @@ def get_by_client_id_and_user_type(
420353
limit=limit,
421354
)
422355

423-
@provide_global_contextual_session
424-
def get_by_client_ids_and_user_type(
425-
self,
426-
session,
427-
client_ids,
428-
user_type,
429-
offset=None,
430-
limit=None,
431-
):
432-
if not client_ids:
433-
return []
434-
435-
return self._repository.get_by(
436-
session,
437-
filters=[
438-
auth_user_model.client_id.in_(client_ids),
439-
auth_user_model.user_type == user_type,
440-
auth_user_model.date_verified != None,
441-
],
442-
offset=offset,
443-
limit=limit,
444-
order_by_clause=auth_user_model.id.desc(),
445-
)
446-
447-
@provide_global_contextual_session
448-
def get_by_client_id_with_substring_search(
449-
self,
450-
session,
451-
client_id,
452-
substring,
453-
offset=None,
454-
limit=10,
455-
join_list=None,
456-
):
457-
return self._repository.get_by(
458-
session,
459-
filters=[
460-
auth_user_model.client_id == client_id,
461-
auth_user_model.user_type == EntityType.MAGIC.value,
462-
sa.or_(
463-
auth_user_model.provenance == Provenance.SMS,
464-
auth_user_model.provenance == Provenance.LINK,
465-
auth_user_model.provenance == None, # noqa: E711
466-
),
467-
sa.or_(
468-
auth_user_model.phone_number.contains(substring),
469-
auth_user_model.email.contains(substring),
470-
),
471-
],
472-
offset=offset,
473-
limit=limit,
474-
order_by_clause=auth_user_model.id.desc(),
475-
join_list=join_list,
476-
)
477-
478356
@provide_global_contextual_session
479357
def yield_by_chunk(self, session, chunk_size, filters=None, join_list=None):
480358
yield from self._repository.yield_by_chunk(
@@ -518,72 +396,6 @@ def get_by_email(
518396
join_list=join_list,
519397
)
520398

521-
@provide_global_contextual_session
522-
def get_by_email_for_interop(
523-
self,
524-
session,
525-
email: str,
526-
wallet_type: WalletType,
527-
network: str,
528-
) -> t.List[auth_user_model]:
529-
"""
530-
Custom method for searching for users eligible for interop. Unfortunately, this can't be done with the current
531-
abstractions in our sql_repository, so this is a one-off bespoke method.
532-
If we need to add more similar queries involving eager loading and multiple joins, we can add an abstraction
533-
inside the repository.
534-
"""
535-
536-
query = (
537-
session.query(auth_user_model)
538-
.join(
539-
auth_user_model.wallets.and_(
540-
auth_wallet_model.wallet_type == str(wallet_type)
541-
).and_(auth_wallet_model.network == network)
542-
)
543-
.options(sa.orm.contains_eager(auth_user_model.wallets))
544-
.join(
545-
auth_user_model.magic_client.and_(
546-
magic_client_model.connect_interop == ConnectInteropStatus.ENABLED,
547-
),
548-
)
549-
.options(sa.orm.contains_eager(auth_user_model.magic_client))
550-
.filter(
551-
auth_wallet_model.wallet_type == wallet_type,
552-
auth_wallet_model.network == network,
553-
)
554-
.filter(
555-
auth_user_model.email == email,
556-
auth_user_model.user_type == EntityType.MAGIC.value,
557-
)
558-
.populate_existing()
559-
)
560-
561-
return query.all()
562-
563-
@provide_global_contextual_session
564-
def get_linked_users(self, session, primary_auth_user_id, join_list, no_op=False):
565-
# TODO(magic-ravi#67899|2022-12-30): Re-enable account linked users for interop. Remove no_op flag.
566-
if no_op:
567-
return []
568-
else:
569-
return self._repository.get_by(
570-
session,
571-
filters=[
572-
auth_user_model.user_type == EntityType.MAGIC.value,
573-
auth_user_model.linked_primary_auth_user_id == primary_auth_user_id,
574-
],
575-
join_list=join_list,
576-
)
577-
578-
@provide_global_contextual_session
579-
def get_by_phone_number(self, session, phone_number):
580-
return self._repository.get_by(
581-
session,
582-
filters=[
583-
auth_user_model.phone_number == phone_number,
584-
],
585-
)
586-
587399

588400
class AuthWallet(LogicComponent[auth_wallet_model, ObjectID, sa.orm.Session]):
589401
model = auth_wallet_model

0 commit comments

Comments
 (0)