mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
housekeep(fastapi): rework aurweb.db session API
Changes: ------- - Add aurweb.db.get_session() - Returns aurweb.db's global `session` instance - Provides us a way to change the implementation of the session instance without interrupting user code. - Use aurweb.db.get_session() in session API methods - Add docstrings to session API methods - Refactor aurweb.db.delete - Normalize aurweb.db.delete to an alias of session.delete - Refresh instances in places we depend on their non-PK columns being up to date. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
f8ba2c5342
commit
4103ab49c9
22 changed files with 212 additions and 138 deletions
|
@ -1,6 +1,6 @@
|
|||
from fastapi import Request
|
||||
|
||||
from aurweb import schema
|
||||
from aurweb import db, schema
|
||||
from aurweb.models.declarative import Base
|
||||
|
||||
|
||||
|
@ -10,11 +10,10 @@ class Ban(Base):
|
|||
__mapper_args__ = {"primary_key": [__table__.c.IPAddress]}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.IPAddress = kwargs.get("IPAddress")
|
||||
self.BanTS = kwargs.get("BanTS")
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
def is_banned(request: Request):
|
||||
from aurweb.db import session
|
||||
ip = request.client.host
|
||||
return session.query(Ban).filter(Ban.IPAddress == ip).first() is not None
|
||||
exists = db.query(Ban).filter(Ban.IPAddress == ip).exists()
|
||||
return db.query(exists).scalar()
|
||||
|
|
|
@ -146,7 +146,7 @@ class User(Base):
|
|||
self.authenticated = False
|
||||
if self.session:
|
||||
with db.begin():
|
||||
db.session.delete(self.session)
|
||||
db.delete(self.session)
|
||||
|
||||
def is_trusted_user(self):
|
||||
return self.AccountType.ID in {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue