feat: change front page

This commit is contained in:
jfmcarreira committed 2026-10-06 09:54:05 +01:00
1 parent ec3e9e46fe
commit 03ab98dd49
11 files changed
+110 -26

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
APP_NAME=CRR Bar Rota
APP_NAME=Contínuos CRR
SECRET_KEY=replace-with-a-long-random-value
DATABASE_URL=sqlite:///./data/bar_rota.db
BASE_URL=http://localhost:8000
+1 -1
View File
@@ -81,4 +81,4 @@ For route/UI changes also start the app and verify `/health`, `/login`, the rota
- CRR brand red is `#ED1C24` and is exposed as `--brand` in `app/static/app.css`.
- For controls with white text, use the darker accessible red `--brand-deep` (`#C81018`), not the exact brand red. The exact brand red is used for borders, focus states, highlights, and other identity accents.
- Keep branding usable on mobile and preserve visible keyboard focus states.
- Default application name is `CRR Bar Rota`; deployments can still override it with `APP_NAME`.
- Default application name is `Contínuos CRR`; deployments can still override it with `APP_NAME`.
+1 -1
View File
@@ -1,4 +1,4 @@
# CRR Bar Rota
# Contínuos CRR
Small self-hosted rota application for a non-profit bar/club.
+4 -2
View File
@@ -4,7 +4,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
app_name: str = "CRR Bar Rota"
app_name: str = "Contínuos CRR"
secret_key: str = "dev-only-change-me"
database_url: str = "sqlite:///./data/bar_rota.db"
base_url: str = "http://localhost:8000"
@@ -23,7 +23,9 @@ class Settings(BaseSettings):
reminder_days_ahead: int = 1
session_https_only: bool = False
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
model_config = SettingsConfigDict(
env_file=".env", env_file_encoding="utf-8", extra="ignore"
)
@property
def normalized_base_url(self) -> str:
+1 -1
View File
@@ -57,7 +57,7 @@
<h3>Next dates</h3>
<p class="date-list">{{ card.dates | join(' · ') }}</p>
</section>
<section class="panel">
<section class="panel" id="rotation-order">
<h3>Rotation order</h3>
<p class="muted">Independent rotation, filled in order. After changing the order, use Apply rotation above to update this month's automatic shifts.</p>
<ol class="rotation-list">
+3 -4
View File
@@ -11,15 +11,14 @@
<body>
<header class="topbar">
<div class="container topbar-inner">
<a class="brand" href="{% if current_user %}/{% else %}/schedules{% endif %}" aria-label="{{ settings.app_name }} home">
<a class="brand" href="/" aria-label="{{ settings.app_name }} home">
<img class="brand-logo" src="{{ url_for('static', path='logo-crr.png') }}" alt="CRR">
<span class="brand-name">{{ settings.app_name }}</span>
</a>
<nav class="nav" aria-label="Primary navigation">
<a href="/schedules">Schedules</a>
<a href="/schedules">Schedules</a>
{% if current_user %}
<a href="/">Rota</a>
<a href="/swaps">Changes</a>
<a href="/swaps">Changes</a>
{% if current_user.is_admin %}
<a href="/admin/schedules">Manage schedules</a>
<a href="/admin/users">People</a>
+1
View File
@@ -2,6 +2,7 @@
{% block content %}
<div class="page-head">
<div>
<p class="eyebrow">Rota</p>
<h1>{{ month_name }} {{ year }}</h1>
<p class="muted">Night duty every day, plus separate Saturday and Sunday lunch rotas.</p>
</div>
+16 -12
View File
@@ -259,21 +259,25 @@ def dashboard(
month: int | None = None,
db: Session = Depends(get_db),
):
user = _require_user(request, db)
user = _current_user(request, db)
if user and not user.is_active:
user = None
year, month = _parse_month(year, month)
assignments = ensure_month_assignments(db, year, month)
grouped = assignments_by_date(assignments)
prev, nxt = _month_nav(year, month)
my_assignment_ids = {a.id for a in assignments if a.user_id == user.id}
open_swap_assignment_ids = set(
db.scalars(
select(SwapRequest.assignment_id).where(
SwapRequest.requester_id == user.id,
SwapRequest.status.in_(["open", "pending_approval"]),
)
).all()
)
my_assignment_ids = {a.id for a in assignments if user and a.user_id == user.id}
open_swap_assignment_ids = set()
if user:
open_swap_assignment_ids = set(
db.scalars(
select(SwapRequest.assignment_id).where(
SwapRequest.requester_id == user.id,
SwapRequest.status.in_(["open", "pending_approval"]),
)
).all()
)
return request.app.state.templates.TemplateResponse(
request=request,
@@ -869,14 +873,14 @@ def admin_rotation_add(
)
if exists:
_flash(request, "That person is already in this rotation.", "error")
return _redirect(f"/admin/schedules/{schedule.id}")
return _redirect(f"/admin/schedules/{schedule.id}#rotation-order")
max_position = db.scalar(
select(func.max(RotationMember.position)).where(RotationMember.schedule_id == schedule.id)
) or 0
db.add(RotationMember(schedule_id=schedule.id, user_id=user.id, position=max_position + 1))
db.commit()
_flash(request, "Rotation member added.")
return _redirect(f"/admin/schedules/{schedule.id}")
return _redirect(f"/admin/schedules/{schedule.id}#rotation-order")
@router.post("/admin/rotation/{member_id}/remove")
+5
View File
@@ -56,6 +56,11 @@ Every assignment on a lunch schedule page has a **Regenerate** button. An admini
- Rota-only people can be assigned by an administrator, appear in rotations, and can be named as the target of a change request, but cannot accept it; an administrator completes the transfer on the schedule's own configuration page.
- A person cannot remove their own login.
## Access
- `/` is the rota and is the landing page for everyone, signed in or not. Signed-out visitors see the month read-only: no "mine" highlighting, no change-request actions.
- Change requests, `/swaps`, and every `/admin` page still require a signed-in, active account.
## Change request state machine
`open` → `pending_approval` → `approved`
+65 -3
View File
@@ -3,7 +3,7 @@ from datetime import date, timedelta
import pytest
from fastapi.testclient import TestClient
from sqlalchemy import create_engine
from sqlalchemy import create_engine, select
from sqlalchemy.orm import sessionmaker
from sqlalchemy.pool import StaticPool
@@ -108,6 +108,35 @@ def test_public_schedules_page_is_open_to_anonymous_visitors(client, db):
assert "Sunday Lunch" in response.text
def test_rota_is_the_landing_page_for_signed_out_visitors(client, db):
seed_schedules(db)
page = client.get("/", follow_redirects=False).text
assert ">Rota</p>" in page
assert '<a class="brand" href="/"' in page
assert "Saturday Lunch" in page
assert "Sign in" in page
assert "Request change" not in page
assert "/swap" not in page
assert 'class="assignment mine"' not in page
def test_signed_in_rota_shows_change_actions_for_own_shifts(client, db):
_, sat, _ = seed_schedules(db)
ana = db.scalar(select(User).where(User.name == "Ana"))
ana.username = "ana"
ana.password_hash = hash_password("a-secure-password")
db.commit()
login(client, "ana", "a-secure-password")
page = client.get("/", follow_redirects=False).text
assert "Request change" in page
assert "/swap" in page
assert f"{sat.id}" in page
def test_public_schedules_show_details_and_rotation_order(client, db):
night, sat, _ = seed_schedules(db)
@@ -212,10 +241,15 @@ def test_signed_in_member_can_also_read_public_schedules(client, db):
assert "Saturday Lunch" in client.get("/schedules").text
def test_rota_stays_private(client, db):
def test_rota_is_read_only_for_signed_out_visitors(client, db):
seed_schedules(db)
assert client.get("/", follow_redirects=False).status_code == 401
page = client.get("/", follow_redirects=False).text
assert "Rota" in page
assert "Request change" not in page
assert "/swap" not in page
assert client.get("/swaps", follow_redirects=False).status_code == 401
def test_admin_schedules_page_separates_the_three_schedule_types(client, db):
@@ -264,3 +298,31 @@ def test_rotation_edits_return_to_the_schedule_page(client, db):
)
assert response.headers["location"] == f"/admin/schedules/{sat.id}"
def test_adding_a_rotation_member_returns_to_the_rotation_order_anchor(client, db):
_, sat, _ = seed_schedules(db)
admin = User(
name="Admin",
username="admin",
password_hash=hash_password("admin-password"),
is_active=True,
is_admin=True,
)
db.add(admin)
newcomer = add_person(db, "Carla")
db.commit()
login(client, "admin", "admin-password")
page = client.get(f"/admin/schedules/{sat.id}").text
assert 'id="rotation-order"' in page
token = CSRF_RE.search(page).group(1)
response = client.post(
f"/admin/schedules/{sat.id}/rotation",
data={"csrf_token": token, "user_id": newcomer.id},
follow_redirects=False,
)
assert response.headers["location"] == f"/admin/schedules/{sat.id}#rotation-order"
db.refresh(sat)
assert newcomer.id in {member.user_id for member in sat.rotation_members}
+12 -1
View File
@@ -112,7 +112,7 @@ def test_person_without_credentials_cannot_sign_in(client, db, admin):
db.commit()
assert "Invalid username or password" in login(client, " ", "a-secure-password")
assert client.get("/", follow_redirects=False).status_code == 401
assert client.get("/swaps", follow_redirects=False).status_code == 401
def test_username_without_password_cannot_sign_in(client, db, admin):
@@ -165,3 +165,14 @@ def test_admin_cannot_remove_their_own_login(client, db, admin):
page = update_person(client, admin.id, name="Admin", new_password="another-password")
assert "Add a username before setting a password for your own account." in page
assert db.get(User, admin.id).can_login is True
def test_signed_in_home_is_the_rota_and_nav_has_no_rota_link(client, db, admin):
landing = login(client, "admin", "admin-password")
assert ">Rota</p>" in landing
nav = client.get("/admin/users").text
assert '<a href="/">Rota</a>' not in nav
assert '<a href="/schedules">Schedules</a>' in nav
assert '<a href="/swaps">Changes</a>' in nav
assert 'href="/"' in nav # the brand stays the home link for signed-in members