Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix: allow learner task board through chat surface

Bingxi Zhao (Frank)7dd1f7f04657
diff --git a/deeptutor/api/routers/auth.py b/deeptutor/api/routers/auth.py
index ea923a19c..50c38fa5b 100644
--- a/deeptutor/api/routers/auth.py
+++ b/deeptutor/api/routers/auth.py
@@ -617,6 +617,8 @@ def _learning_surface_for_path(
("/api/question", "chat"),
("/api/question-notebook", "chat"),
("/api/sessions", "chat"),
+ # Task cards are private to the learner's current content workspace.
+ ("/api/task-board", "chat"),
# Mastery Path progress/topics are the learner's own per-user data;
# the router already scopes every record to the current account, so
# all methods (including progress PATCH/POST) belong to "chat".
diff --git a/tests/multi_user/test_learning_surface_map.py b/tests/multi_user/test_learning_surface_map.py
index d85a854bb..f1bdb0233 100644
--- a/tests/multi_user/test_learning_surface_map.py
+++ b/tests/multi_user/test_learning_surface_map.py
@@ -29,6 +29,10 @@ from deeptutor.api.routers.auth import _learning_surface_for_path
("/api/chat/sessions", "GET", "chat"),
("/api/question/generate", "POST", "chat"),
("/api/sessions/abc", "GET", "chat"),
+ ("/api/task-board", "GET", "chat"),
+ ("/api/task-board/cards", "POST", "chat"),
+ ("/api/task-board/cards/card-1", "PATCH", "chat"),
+ ("/api/task-board-private", "GET", ""),
# Mastery Path: the learner's own per-user progress, all methods.
("/api/mastery-paths/topics", "GET", "chat"),
("/api/mastery-paths/topics/index", "GET", "chat"),
diff --git a/tests/multi_user/test_task_board.py b/tests/multi_user/test_task_board.py
index be827e779..5a2a07682 100644
--- a/tests/multi_user/test_task_board.py
+++ b/tests/multi_user/test_task_board.py
@@ -58,6 +58,46 @@ def test_authentication_is_required_for_reads_and_writes(client):
).status_code == 401
+def test_learning_policy_allows_board_reads_and_writes_only_with_chat_surface(client, monkeypatch):
+ from deeptutor.multi_user.grants import learner_grant, save_grant
+ from deeptutor.multi_user.identity import save_user
+
+ save_user("admin", "placeholder", role="admin")
+ learner = save_user("alice", "placeholder", preset="learner")
+ monkeypatch.setattr(
+ auth,
+ "decode_token",
+ lambda token: (
+ TokenPayload(username="alice", role="user", user_id=learner["id"])
+ if token == "alice"
+ else None
+ ),
+ )
+
+ grant = learner_grant(learner["id"])
+ save_grant(learner["id"], grant)
+
+ assert client.get("/api/task-board", headers=headers()).status_code == 200
+ created = client.post("/api/task-board/cards", json={"title": "Practice"}, headers=headers())
+ assert created.status_code == 201
+ card_id = created.json()["cards"][0]["id"]
+ updated = client.patch(
+ f"/api/task-board/cards/{card_id}", json={"status": "doing"}, headers=headers()
+ )
+ assert updated.status_code == 200
+ assert updated.json()["cards"][0]["status"] == "doing"
+
+ grant["learning_policy"]["allowed_surfaces"] = ["reading"]
+ save_grant(learner["id"], grant)
+ assert client.get("/api/task-board", headers=headers()).status_code == 403
+ assert (
+ client.post("/api/task-board/cards", json={"title": "Hidden"}, headers=headers())
+ ).status_code == 403
+ assert (
+ client.patch(f"/api/task-board/cards/{card_id}", json={"status": "done"}, headers=headers())
+ ).status_code == 403
+
+
def test_create_edit_move_archive_restore_and_reload(client):
assert client.get("/api/task-board", headers=headers()).json() == {"cards": []}
response = client.post(