fix: pinned is set to false for all posts in learner area

This commit is contained in:
adeel.tajamul
2022-06-17 17:38:44 +05:00
parent 30229c86e2
commit 92e862149d
2 changed files with 16 additions and 1 deletions

View File

@@ -92,7 +92,7 @@ from .serializers import (
UserStatsSerializer,
get_context,
)
from .utils import discussion_open_for_user
from .utils import discussion_open_for_user, set_threads_attribute_value
User = get_user_model()
@@ -883,6 +883,7 @@ def get_learner_active_thread_list(request, course_key, query_params):
profiled_user = comment_client.User(id=user_id, course_id=course_key)
threads, page, num_pages = profiled_user.active_threads(query_params)
threads = set_threads_attribute_value(threads, "pinned", False)
results = _serialize_discussion_entities(
request, context, threads, {'profile_image'}, DiscussionEntity.thread
)

View File

@@ -14,3 +14,17 @@ def discussion_open_for_user(course, user):
user: User to check for privileges in course
"""
return course.forum_posts_allowed or has_discussion_privileges(user, course.id)
def set_threads_attribute_value(threads, attribute, value):
"""
It iterates over thread list and assign thread attribute the value
Arguments:
threads: List containing threads
attribute: the key for thread dict
value: the value to assign to the thread attribute
"""
for thread in threads:
thread[attribute] = value
return threads