Commit b7e2d3be by Waheed Ahmed

After MKT has reviewed a COURSE, any CT edits doesn't have to be approved by MKT again.

ECOM-7538
parent e32f2f15
......@@ -441,7 +441,7 @@ class ChangeCourseStateViewTests(TestCase):
def test_change_course_state(self):
"""
Verify that if marketing user change course workflow state, owner role will be changed to `CourseTeam`.
Verify that if marketing user change course state, owner role will be changed to `CourseTeam`.
"""
self.assertNotEqual(self.course_state.name, CourseStateChoices.Review)
factories.CourseUserRoleFactory(
......@@ -465,6 +465,8 @@ class ChangeCourseStateViewTests(TestCase):
self.assertEqual(self.course_state.name, CourseStateChoices.Review)
self.assertEqual(self.course_state.owner_role, PublisherUserRole.CourseTeam)
# Verify that course is marked as reviewed by marketing.
self.assertTrue(self.course_state.marketing_reviewed)
subject = 'Changes to {title} are ready for review'.format(title=self.course.title)
self._assert_email_sent(course_team_user, subject)
......
......@@ -522,11 +522,10 @@ class CourseState(TimeStampedModel, ChangedByMixin):
elif state == CourseStateChoices.Review:
user_role = self.course.course_user_roles.get(user=user)
if user_role.role == PublisherUserRole.MarketingReviewer:
self.owner_role = PublisherUserRole.CourseTeam
self.owner_role_modified = timezone.now()
self.change_owner_role(PublisherUserRole.CourseTeam)
self.marketing_reviewed = True
elif user_role.role == PublisherUserRole.CourseTeam:
self.owner_role = PublisherUserRole.MarketingReviewer
self.owner_role_modified = timezone.now()
self.change_owner_role(PublisherUserRole.MarketingReviewer)
self.review()
......@@ -536,7 +535,6 @@ class CourseState(TimeStampedModel, ChangedByMixin):
elif state == CourseStateChoices.Approved:
user_role = self.course.course_user_roles.get(user=user)
self.approved_by_role = user_role.role
self.owner_role_modified = timezone.now()
self.approved()
if waffle.switch_is_active('enable_publisher_email_notifications'):
......@@ -618,11 +616,9 @@ class CourseRunState(TimeStampedModel, ChangedByMixin):
elif state == CourseRunStateChoices.Review:
user_role = self.course_run.course.course_user_roles.get(user=user)
if user_role.role == PublisherUserRole.ProjectCoordinator:
self.owner_role = PublisherUserRole.CourseTeam
self.owner_role_modified = timezone.now()
self.change_owner_role(PublisherUserRole.CourseTeam)
elif user_role.role == PublisherUserRole.CourseTeam:
self.owner_role = PublisherUserRole.ProjectCoordinator
self.owner_role_modified = timezone.now()
self.change_owner_role(PublisherUserRole.ProjectCoordinator)
self.review()
......@@ -632,8 +628,7 @@ class CourseRunState(TimeStampedModel, ChangedByMixin):
elif state == CourseRunStateChoices.Approved:
user_role = self.course_run.course.course_user_roles.get(user=user)
self.approved_by_role = user_role.role
self.owner_role = PublisherUserRole.Publisher
self.owner_role_modified = timezone.now()
self.change_owner_role(PublisherUserRole.Publisher)
self.approved()
if waffle.switch_is_active('enable_publisher_email_notifications'):
......
......@@ -2068,6 +2068,36 @@ class CourseEditViewTests(TestCase):
self.assertEqual(course_state.name, CourseStateChoices.Draft)
self.assertEqual(course_state.owner_role, PublisherUserRole.CourseTeam)
def test_edit_course_with_marketing_reviewed(self):
"""
Verify that if marketing already reviewed the course and then course team editing the course,
state does not change to `Draft` and ownership remains to `CourseTeam`.
"""
self.client.logout()
self.client.login(username=self.course_team_role.user.username, password=USER_PASSWORD)
self._assign_permissions(self.organization_extension)
self.course.course_state.name = CourseStateChoices.Review
self.course.course_state.owner_role = PublisherUserRole.CourseTeam
self.course.course_state.marketing_reviewed = True
self.course.course_state.save()
post_data = self._post_data(self.organization_extension)
post_data['team_admin'] = self.course_team_role.user.id
response = self.client.post(self.edit_page_url, data=post_data)
self.assertRedirects(
response,
expected_url=reverse('publisher:publisher_course_detail', kwargs={'pk': self.course.id}),
status_code=302,
target_status_code=200
)
course_state = CourseState.objects.get(id=self.course.course_state.id)
self.assertEqual(course_state.name, CourseStateChoices.Review)
self.assertEqual(course_state.owner_role, PublisherUserRole.CourseTeam)
@ddt.ddt
class CourseRunEditViewTests(TestCase):
......
......@@ -365,13 +365,17 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView):
course_admin_role.user = team_admin
course_admin_role.save()
if self.object.course_state.name != CourseStateChoices.Draft:
self.object.course_state.change_state(state=CourseStateChoices.Draft, user=user)
# Change ownership if user role not equal to owner role.
user_role = self.object.course_user_roles.get(user=user)
if self.object.course_state.owner_role != user_role.role:
self.object.course_state.change_owner_role(user_role.role)
# Change course state to draft if marketing not yet reviewed or
# if marketing person updating the course.
if not self.object.course_state.marketing_reviewed or user_role.role == PublisherUserRole.MarketingReviewer:
if self.object.course_state.name != CourseStateChoices.Draft:
self.object.course_state.change_state(state=CourseStateChoices.Draft, user=user)
# Change ownership if user role not equal to owner role.
if self.object.course_state.owner_role != user_role.role:
self.object.course_state.change_owner_role(user_role.role)
messages.success(self.request, _('Course updated successfully.'))
return HttpResponseRedirect(self.get_success_url())
......
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