Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions forum/api/threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions forum/backends/mongodb/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions forum/backends/mysql/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tests/test_views/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading