From 06ff32c596086e860f93c585df93ca489d55ccc1 Mon Sep 17 00:00:00 2001 From: Sara Burns Date: Thu, 26 Mar 2026 12:50:13 -0400 Subject: [PATCH 1/3] fix: Fix thread api call to work with teams --- forum/api/threads.py | 2 ++ forum/backends/mongodb/api.py | 1 + forum/backends/mysql/api.py | 1 + forum/migration_helpers.py | 1 + package-lock.json | 6 ++++ setup.py | 1 - .../test_mongodb/test_comments.py | 1 - .../test_commands/test_migration_commands.py | 1 + tests/test_views/test_threads.py | 35 +++++++++++++++++++ 9 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 package-lock.json diff --git a/forum/api/threads.py b/forum/api/threads.py index b5b036c5..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,6 +386,7 @@ def get_user_threads( "user_id": user_id, "group_id": group_id, "group_ids": group_ids, + "context": context, } params = {k: v for k, v in params.items() if v is not None} backend.validate_params(params) 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/forum/backends/mysql/api.py b/forum/backends/mysql/api.py index c383d31a..1641c860 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), ) diff --git a/forum/migration_helpers.py b/forum/migration_helpers.py index 23b68e60..fb3a79a9 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/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/setup.py b/setup.py index db4f5f03..940e9d77 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 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 From 2c1d6394d6095cc1e7b07654a927c8ee8c7961bd Mon Sep 17 00:00:00 2001 From: Sara Burns Date: Tue, 14 Apr 2026 14:16:11 -0400 Subject: [PATCH 2/3] test: add test --- forum/backends/mongodb/api.py | 1 + forum/backends/mysql/api.py | 1 + tests/test_views/test_threads.py | 4 +++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/forum/backends/mongodb/api.py b/forum/backends/mongodb/api.py index d74c281c..4c3dd78b 100644 --- a/forum/backends/mongodb/api.py +++ b/forum/backends/mongodb/api.py @@ -948,6 +948,7 @@ def validate_params(params: dict[str, Any], user_id: Optional[str] = None) -> No "commentable_ids", "group_id", "group_ids", + "context", ] if not user_id: valid_params.append("user_id") diff --git a/forum/backends/mysql/api.py b/forum/backends/mysql/api.py index 1641c860..9120ac15 100644 --- a/forum/backends/mysql/api.py +++ b/forum/backends/mysql/api.py @@ -1105,6 +1105,7 @@ def validate_params( "commentable_ids", "group_id", "group_ids", + "context", ] if not user_id: valid_params.append("user_id") diff --git a/tests/test_views/test_threads.py b/tests/test_views/test_threads.py index 40eeece4..46892158 100644 --- a/tests/test_views/test_threads.py +++ b/tests/test_views/test_threads.py @@ -447,7 +447,9 @@ 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: +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) From bdea1fb5da4eeb3514a9228f3dc2691892bf6e99 Mon Sep 17 00:00:00 2001 From: Sara Burns Date: Tue, 14 Apr 2026 14:21:05 -0400 Subject: [PATCH 3/3] chore: reset untouched files --- forum/migration_helpers.py | 1 - package-lock.json | 6 ------ setup.py | 1 + tests/test_backends/test_mongodb/test_comments.py | 1 + .../test_commands/test_migration_commands.py | 1 - 5 files changed, 2 insertions(+), 8 deletions(-) delete mode 100644 package-lock.json diff --git a/forum/migration_helpers.py b/forum/migration_helpers.py index fb3a79a9..23b68e60 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/package-lock.json b/package-lock.json deleted file mode 100644 index 929f206a..00000000 --- a/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "forum", - "lockfileVersion": 3, - "requires": true, - "packages": {} -} diff --git a/setup.py b/setup.py index 940e9d77..db4f5f03 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