5 Commits
Author SHA1 Message Date
ahtlon ee91b03198 last_used in register_card
Check flake syntax / flake-check (push) Successful in 33s
Test python action / test (push) Successful in 41s
2026-11-09 15:35:56 +01:00
ahtlon 2a44e3a1a6 Add card last_used entry 2026-11-09 15:35:13 +01:00
ahtlon f0bd1e68e8 add calendar manager endpoint 2026-11-09 13:19:24 +01:00
ahtlon 8ca4da2e1a Add flake check
Test python action / test (push) Successful in 38s
Check flake syntax / flake-check (push) Successful in 2m15s
2026-11-06 09:05:08 +01:00
ahtlon d93491f466 Merge pull request 'Add Caldav support for access checks' (#30) from caldav into master
Test python action / test (push) Successful in 37s
Reviewed-on: #30
2026-11-05 22:52:56 +01:00
8 changed files with 90 additions and 29 deletions
+14
View File
@@ -0,0 +1,14 @@
name: "Check flake syntax"
on:
push:
jobs:
flake-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install dependencies for Nix setup action
run: |
apt update -y
apt install sudo -y
- uses: cachix/install-nix-action@v30
- run: nix flake check --no-update-lock-file --accept-flake-config .
+44
View File
@@ -0,0 +1,44 @@
import logging
from fastapi import APIRouter, Depends, HTTPException
from app.services.auth import auth_is_admin
from app.services.caldav import get_caldav_handler
from app.model.models import Card
from sqlmodel import Session, select
logger= logging.getLogger(__name__)
calendar_router = APIRouter(
prefix="/api/v1/calendar",
tags=["Calendar diagnostics"],
dependencies=[Depends(auth_is_admin)]
)
@calendar_router.get("/isActive")
def cal_is_active():
if get_caldav_handler() is None:
return False
else:
return True
@calendar_router.get("/calGetActiveEvents")
def cal_get_active_events(db: Session = Depends(get_session)):
handler = get_caldav_handler()
if handler is None:
raise HTTPException(503, "Caldav handler not initialized")
return handler.get_active_events()
@calendar_router.get("/calGetFutureEvents")
def cal_get_future_events(db: Session = Depends(get_session)):
handler = get_caldav_handler()
if handler is None:
raise HTTPException(503, "Caldav handler not initialized")
return handler.get_future_events()
@calendar_router.get("/calGetActiveGroups")
def cal_get_active_groups(db: Session = Depends(get_session)):
handler = get_caldav_handler()
if handler is None:
raise HTTPException(503, "Caldav handler not initialized")
return handler.get_active_groups()
+10
View File
@@ -3,6 +3,7 @@ import logging
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.exc import NoResultFound
from sqlmodel import Session, select
from datetime import datetime, UTC
from app.model.models import Card, CardCreate, CardUpdate, GroupDB
from app.services.auth import auth_is_admin
@@ -27,6 +28,7 @@ def register_card(cardInput: CardCreate):
name=cardInput.name,
card_serial=uid,
enabled=cardInput.enabled,
last_used=datetime.now(tz=UTC)
)
return card
@@ -116,3 +118,11 @@ def update_card(
) from err
db_card.sqlmodel_update(card_data)
return add_and_refresh(db, db_card)
@card_router.get("/inactive")
def inactive_card_search(enabled: bool = False, uses: bool = False, ended: bool = False, db: Session = Depends(get_session), admin: bool = Depends(auth_is_admin)):
results = []
if not enabled and not uses and not ended:
return {"message": "No results. Please activate at least one filter rule"}
if enabled:
return {"message": "Results with disabled cards heres"}
+1 -25
View File
@@ -63,28 +63,4 @@ def list_all_cards(db: Session = Depends(get_session)):
out = []
for i in cards:
out.append({i.key: i.group.name})
return out
@debug_router.get("/calGetActiveEvents")
def cal_get_active_events(db: Session = Depends(get_session)):
handler = get_caldav_handler()
if handler is None:
raise HTTPException(503, "Caldav handler not initialized")
return handler.get_active_events()
@debug_router.get("/calGetFutureEvents")
def cal_get_future_events(db: Session = Depends(get_session)):
handler = get_caldav_handler()
if handler is None:
raise HTTPException(503, "Caldav handler not initialized")
return handler.get_future_events()
@debug_router.get("/calGetActiveGroups")
def cal_get_active_groups(db: Session = Depends(get_session)):
handler = get_caldav_handler()
if handler is None:
raise HTTPException(503, "Caldav handler not initialized")
return handler.get_active_groups()
return out
+1
View File
@@ -170,6 +170,7 @@ class Card(Base, table=True):
name: str = Field(unique=True, max_length=32)
group_id: int | None = Field(default=None, foreign_key="groupdb.id")
group: GroupDB | None = Relationship(back_populates="cards")
last_used: datetime = Field(sa_type=UTCDateTime)
class CardCreate(Base):
+14 -4
View File
@@ -1,5 +1,5 @@
import logging
from datetime import datetime
from datetime import datetime, UTC
from sqlalchemy import exc
from sqlmodel import select
@@ -98,10 +98,16 @@ def decrementOneshot(db: Session, oneshot: OneShotAccess):
oneshot.sqlmodel_update(oneshot, update=data)
add_and_refresh(db, oneshot)
def updateLastUsed(db: Session, card: Card):
data = card.model_dump()
data["lastUsed"] = datetime.now(UTC)
card.sqlmodel_update(card, update=data)
add_and_refresh(db, card)
def checkAccess(key: str, db: Session):
try:
card = db.exec(select(Card).where(Card.key == key)).one()
updateLastUsed(db, card)
if not card.enabled:
logger.info("Card Inactive!")
return False
@@ -122,9 +128,13 @@ def checkAccess(key: str, db: Session):
ends_at = auth.oneshot.ends_at
if ends_at.tzinfo is None:
ends_at = ends_at.astimezone()
if current_time < ends_at and auth.oneshot.uses > 0:
decrementOneshot(db, auth.oneshot)
return True
if current_time < ends_at:
if auth.oneshot.uses > 0:
decrementOneshot(db, auth.oneshot)
return True
elif auth.oneshot.uses == -1:
logger.debug("Unlimited use card found")
return True
logger.info("No more auths found")
return False
except exc.NoResultFound as err:
+1
View File
@@ -217,6 +217,7 @@ def test_card(db_session, test_group):
enabled=True,
name="test_card",
card_serial="00:00:00:00:00:00:00",
last_used=datetime.now()
)
db_session.add(card)
db_session.commit()
+5
View File
@@ -23,6 +23,7 @@ def test_check_access_with_valid_oneshot(db_session):
enabled=True,
name="test_card",
card_serial="00:00:00:00:00:00:00",
last_used=datetime.datetime.now()
)
db_session.add(card)
@@ -61,6 +62,7 @@ def test_check_access_with_inactive_aa(db_session):
enabled=True,
name="test_card",
card_serial="00:00:00:00:00:00:00",
last_used=datetime.datetime.now()
)
db_session.add(card)
@@ -90,6 +92,7 @@ def test_check_access_with_inactive_card(db_session):
enabled=False,
name="test_card",
card_serial="00:00:00:00:00:00:00",
last_used=datetime.datetime.now()
)
db_session.add(card)
@@ -119,6 +122,7 @@ def test_regression_check_access_issue_28(db_session):
enabled=True,
name="test_card",
card_serial="00:00:00:00:00:00:00",
last_used=datetime.datetime.now()
)
db_session.add(card)
@@ -163,6 +167,7 @@ def _create_card_with_oneshot(db_session, ends_at):
enabled=True,
name="test_card",
card_serial="00:00:00:00:00:00:00",
last_used=datetime.datetime.now()
)
db_session.add(card)