Commit 74435a79 by Waheed Ahmed

Fixed role widgets for parent course.

ECOM-7500
parent 4506d4d0
...@@ -1721,16 +1721,13 @@ class CourseDetailViewTests(TestCase): ...@@ -1721,16 +1721,13 @@ class CourseDetailViewTests(TestCase):
factories.CourseUserRoleFactory( factories.CourseUserRoleFactory(
course=self.course, user=self.user, role=PublisherUserRole.MarketingReviewer course=self.course, user=self.user, role=PublisherUserRole.MarketingReviewer
) )
factories.CourseUserRoleFactory(
course=self.course, user=UserFactory(), role=PublisherUserRole.Publisher
)
# To create history objects for both `Review` and `Approved` states # To create history objects for both `Review` and `Approved` states
self.course_state.name = CourseStateChoices.Review self.course_state.name = CourseStateChoices.Review
self.course_state.save() self.course_state.save()
self.course_state.name = CourseStateChoices.Approved self.course_state.name = CourseStateChoices.Approved
self.course_state.owner_role = PublisherUserRole.Publisher self.course_state.owner_role = PublisherUserRole.MarketingReviewer
self.course_state.approved_by_role = PublisherUserRole.CourseTeam self.course_state.approved_by_role = PublisherUserRole.MarketingReviewer
self.course_state.save() self.course_state.save()
self.user.groups.add(self.organization_extension.group) self.user.groups.add(self.organization_extension.group)
...@@ -1768,6 +1765,29 @@ class CourseDetailViewTests(TestCase): ...@@ -1768,6 +1765,29 @@ class CourseDetailViewTests(TestCase):
# Verify that user cannot see edit button if he has no role for course. # Verify that user cannot see edit button if he has no role for course.
self.assert_can_edit_permission(can_edit=False) self.assert_can_edit_permission(can_edit=False)
def test_detail_page_with_role_widgets(self):
"""
Test that user can see only two role widgets `Course Team` and `Marketing`
on detail page even if other roles exists for course.
"""
factories.CourseUserRoleFactory(
course=self.course, user=UserFactory(), role=PublisherUserRole.MarketingReviewer
)
factories.CourseUserRoleFactory(
course=self.course, user=UserFactory(), role=PublisherUserRole.Publisher
)
self.user.groups.add(self.organization_extension.group)
assign_perm(OrganizationExtension.VIEW_COURSE, self.organization_extension.group, self.organization_extension)
assign_perm(OrganizationExtension.EDIT_COURSE, self.organization_extension.group, self.organization_extension)
response = self.client.get(self.detail_page_url)
self.assertContains(response, '<div class="role-widget">', 2)
self.assertContains(response, '<strong>COURSE TEAM</strong>')
self.assertContains(response, '<strong>MARKETING</strong>')
self.assertNotContains(response, '<strong>PUBLISHER</strong>')
class CourseEditViewTests(TestCase): class CourseEditViewTests(TestCase):
""" Tests for the course edit view. """ """ Tests for the course edit view. """
......
...@@ -392,7 +392,7 @@ class CourseDetailView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMixi ...@@ -392,7 +392,7 @@ class CourseDetailView(mixins.LoginRequiredMixin, mixins.PublisherPermissionMixi
context['publisher_history_widget_feature'] = waffle.switch_is_active('publisher_history_widget_feature') context['publisher_history_widget_feature'] = waffle.switch_is_active('publisher_history_widget_feature')
context['publisher_approval_widget_feature'] = waffle.switch_is_active('publisher_approval_widget_feature') context['publisher_approval_widget_feature'] = waffle.switch_is_active('publisher_approval_widget_feature')
context['role_widgets'] = get_course_role_widgets_data( context['role_widgets'] = get_course_role_widgets_data(
user, course, course.course_state, 'publisher:api:change_course_state' user, course, course.course_state, 'publisher:api:change_course_state', parent_course=True
) )
# Add warning popup information if user can edit the course but does not own it. # Add warning popup information if user can edit the course but does not own it.
...@@ -703,11 +703,14 @@ class CourseRevisionView(mixins.LoginRequiredMixin, DetailView): ...@@ -703,11 +703,14 @@ class CourseRevisionView(mixins.LoginRequiredMixin, DetailView):
return context return context
def get_course_role_widgets_data(user, course, state_object, change_state_url): def get_course_role_widgets_data(user, course, state_object, change_state_url, parent_course=False):
""" Create role widgets list for course user roles. """ """ Create role widgets list for course user roles. """
role_widgets = [] role_widgets = []
course_roles = course.course_user_roles
if parent_course:
course_roles = course_roles.filter(role__in=[PublisherUserRole.CourseTeam, PublisherUserRole.MarketingReviewer])
for course_role in course.course_user_roles.order_by('role'): for course_role in course_roles.order_by('role'):
role_widget = { role_widget = {
'course_role': course_role, 'course_role': course_role,
'heading': ROLE_WIDGET_HEADINGS.get(course_role.role), 'heading': ROLE_WIDGET_HEADINGS.get(course_role.role),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment