feat(settings): add SMTP admin configuration
This commit is contained in:
parent
c58e212e3a
commit
884a20e043
32 changed files with 1200 additions and 42 deletions
|
|
@ -343,6 +343,17 @@ class RepairRepository:
|
|||
.where(RepairNotificationEvent.status.in_(["failed", "skipped"]))
|
||||
) or 0
|
||||
|
||||
@staticmethod
|
||||
def latest_failed_status_mail(db: Session) -> RepairNotificationEvent | None:
|
||||
return db.scalar(
|
||||
select(RepairNotificationEvent)
|
||||
.where(RepairNotificationEvent.event_type == "repair_status_mail")
|
||||
.where(RepairNotificationEvent.success.is_(False))
|
||||
.where(RepairNotificationEvent.status.in_(["failed", "skipped"]))
|
||||
.order_by(RepairNotificationEvent.created_at.desc(), RepairNotificationEvent.id.desc())
|
||||
.limit(1)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def count_open_repairs_without_customer_email(db: Session) -> int:
|
||||
return db.scalar(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,35 @@
|
|||
from collections.abc import Iterable
|
||||
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.models.system_setting import SystemSetting
|
||||
|
||||
|
||||
class SystemSettingsRepository:
|
||||
@staticmethod
|
||||
def get(db: Session, key: str) -> SystemSetting | None:
|
||||
return db.scalar(select(SystemSetting).where(SystemSetting.key == key))
|
||||
|
||||
@staticmethod
|
||||
def get_many(db: Session, keys: Iterable[str]) -> dict[str, SystemSetting]:
|
||||
key_list = list(keys)
|
||||
if not key_list:
|
||||
return {}
|
||||
|
||||
settings = db.scalars(select(SystemSetting).where(SystemSetting.key.in_(key_list))).all()
|
||||
return {setting.key: setting for setting in settings}
|
||||
|
||||
@staticmethod
|
||||
def upsert(db: Session, *, key: str, value: str, is_secret: bool = False) -> SystemSetting:
|
||||
setting = SystemSettingsRepository.get(db, key)
|
||||
if setting is None:
|
||||
setting = SystemSetting(key=key, value=value, is_secret=is_secret)
|
||||
db.add(setting)
|
||||
db.flush()
|
||||
return setting
|
||||
|
||||
setting.value = value
|
||||
setting.is_secret = is_secret
|
||||
db.flush()
|
||||
return setting
|
||||
Loading…
Add table
Add a link
Reference in a new issue