Commit ddf50371 by Simon Chen

If an course team wants to opt out of studio auto creation, they can with this…

If an course team wants to opt out of studio auto creation, they can with this new toggle on organization
LEANER-2469
parent b2ed6602
# -*- coding: utf-8 -*-
# Generated by Django 1.11.3 on 2017-09-27 17:58
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('publisher', '0057_auto_20170920_1821'),
]
operations = [
migrations.AddField(
model_name='historicalorganizationextension',
name='auto_create_in_studio',
field=models.BooleanField(default=True, help_text='When this flag is enabled, creation of a new course run in Publisher will also create a corresponding course run in Studio.', verbose_name='Automatically create a run in Studio'),
),
migrations.AddField(
model_name='organizationextension',
name='auto_create_in_studio',
field=models.BooleanField(default=True, help_text='When this flag is enabled, creation of a new course run in Publisher will also create a corresponding course run in Studio.', verbose_name='Automatically create a run in Studio'),
),
]
......@@ -570,6 +570,15 @@ class OrganizationExtension(TimeStampedModel):
organization = models.OneToOneField(Organization, related_name='organization_extension')
group = models.OneToOneField(Group, related_name='organization_extension')
auto_create_in_studio = models.BooleanField(
default=True,
verbose_name=_('Automatically create a run in Studio'),
help_text=_(
"When this flag is enabled, creation of a new course run in Publisher"
" will also create a corresponding course run in Studio."
)
)
history = HistoricalRecords()
class Meta(TimeStampedModel.Meta):
......
......@@ -21,6 +21,22 @@ def get_related_discovery_course_run(publisher_course_run):
def create_course_run_in_studio_receiver(sender, instance, created, **kwargs): # pylint: disable=unused-argument
if created and waffle.switch_is_active('enable_publisher_create_course_run_in_studio'):
course = instance.course
for organization in course.organizations.all():
try:
if not organization.organization_extension.auto_create_in_studio:
logger.warning(
('Course run [%d] will not be automatically created in studio.'
'Organization [%s] has opted out of this feature.'),
course.id,
organization.key,
)
return
except ObjectDoesNotExist:
logger.exception(
'Organization [%s] does not have an associated OrganizationExtension',
organization.key,
)
partner = course.partner
if not partner:
......
......@@ -12,7 +12,7 @@ from course_discovery.apps.core.models import Partner
from course_discovery.apps.course_metadata.tests.factories import CourseRunFactory as DiscoveryCourseRunFactory
from course_discovery.apps.course_metadata.tests.factories import OrganizationFactory
from course_discovery.apps.publisher.studio_api_utils import StudioAPI
from course_discovery.apps.publisher.tests.factories import CourseRunFactory
from course_discovery.apps.publisher.tests.factories import CourseRunFactory, OrganizationExtensionFactory
@freeze_time('2017-01-01T00:00:00Z')
......@@ -30,6 +30,23 @@ class TestSignals:
publisher_course_run.course.id
)
@override_switch('enable_publisher_create_course_run_in_studio', active=True)
def test_create_course_run_in_studio_with_organization_opt_out(self):
with mock.patch('course_discovery.apps.publisher.signals.logger.warning') as mock_logger:
course_organization = OrganizationFactory()
OrganizationExtensionFactory(
organization=course_organization,
auto_create_in_studio=False
)
publisher_course_run = CourseRunFactory(course__organizations=[course_organization])
mock_logger.assert_called_with(
('Course run [%d] will not be automatically created in studio.'
'Organization [%s] has opted out of this feature.'),
publisher_course_run.course.id,
course_organization.key,
)
@responses.activate
@mock.patch.object(Partner, 'access_token', return_value='JWT fake')
@override_switch('enable_publisher_create_course_run_in_studio', active=True)
......@@ -50,14 +67,22 @@ class TestSignals:
course_run_key=course_run_key
)
responses.add(responses.POST, url, json=body, status=200)
with mock.patch('course_discovery.apps.publisher.signals.logger.exception') as mock_logger:
publisher_course_run = CourseRunFactory(
start=start,
lms_course_id=None,
course__organizations=[organization]
)
publisher_course_run = CourseRunFactory(start=start, lms_course_id=None, course__organizations=[organization])
# We refresh because the signal should update the instance with the course run key from Studio
publisher_course_run.refresh_from_db()
# We refresh because the signal should update the instance with the course run key from Studio
publisher_course_run.refresh_from_db()
assert len(responses.calls) == 2
assert publisher_course_run.lms_course_id == course_run_key
assert len(responses.calls) == 2
assert publisher_course_run.lms_course_id == course_run_key
mock_logger.assert_called_with(
'Organization [%s] does not have an associated OrganizationExtension',
organization.key,
)
@responses.activate
@mock.patch.object(Partner, 'access_token', return_value='JWT fake')
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-20 15:36-0400\n"
"POT-Creation-Date: 2017-09-27 18:21+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -895,6 +895,16 @@ msgstr ""
msgid "Course Role"
msgstr ""
#: apps/publisher/models.py
msgid "Automatically create a run in Studio"
msgstr ""
#: apps/publisher/models.py
msgid ""
"When this flag is enabled, creation of a new course run in Publisher will "
"also create a corresponding course run in Studio."
msgstr ""
#: apps/publisher/models.py apps/publisher/wrappers.py
msgid "In Draft since"
msgstr ""
......@@ -2612,8 +2622,8 @@ msgstr ""
#: apps/publisher/templates/publisher/email/comment.html
#, python-format
msgid ""
"The %(team_name)s made the following comment on %(course_name)s on %(date)s "
"at %(time)s"
"%(user_name)s made the following comment on %(course_name)s on %(date)s at "
"%(time)s"
msgstr ""
#: apps/publisher/templates/publisher/email/comment.html
......@@ -2634,7 +2644,7 @@ msgstr ""
#: apps/publisher/templates/publisher/email/comment.txt
#, python-format
msgid ""
"The %(team_name)s made the following comment on %(course_name)s %(date)s at "
"%(user_name)s made the following comment on %(course_name)s %(date)s at "
"%(time)s."
msgstr ""
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-15 15:30+0000\n"
"POT-Creation-Date: 2017-09-27 18:21+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-20 15:36-0400\n"
"POT-Creation-Date: 2017-09-27 18:21+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......@@ -1048,6 +1048,20 @@ msgstr "Örgänïzätïön Rölé Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт α
msgid "Course Role"
msgstr "Çöürsé Rölé Ⱡ'σяєм ιρѕυм ∂σłσя #"
#: apps/publisher/models.py
msgid "Automatically create a run in Studio"
msgstr ""
"Àütömätïçällý çréäté ä rün ïn Stüdïö Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυ#"
#: apps/publisher/models.py
msgid ""
"When this flag is enabled, creation of a new course run in Publisher will "
"also create a corresponding course run in Studio."
msgstr ""
"Whén thïs fläg ïs énäßléd, çréätïön öf ä néw çöürsé rün ïn Püßlïshér wïll "
"älsö çréäté ä çörréspöndïng çöürsé rün ïn Stüdïö. Ⱡ'σяєм ιρ#"
#: apps/publisher/models.py apps/publisher/wrappers.py
msgid "In Draft since"
msgstr "Ìn Dräft sïnçé Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт#"
......@@ -3081,11 +3095,11 @@ msgstr ""
#: apps/publisher/templates/publisher/email/comment.html
#, python-format
msgid ""
"The %(team_name)s made the following comment on %(course_name)s on %(date)s "
"at %(time)s"
"%(user_name)s made the following comment on %(course_name)s on %(date)s at "
"%(time)s"
msgstr ""
"Thé %(team_name)s mädé thé föllöwïng çömmént ön %(course_name)s ön %(date)s "
"ät %(time)s Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"
"%(user_name)s mädé thé föllöwïng çömmént ön %(course_name)s ön %(date)s ät "
"%(time)s Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"
#: apps/publisher/templates/publisher/email/comment.html
#: apps/publisher/templates/publisher/email/comment.txt
......@@ -3105,10 +3119,10 @@ msgstr "Thé édX téäm Ⱡ'σяєм ιρѕυм ∂σłσя ѕ#"
#: apps/publisher/templates/publisher/email/comment.txt
#, python-format
msgid ""
"The %(team_name)s made the following comment on %(course_name)s %(date)s at "
"%(user_name)s made the following comment on %(course_name)s %(date)s at "
"%(time)s."
msgstr ""
"Thé %(team_name)s mädé thé föllöwïng çömmént ön %(course_name)s %(date)s ät "
"%(user_name)s mädé thé föllöwïng çömmént ön %(course_name)s %(date)s ät "
"%(time)s. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕє¢тєтυя α#"
#: apps/publisher/templates/publisher/email/course/mark_as_reviewed.html
......
......@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-15 15:30+0000\n"
"POT-Creation-Date: 2017-09-27 18:21+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
......
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