From e97dc6cb04f844cbad09e2a9139cdc4623a543ca Mon Sep 17 00:00:00 2001 From: Sara Burns Date: Thu, 26 Mar 2026 12:50:13 -0400 Subject: [PATCH 1/4] fix: Fix thread api call to work with teams --- forum/api/threads.py | 1 + forum/backends/mysql/api.py | 1 + 2 files changed, 2 insertions(+) diff --git a/forum/api/threads.py b/forum/api/threads.py index b5b036c5..fb692b12 100644 --- a/forum/api/threads.py +++ b/forum/api/threads.py @@ -385,6 +385,7 @@ def get_user_threads( "user_id": user_id, "group_id": group_id, "group_ids": group_ids, + "context": kwargs.get('context', None) } params = {k: v for k, v in params.items() if v is not None} backend.validate_params(params) diff --git a/forum/backends/mysql/api.py b/forum/backends/mysql/api.py index b115119b..0e00ebc7 100644 --- a/forum/backends/mysql/api.py +++ b/forum/backends/mysql/api.py @@ -1158,6 +1158,7 @@ def get_threads( params.get("sort_key", ""), int(params.get("page", 1)), int(params.get("per_page", 100)), + context=params.get('context', 'course'), commentable_ids=params.get("commentable_ids", []), is_moderator=params.get("is_moderator", False), ) From 63a9ade13dd3305321de8d0722a5a7b2c2f85162 Mon Sep 17 00:00:00 2001 From: Sara Burns Date: Thu, 26 Mar 2026 13:15:02 -0400 Subject: [PATCH 2/4] fix: formatting --- forum/api/threads.py | 2 +- forum/backends/mysql/api.py | 2 +- forum/migration_helpers.py | 1 - setup.py | 1 + tests/test_backends/test_mongodb/test_comments.py | 1 + tests/test_management/test_commands/test_migration_commands.py | 1 - 6 files changed, 4 insertions(+), 4 deletions(-) diff --git a/forum/api/threads.py b/forum/api/threads.py index fb692b12..a8873cc1 100644 --- a/forum/api/threads.py +++ b/forum/api/threads.py @@ -385,7 +385,7 @@ def get_user_threads( "user_id": user_id, "group_id": group_id, "group_ids": group_ids, - "context": kwargs.get('context', None) + "context": kwargs.get("context", None), } params = {k: v for k, v in params.items() if v is not None} backend.validate_params(params) diff --git a/forum/backends/mysql/api.py b/forum/backends/mysql/api.py index 0e00ebc7..fea6340e 100644 --- a/forum/backends/mysql/api.py +++ b/forum/backends/mysql/api.py @@ -1158,7 +1158,7 @@ def get_threads( params.get("sort_key", ""), int(params.get("page", 1)), int(params.get("per_page", 100)), - context=params.get('context', 'course'), + context=params.get("context", "course"), commentable_ids=params.get("commentable_ids", []), is_moderator=params.get("is_moderator", False), ) diff --git a/forum/migration_helpers.py b/forum/migration_helpers.py index f47d5672..747eb590 100644 --- a/forum/migration_helpers.py +++ b/forum/migration_helpers.py @@ -25,7 +25,6 @@ ) from forum.utils import make_aware, get_trunc_title - logger = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index 19c52af7..6eef312c 100755 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ """ Package metadata for forum. """ + import os import re import sys diff --git a/tests/test_backends/test_mongodb/test_comments.py b/tests/test_backends/test_mongodb/test_comments.py index df750922..d35d64c4 100644 --- a/tests/test_backends/test_mongodb/test_comments.py +++ b/tests/test_backends/test_mongodb/test_comments.py @@ -2,6 +2,7 @@ """ Tests for the `Comment` model. """ + from forum.backends.mongodb import Comment diff --git a/tests/test_management/test_commands/test_migration_commands.py b/tests/test_management/test_commands/test_migration_commands.py index e9fa1b1b..49e48f48 100644 --- a/tests/test_management/test_commands/test_migration_commands.py +++ b/tests/test_management/test_commands/test_migration_commands.py @@ -24,7 +24,6 @@ ) from forum.utils import get_trunc_title - pytestmark = pytest.mark.django_db From 78ebcd80cdd78ab23cc01b983299583e9d33f9cf Mon Sep 17 00:00:00 2001 From: Sara Burns Date: Mon, 30 Mar 2026 11:45:22 -0400 Subject: [PATCH 3/4] fix: context as named parameter --- forum/api/threads.py | 3 ++- forum/migration_helpers.py | 1 + setup.py | 1 - tests/test_backends/test_mongodb/test_comments.py | 1 - tests/test_management/test_commands/test_migration_commands.py | 1 + 5 files changed, 4 insertions(+), 3 deletions(-) diff --git a/forum/api/threads.py b/forum/api/threads.py index a8873cc1..f04bcc80 100644 --- a/forum/api/threads.py +++ b/forum/api/threads.py @@ -362,6 +362,7 @@ def get_user_threads( user_id: Optional[str] = None, group_id: Optional[int] = None, group_ids: Optional[int] = None, + context: Optional[str] = None, **kwargs: Any, ) -> dict[str, Any]: """ @@ -385,7 +386,7 @@ def get_user_threads( "user_id": user_id, "group_id": group_id, "group_ids": group_ids, - "context": kwargs.get("context", None), + "context": context, } params = {k: v for k, v in params.items() if v is not None} backend.validate_params(params) diff --git a/forum/migration_helpers.py b/forum/migration_helpers.py index 747eb590..f47d5672 100644 --- a/forum/migration_helpers.py +++ b/forum/migration_helpers.py @@ -25,6 +25,7 @@ ) from forum.utils import make_aware, get_trunc_title + logger = logging.getLogger(__name__) diff --git a/setup.py b/setup.py index 6eef312c..19c52af7 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ """ Package metadata for forum. """ - import os import re import sys diff --git a/tests/test_backends/test_mongodb/test_comments.py b/tests/test_backends/test_mongodb/test_comments.py index d35d64c4..df750922 100644 --- a/tests/test_backends/test_mongodb/test_comments.py +++ b/tests/test_backends/test_mongodb/test_comments.py @@ -2,7 +2,6 @@ """ Tests for the `Comment` model. """ - from forum.backends.mongodb import Comment diff --git a/tests/test_management/test_commands/test_migration_commands.py b/tests/test_management/test_commands/test_migration_commands.py index 49e48f48..e9fa1b1b 100644 --- a/tests/test_management/test_commands/test_migration_commands.py +++ b/tests/test_management/test_commands/test_migration_commands.py @@ -24,6 +24,7 @@ ) from forum.utils import get_trunc_title + pytestmark = pytest.mark.django_db From 913207de40203d6f78f8b396384e5a8fc95671ec Mon Sep 17 00:00:00 2001 From: Sara Burns Date: Wed, 8 Apr 2026 15:23:45 -0400 Subject: [PATCH 4/4] wip --- forum/backends/mongodb/api.py | 1 + package-lock.json | 6 ++++++ tests/test_views/test_threads.py | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 package-lock.json diff --git a/forum/backends/mongodb/api.py b/forum/backends/mongodb/api.py index b279ac8e..d74c281c 100644 --- a/forum/backends/mongodb/api.py +++ b/forum/backends/mongodb/api.py @@ -992,6 +992,7 @@ def get_threads( int(params.get("per_page", 100)), commentable_ids=params.get("commentable_ids", []), is_moderator=params.get("is_moderator", False), + context=params.get("context", "course"), ) context: dict[str, Any] = { "count_flagged": count_flagged, diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 00000000..929f206a --- /dev/null +++ b/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "forum", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/tests/test_views/test_threads.py b/tests/test_views/test_threads.py index ca28d864..40eeece4 100644 --- a/tests/test_views/test_threads.py +++ b/tests/test_views/test_threads.py @@ -447,6 +447,41 @@ def test_unresponded_filter(api_client: APIClient, patched_get_backend: Any) -> assert len(thread) == 1 +def test_get_user_threads_context(api_client: APIClient, patched_get_backend: Any) -> None: + """Test get_user_threads filters threads by context.""" + backend = patched_get_backend + user_id, course_thread_id = setup_models(backend=backend) + standalone_thread_id = backend.create_thread( + { + "title": "Standalone Thread", + "body": "Standalone Thread", + "course_id": "course1", + "commentable_id": "CommentThread", + "author_id": user_id, + "author_username": "user1", + "abuse_flaggers": [], + "historical_abuse_flaggers": [], + "context": "standalone", + } + ) + + # Default (course) context: only the course thread is returned + response = api_client.get_json("/api/v2/threads", {"course_id": "course1"}) + assert response.status_code == 200 + ids = [t["id"] for t in response.json()["collection"]] + assert course_thread_id in ids + assert standalone_thread_id not in ids + + # Explicit standalone context: only the standalone thread is returned + response = api_client.get_json( + "/api/v2/threads", {"course_id": "course1", "context": "standalone"} + ) + assert response.status_code == 200 + ids = [t["id"] for t in response.json()["collection"]] + assert standalone_thread_id in ids + assert course_thread_id not in ids + + def test_filter_by_post_type(api_client: APIClient, patched_get_backend: Any) -> None: """Test filter threads by thread_type through get thread API.""" backend = patched_get_backend