Merge pull request #5687 from edx/sanchez/no-donations-for-microsites
Adding an additional check to avoid donations showing up for microsites.
This commit is contained in:
@@ -163,6 +163,25 @@ class CourseMode(models.Model):
|
||||
return mode.min_price
|
||||
return 0
|
||||
|
||||
@classmethod
|
||||
def has_payment_options(cls, course_id):
|
||||
"""Determines if there is any mode that has payment options
|
||||
|
||||
Check the dict of course modes and see if any of them have a minimum price or
|
||||
suggested prices. Returns True if any course mode has a payment option.
|
||||
|
||||
Args:
|
||||
course_mode_dict (dict): Dictionary mapping course mode slugs to Modes
|
||||
|
||||
Returns:
|
||||
True if any course mode has a payment option.
|
||||
|
||||
"""
|
||||
for mode in cls.modes_for_course(course_id):
|
||||
if mode.min_price > 0 or mode.suggested_prices != '':
|
||||
return True
|
||||
return False
|
||||
|
||||
@classmethod
|
||||
def min_course_price_for_currency(cls, course_id, currency):
|
||||
"""
|
||||
|
||||
@@ -127,3 +127,22 @@ class CourseModeModelTest(TestCase):
|
||||
mode = CourseMode.verified_mode_for_course(self.course_key)
|
||||
|
||||
self.assertEqual(mode.slug, 'professional')
|
||||
|
||||
def test_course_has_payment_options(self):
|
||||
# Has no payment options.
|
||||
honor, _ = self.create_mode('honor', 'Honor')
|
||||
self.assertFalse(CourseMode.has_payment_options(self.course_key))
|
||||
|
||||
# Now we do have a payment option.
|
||||
verified, _ = self.create_mode('verified', 'Verified', min_price=5)
|
||||
self.assertTrue(CourseMode.has_payment_options(self.course_key))
|
||||
|
||||
# Unset verified's minimum price.
|
||||
verified.min_price = 0
|
||||
verified.save()
|
||||
self.assertFalse(CourseMode.has_payment_options(self.course_key))
|
||||
|
||||
# Finally, give the honor mode payment options
|
||||
honor.suggested_prices = '5, 10, 15'
|
||||
honor.save()
|
||||
self.assertTrue(CourseMode.has_payment_options(self.course_key))
|
||||
|
||||
@@ -697,7 +697,10 @@ def _allow_donation(course_modes, course_id):
|
||||
True if the course is allowing donations.
|
||||
|
||||
"""
|
||||
return DonationConfiguration.current().enabled and not CourseMode.has_verified_mode(course_modes[course_id])
|
||||
donations_enabled = DonationConfiguration.current().enabled
|
||||
is_verified_mode = CourseMode.has_verified_mode(course_modes[course_id])
|
||||
has_payment_option = CourseMode.has_payment_options(course_id)
|
||||
return donations_enabled and not is_verified_mode and not has_payment_option
|
||||
|
||||
|
||||
def try_change_enrollment(request):
|
||||
|
||||
Reference in New Issue
Block a user