Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
f68edf9f
Commit
f68edf9f
authored
Mar 05, 2018
by
Michael Terry
Committed by
Michael Terry
Mar 05, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Drop publisher_entitlements waffle flag
The feature has fully landed. We just want it always on now. LEARNER-4152
parent
84f26e86
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
59 deletions
+25
-59
course_discovery/apps/publisher/api/v1/tests/test_views.py
+0
-3
course_discovery/apps/publisher/api/v1/views.py
+12
-15
course_discovery/apps/publisher/constants.py
+0
-1
course_discovery/apps/publisher/tests/test_views.py
+1
-17
course_discovery/apps/publisher/views.py
+12
-23
No files found.
course_discovery/apps/publisher/api/v1/tests/test_views.py
View file @
f68edf9f
...
...
@@ -14,7 +14,6 @@ from course_discovery.apps.core.utils import serialize_datetime
from
course_discovery.apps.course_metadata.models
import
CourseEntitlement
as
DiscoveryCourseEntitlement
from
course_discovery.apps.course_metadata.models
import
Seat
as
DiscoverySeat
from
course_discovery.apps.course_metadata.models
import
CourseRun
,
SeatType
,
Video
from
course_discovery.apps.course_metadata.tests
import
toggle_switch
from
course_discovery.apps.course_metadata.tests.factories
import
OrganizationFactory
,
PersonFactory
from
course_discovery.apps.ietf_language_tags.models
import
LanguageTag
from
course_discovery.apps.publisher.api.utils
import
(
serialize_entitlement_for_ecommerce_api
,
...
...
@@ -82,8 +81,6 @@ class CourseRunViewSetTests(APITestCase):
@responses.activate
@mock.patch.object
(
Partner
,
'access_token'
,
return_value
=
'JWT fake'
)
def
test_publish
(
self
,
mock_access_token
):
# pylint: disable=unused-argument,too-many-statements
toggle_switch
(
'publisher_entitlements'
,
True
)
publisher_course_run
=
self
.
_create_course_run_for_publication
()
currency
=
Currency
.
objects
.
get
(
code
=
'USD'
)
...
...
course_discovery/apps/publisher/api/v1/views.py
View file @
f68edf9f
import
logging
from
collections
import
OrderedDict
import
waffle
from
edx_rest_api_client.client
import
EdxRestApiClient
from
edx_rest_framework_extensions.authentication
import
JwtAuthentication
from
rest_framework
import
permissions
,
serializers
,
status
,
viewsets
...
...
@@ -95,9 +94,8 @@ class CourseRunViewSet(viewsets.GenericViewSet):
# NOTE: We only order here to aid testing. The E-Commerce API does NOT care about ordering.
products
=
[
serialize_seat_for_ecommerce_api
(
seat
)
for
seat
in
course_run
.
seats
.
exclude
(
type
=
Seat
.
CREDIT
)
.
order_by
(
'created'
)]
if
waffle
.
switch_is_active
(
'publisher_entitlements'
):
products
.
extend
([
serialize_entitlement_for_ecommerce_api
(
entitlement
)
for
entitlement
in
course_run
.
course
.
entitlements
.
order_by
(
'created'
)])
products
.
extend
([
serialize_entitlement_for_ecommerce_api
(
entitlement
)
for
entitlement
in
course_run
.
course
.
entitlements
.
order_by
(
'created'
)])
data
[
'products'
]
=
products
try
:
...
...
@@ -160,17 +158,16 @@ class CourseRunViewSet(viewsets.GenericViewSet):
discovery_course_run
.
transcript_languages
.
add
(
*
course_run
.
transcript_languages
.
all
())
discovery_course_run
.
staff
.
add
(
*
course_run
.
staff
.
all
())
if
waffle
.
switch_is_active
(
'publisher_entitlements'
):
for
entitlement
in
publisher_course
.
entitlements
.
all
():
DiscoveryCourseEntitlement
.
objects
.
update_or_create
(
course
=
discovery_course
,
mode
=
SeatType
.
objects
.
get
(
slug
=
entitlement
.
mode
),
defaults
=
{
'partner'
:
partner
,
'price'
:
entitlement
.
price
,
'currency'
:
entitlement
.
currency
,
}
)
for
entitlement
in
publisher_course
.
entitlements
.
all
():
DiscoveryCourseEntitlement
.
objects
.
update_or_create
(
course
=
discovery_course
,
mode
=
SeatType
.
objects
.
get
(
slug
=
entitlement
.
mode
),
defaults
=
{
'partner'
:
partner
,
'price'
:
entitlement
.
price
,
'currency'
:
entitlement
.
currency
,
}
)
for
seat
in
course_run
.
seats
.
exclude
(
type
=
Seat
.
CREDIT
)
.
order_by
(
'created'
):
DiscoverySeat
.
objects
.
update_or_create
(
...
...
course_discovery/apps/publisher/constants.py
View file @
f68edf9f
...
...
@@ -16,5 +16,4 @@ PARTNER_SUPPORT_GROUP_NAME = 'Partner Support Members'
PARTNER_COORDINATOR_GROUP_NAME
=
'Partner Coordinators'
# Waffle flags
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
=
'publisher_entitlements'
PUBLISHER_CREATE_AUDIT_SEATS_FOR_VERIFIED_COURSE_RUNS
=
'publisher_create_audit_seats_for_verified_course_runs'
course_discovery/apps/publisher/tests/test_views.py
View file @
f68edf9f
...
...
@@ -35,7 +35,7 @@ from course_discovery.apps.publisher.choices import (
)
from
course_discovery.apps.publisher.constants
import
(
ADMIN_GROUP_NAME
,
INTERNAL_USER_GROUP_NAME
,
PROJECT_COORDINATOR_GROUP_NAME
,
PUBLISHER_CREATE_AUDIT_SEATS_FOR_VERIFIED_COURSE_RUNS
,
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
,
REVIEWER_GROUP_NAME
PUBLISHER_CREATE_AUDIT_SEATS_FOR_VERIFIED_COURSE_RUNS
,
REVIEWER_GROUP_NAME
)
from
course_discovery.apps.publisher.models
import
(
Course
,
CourseEntitlement
,
CourseRun
,
CourseRunState
,
CourseState
,
OrganizationExtension
,
Seat
...
...
@@ -302,8 +302,6 @@ class CreateCourseViewTests(SiteMixin, TestCase):
"""
Verify that we create an entitlement for appropriate types (happy path)
"""
toggle_switch
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
,
True
)
data
=
{
'mode'
:
mode
,
'price'
:
50
}
course
=
self
.
_create_course_with_post
(
data
)
...
...
@@ -316,21 +314,10 @@ class CreateCourseViewTests(SiteMixin, TestCase):
self
.
assertEqual
(
mode
,
entitlement
.
mode
)
self
.
assertEqual
(
50
,
entitlement
.
price
)
def
test_no_entitlement_created_without_switch
(
self
):
"""
Verify that when we create a verified seat without the entitlement waffle switch enabled, we set version right
"""
toggle_switch
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
,
False
)
data
=
{
'mode'
:
CourseEntitlement
.
VERIFIED
,
'price'
:
50
}
course
=
self
.
_create_course_with_post
(
data
)
self
.
assertEqual
(
0
,
CourseEntitlement
.
objects
.
all
()
.
count
())
self
.
assertEqual
(
Course
.
SEAT_VERSION
,
course
.
version
)
def
test_seat_version
(
self
):
"""
Verify that when we create a seat product without an entitlement, we set version correctly
"""
toggle_switch
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
,
True
)
course
=
self
.
_create_course_with_post
()
self
.
assertEqual
(
0
,
CourseEntitlement
.
objects
.
all
()
.
count
())
self
.
assertEqual
(
Course
.
SEAT_VERSION
,
course
.
version
)
...
...
@@ -340,7 +327,6 @@ class CreateCourseViewTests(SiteMixin, TestCase):
"""
Verify that we check price validity when making an entitlement
"""
toggle_switch
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
,
True
)
data
=
{
'title'
:
'Test2'
,
'number'
:
'testX234'
,
'mode'
:
CourseEntitlement
.
VERIFIED
}
if
price
is
not
None
:
data
[
'price'
]
=
price
...
...
@@ -2996,7 +2982,6 @@ class CourseEditViewTests(SiteMixin, TestCase):
Verify that a SEAT_VERSION Course that has course runs associated with it can be updated without changing
the version, and can change the version as long as the Course Run Seat prices and types match the Course
"""
toggle_switch
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
,
True
)
self
.
user
.
groups
.
add
(
Group
.
objects
.
get
(
name
=
INTERNAL_USER_GROUP_NAME
))
self
.
course
.
version
=
Course
.
SEAT_VERSION
self
.
course
.
save
()
...
...
@@ -3070,7 +3055,6 @@ class CourseEditViewTests(SiteMixin, TestCase):
"""
Verify that an ENTITLEMENT_VERSION Course cannot be reverted to a SEAT_RUN Course, but a Course can be updated
"""
toggle_switch
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
,
True
)
self
.
user
.
groups
.
add
(
Group
.
objects
.
get
(
name
=
INTERNAL_USER_GROUP_NAME
))
self
.
course
.
version
=
Course
.
SEAT_VERSION
self
.
course
.
save
()
...
...
course_discovery/apps/publisher/views.py
View file @
f68edf9f
...
...
@@ -27,7 +27,6 @@ from course_discovery.apps.course_metadata.models import Person
from
course_discovery.apps.ietf_language_tags.models
import
LanguageTag
from
course_discovery.apps.publisher
import
emails
,
mixins
,
serializers
from
course_discovery.apps.publisher.choices
import
CourseRunStateChoices
,
CourseStateChoices
,
PublisherUserRole
from
course_discovery.apps.publisher.constants
import
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
from
course_discovery.apps.publisher.dataloader.create_courses
import
process_course
from
course_discovery.apps.publisher.emails
import
send_email_for_published_course_run_editing
from
course_discovery.apps.publisher.forms
import
(
...
...
@@ -256,14 +255,12 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
return
success_url
def
get_context_data
(
self
):
data
=
{
return
{
'course_form'
:
self
.
course_form
(
user
=
self
.
request
.
user
),
'entitlement_form'
:
self
.
entitlement_form
(),
'publisher_hide_features_for_pilot'
:
waffle
.
switch_is_active
(
'publisher_hide_features_for_pilot'
),
'publisher_add_instructor_feature'
:
waffle
.
switch_is_active
(
'publisher_add_instructor_feature'
),
}
if
waffle
.
switch_is_active
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
):
data
[
'entitlement_form'
]
=
self
.
entitlement_form
()
return
data
def
get
(
self
,
request
,
*
args
,
**
kwargs
):
return
render
(
request
,
self
.
template_name
,
self
.
get_context_data
())
...
...
@@ -272,8 +269,6 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
ctx
=
self
.
get_context_data
()
add_new_run
=
request
.
POST
.
get
(
'add_new_run'
)
support_entitlements
=
waffle
.
switch_is_active
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
)
# pass selected organization to CourseForm to populate related
# choices into institution admin field
user
=
self
.
request
.
user
...
...
@@ -287,7 +282,7 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
try
:
with
transaction
.
atomic
():
course
=
course_form
.
save
(
commit
=
False
)
if
entitlement_form
[
'mode'
]
.
value
()
and
support_entitlements
:
if
entitlement_form
[
'mode'
]
.
value
():
course
.
version
=
Course
.
ENTITLEMENT_VERSION
else
:
course
.
version
=
Course
.
SEAT_VERSION
...
...
@@ -297,7 +292,7 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
course_form
.
save_m2m
()
# Now create entitlement if we need to
if
course
.
version
==
Course
.
ENTITLEMENT_VERSION
:
if
course
.
uses_entitlements
:
entitlement_form
.
save
(
course
=
course
)
organization_extension
=
get_object_or_404
(
...
...
@@ -350,10 +345,9 @@ class CreateCourseView(mixins.LoginRequiredMixin, mixins.PublisherUserRequiredMi
ctx
.
update
(
{
'course_form'
:
course_form
,
'entitlement_form'
:
entitlement_form
,
}
)
if
support_entitlements
:
ctx
[
'entitlement_form'
]
=
entitlement_form
return
render
(
request
,
self
.
template_name
,
ctx
,
status
=
400
)
...
...
@@ -388,11 +382,10 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView):
}
)
if
waffle
.
switch_is_active
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
):
if
self
.
object
.
version
==
Course
.
ENTITLEMENT_VERSION
:
context
[
'entitlement_form'
]
=
self
.
entitlement_form
(
instance
=
self
.
object
.
entitlements
.
first
())
else
:
context
[
'entitlement_form'
]
=
self
.
entitlement_form
({
'mode'
:
''
})
if
self
.
object
.
uses_entitlements
:
context
[
'entitlement_form'
]
=
self
.
entitlement_form
(
instance
=
self
.
object
.
entitlements
.
first
())
else
:
context
[
'entitlement_form'
]
=
self
.
entitlement_form
({
'mode'
:
''
})
return
context
...
...
@@ -560,13 +553,9 @@ class CourseEditView(mixins.PublisherPermissionMixin, UpdateView):
)
return
self
.
render_to_response
(
self
.
get_context_data
(
form
=
course_form
))
# If the switch is active handle the different Course versions, otherwise just save the form like normal
if
waffle
.
switch_is_active
(
PUBLISHER_ENTITLEMENTS_WAFFLE_SWITCH
):
error_response
=
self
.
_handle_entitlement_update
(
user
,
request
,
course_form
)
if
error_response
:
return
error_response
else
:
self
.
_update_course
(
course_form
,
user
,
Course
.
SEAT_VERSION
)
error_response
=
self
.
_handle_entitlement_update
(
user
,
request
,
course_form
)
if
error_response
:
return
error_response
organization
=
course_form
.
cleaned_data
[
'organization'
]
if
self
.
object
.
organizations
.
first
()
!=
organization
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment