Fix: Login deleting old clients was conflicting with login history
Chore: Moved to angular linting using the recommended plugins / settings
This commit is contained in:
@ -12,7 +12,7 @@ from fastapi import (
|
||||
)
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from sqlalchemy import and_
|
||||
from sqlalchemy import and_, or_
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from .. import __version__
|
||||
@ -61,7 +61,21 @@ async def login_for_access_token(
|
||||
if allowed:
|
||||
history = LoginHistory(user.id, client.id)
|
||||
db.add(history)
|
||||
db.execute(LoginHistory.__table__.delete(LoginHistory.date < datetime.utcnow() - timedelta(days=30)))
|
||||
db.execute(
|
||||
LoginHistory.__table__.delete(
|
||||
or_(
|
||||
LoginHistory.date < datetime.utcnow() - timedelta(days=30),
|
||||
LoginHistory.client_id.in_(
|
||||
db.query(Client.id)
|
||||
.filter(
|
||||
Client.creation_date < datetime.utcnow() - timedelta(days=3),
|
||||
Client.enabled == False, # noqa: E712
|
||||
)
|
||||
.subquery()
|
||||
),
|
||||
)
|
||||
)
|
||||
)
|
||||
db.execute(
|
||||
Client.__table__.delete(
|
||||
and_(Client.creation_date < datetime.utcnow() - timedelta(days=3), Client.enabled == False) # noqa: E712
|
||||
|
||||
Reference in New Issue
Block a user