mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 15:54:45 +01:00
fix(users): unlink RetroAchievements when ra_username is sent empty (#5475)
This commit is contained in:
1 parent
260abdfd8f
commit
4b01bebfb8
5 files changed
+141
-29
No files matched your search
@@ -1,4 +1,4 @@
|
||||
from collections.abc import Sequence
|
||||
from collections.abc import Mapping, Sequence
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any
|
||||
|
||||
@@ -10,7 +10,7 @@ from decorators.database import INJECTED_SESSION, begin_session
|
||||
from exceptions.database_exceptions import LastAdminError
|
||||
from models.user import Role, User
|
||||
|
||||
from .base_handler import DBBaseHandler
|
||||
from .base_handler import DBBaseHandler, affected_rows
|
||||
|
||||
LAST_ACTIVE_DEBOUNCE = timedelta(minutes=5)
|
||||
|
||||
@@ -126,6 +126,27 @@ class DBUsersHandler(DBBaseHandler):
|
||||
)
|
||||
return session.scalars(select(User).filter_by(id=id)).one()
|
||||
|
||||
@begin_session
|
||||
def set_ra_progression(
|
||||
self,
|
||||
id: int,
|
||||
ra_username: str,
|
||||
progression: Mapping[str, object],
|
||||
session: Session = INJECTED_SESSION,
|
||||
) -> bool:
|
||||
"""Store progression fetched for `ra_username` if the user still links that profile.
|
||||
|
||||
Returns:
|
||||
Whether the progression was stored.
|
||||
"""
|
||||
result = session.execute(
|
||||
update(User)
|
||||
.where(User.id == id, User.ra_username == ra_username)
|
||||
.values(ra_progression=progression)
|
||||
.execution_options(synchronize_session=False)
|
||||
)
|
||||
return affected_rows(result) > 0
|
||||
|
||||
@begin_session
|
||||
def update_last_active(
|
||||
self,
|
||||
|
||||
Reference in new issue
Block a user