feat: account share

This commit is contained in:
jfmcarreira committed 2026-10-06 18:17:18 +01:00
1 parent 3f78dbb490
commit f4dade9eec
25 files changed
+1185 -331

No files matched your search

+43 -18
View File
@@ -17,7 +17,15 @@ from .database import (
stamp,
)
from . import models
from .models import Assignment, MonthlyPattern, NotificationLog, RotationMember, Schedule, User
from .models import (
Assignment,
LoginAccount,
MonthlyPattern,
NotificationLog,
RotationMember,
Schedule,
User,
)
from .i18n import day_long, day_numeric
from .notifications import send_email_notification
from .scheduling import ensure_month_assignments
@@ -43,29 +51,45 @@ def init_db() -> None:
def seed_demo() -> None:
init_db()
# The last two share one login, the way a team would in real life.
demo_people = [
("Alice", "alice", "alice@example.com"),
("Bruno", "bruno", "bruno@example.com"),
("Carla", "carla", None),
("Diogo", "diogo", "diogo@example.com"),
("Carla", "sabado", None),
("Diogo", "sabado", "diogo@example.com"),
]
with SessionLocal() as db:
for name, username, email in demo_people:
if not db.scalar(select(User.id).where(User.username == username)):
db.add(
User(
name=name,
username=username,
email=email,
phone=None,
password_hash=hash_password("demo-password"),
is_active=True,
is_admin=False,
notify_email=True,
)
if db.scalar(select(User.id).where(User.name == name)):
continue # this person is already there, whoever they sign in with
account = db.scalar(select(LoginAccount).where(LoginAccount.username == username))
if account is None:
account = LoginAccount(
name=name,
username=username,
password_hash=hash_password("demo-password"),
is_admin=False,
is_active=True,
)
db.add(account)
db.flush()
db.add(
User(
name=name,
login=account,
email=email,
phone=None,
is_active=True,
notify_email=True,
)
)
db.commit()
people = db.scalars(select(User).where(User.username.in_([x[1] for x in demo_people])).order_by(User.name)).all()
people = db.scalars(
select(User)
.join(LoginAccount)
.where(LoginAccount.username.in_([x[1] for x in demo_people]))
.order_by(User.name)
).all()
schedules = db.scalars(
select(Schedule).where(Schedule.slug.in_(["saturday-lunch", "sunday-lunch"])).order_by(Schedule.id)
).all()
@@ -91,7 +115,8 @@ def seed_demo() -> None:
for month in (today, next_month):
ensure_month_assignments(db, month.year, month.month)
print("Demo data seeded for this month and next. Existing assignments and configuration preserved.")
print("Demo logins: alice, bruno, carla, diogo. Password: demo-password (new accounts only).")
print("Demo logins: alice, bruno, sabado (Carla e Diogo entram com a mesma conta). "
"Password: demo-password (new accounts only).")
def db_shell() -> None:
@@ -100,7 +125,7 @@ def db_shell() -> None:
with SessionLocal() as db:
namespace = {"db": db, "select": select, "models": models}
namespace.update({name: getattr(models, name) for name in (
"User", "Schedule", "MonthlyPattern", "RotationMember", "Assignment", "SwapRequest", "NotificationLog"
"User", "LoginAccount", "Schedule", "MonthlyPattern", "RotationMember", "Assignment", "SwapRequest", "NotificationLog"
)})
code.interact(
banner="Database console: db, select, models and model classes are available.\n"