Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1542a0c
UNIFICATION: get_current_organization don't assume single Organization
bryanlandia Dec 12, 2020
b5ab596
Use FEATURE switch to determine how we get current Org by by Site
bryanlandia Dec 14, 2020
2d216b6
Fix factory.fuzzy import in appsembler api test factories
bryanlandia Dec 17, 2020
d298926
TestCase covering appsembler.sites.utils get_current_organization
bryanlandia Dec 17, 2020
7db75ba
Allow auto-generation of certs (e.g., on passing grade) for Honor mode
bryanlandia Dec 23, 2020
bc00049
Merge pull request #794 from appsembler/bryan/allow-auto-generated-ce…
bryanlandia Dec 28, 2020
42d2a46
tracks static page
OmarIthawi Dec 29, 2020
e9f577b
Merge pull request #796 from appsembler/omar/tracks
OmarIthawi Dec 29, 2020
0eae98c
Merge pull request #785 from appsembler/bryan/tahoe-standalone-compat…
bryanlandia Dec 29, 2020
17648d7
Update translations (autogenerated message)
OmarIthawi Jan 6, 2021
45d0fa6
Merge pull request #797 from appsembler/omar/i18n-2021
OmarIthawi Jan 6, 2021
14e11b9
lms organization middleware to make tiers expiration work in lms
OmarIthawi Jan 19, 2021
8a4c2fa
RedirectMiddleware: redirect function variable unshadow
OmarIthawi Jan 19, 2021
eef9ea3
Merge pull request #804 from appsembler/omar/dupl-var
OmarIthawi Jan 19, 2021
2ea4d3a
Merge pull request #803 from appsembler/omar/lms-org-middleware
OmarIthawi Jan 20, 2021
26e2503
RED-1431: bump django-tiers to v0.2.3 for trial expiration fixes
OmarIthawi Jan 20, 2021
614cdd1
Merge pull request #806 from appsembler/omar/tiers-bump
OmarIthawi Jan 20, 2021
efb1e17
add honeycomb tracing and context on registration API
thraxil Feb 2, 2021
d20ff8a
Merge pull request #812 from appsembler/registration-honeycomb
OmarIthawi Feb 3, 2021
6afa0cf
get_active_sites() to return QuerySet
OmarIthawi Feb 4, 2021
6d453b2
beeline: fix unhashable type: 'dict'
OmarIthawi Feb 4, 2021
2da4dbf
Merge pull request #815 from appsembler/omar/sites-queryset
OmarIthawi Feb 4, 2021
0de24d8
Merge pull request #816 from appsembler/omar/beeline-fix
OmarIthawi Feb 4, 2021
298d314
FEATURE FLAG-gate the inclusion of Appsembler Redirect middlewares
bryanlandia Feb 4, 2021
f9cae26
Tahoe RedirectMiddleware use TAHOE_MAINSITE_REDIRECT_URL ENV_TOKEN
bryanlandia Feb 4, 2021
2fb2af2
RedirectMiddleware tests, import cleanup
bryanlandia Feb 4, 2021
e603c70
Tahoe redirect middleware tests updates
bryanlandia Feb 4, 2021
e4bf2b3
constant for TAHOE_MARKETING_SITE_URL in settings
bryanlandia Feb 4, 2021
baccd3a
Clarify variable name and fix insert ordering of Tahoe redir middleware
bryanlandia Feb 19, 2021
d7c4265
Merge pull request #817 from appsembler/appsembler/tahoe-move-middlew…
bryanlandia Feb 19, 2021
577fd48
get_lms_link_from_course_key fallback to LMS base if no Site found
bryanlandia Feb 2, 2021
f209638
Removed unused preview property and add unit tests for get_lms_link_f…
bryanlandia Feb 22, 2021
ad6e1b0
Merge pull request #813 from appsembler/bryan/lms-link-fallback-no-co…
bryanlandia Feb 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lms/djangoapps/certificates/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import logging

from django.conf import settings
from django.db.models.signals import post_save
from django.dispatch import receiver

Expand Down Expand Up @@ -126,6 +127,12 @@ def fire_ungenerated_certificate_task(user, course_key, expected_verification_st
CourseMode.PROFESSIONAL,
CourseMode.NO_ID_PROFESSIONAL_MODE,
]
if settings.FEATURES.get('TAHOE_AUTO_GENERATE_HONOR_CERTS', False):
# Appsembler change: allow for Honor mode
allowed_enrollment_modes_list += [
CourseMode.HONOR
]

enrollment_mode, __ = CourseEnrollment.enrollment_mode_for_user(user, course_key)
cert = GeneratedCertificate.certificate_for_student(user, course_key)

Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/certificates/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import ddt
import mock

from django.conf import settings

from lms.djangoapps.certificates import api as certs_api
from lms.djangoapps.certificates.models import (
CertificateGenerationConfiguration,
Expand Down Expand Up @@ -311,9 +313,10 @@ def setUp(self):
('no-id-professional', True),
('credit', True),
('audit', False),
('honor', False),
('honor', True), # TAHOE_AUTO_GENERATE_HONOR_CERTS feature: allows for honor
)
@ddt.unpack
@mock.patch.dict(settings.FEATURES, {'TAHOE_AUTO_GENERATE_HONOR_CERTS': True})
def test_fire_ungenerated_certificate_task_allowed_modes(self, enrollment_mode, should_create):
"""
Test that certificate generation task is fired for only modes that are
Expand Down
1 change: 1 addition & 0 deletions lms/djangoapps/static_template_view/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
url(r'^500$', views.render_500, name='static_template_view.views.render_500'),

url(r'^blog$', views.render, {'template': 'blog.html'}, name="blog"),
url(r'^tracks$', views.render, {'template': 'tracks.html'}, name="tracks"),
url(r'^contact$', views.render, {'template': 'contact.html'}, name="contact"),
url(r'^donate$', views.render, {'template': 'donate.html'}, name="donate"),
url(r'^faq$', views.render, {'template': 'faq.html'}, name="faq"),
Expand Down
16 changes: 16 additions & 0 deletions lms/templates/static_templates/tracks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<%page expression_filter="h"/>
<%! from django.utils.translation import ugettext as _ %>
<%inherit file="../main.html" />

<%block name="pagetitle">${_("Tracks")}</%block>

<main id="main" aria-label="Content" tabindex="-1">
<section class="container tracks">
<h1>
<%block name="pageheader">${page_header or _("Tracks")}</%block>
</h1>
<p>
<%block name="pagecontent">${page_content or _("This page left intentionally blank. Feel free to add your own content.")}</%block>
</p>
</section>
</main>
2 changes: 2 additions & 0 deletions openedx/core/djangoapps/appsembler/api/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import datetime

import factory
import factory.fuzzy

from openedx.core.djangoapps.content.course_overviews.models import (
CourseOverview,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ def plugin_settings(settings):
settings.CUSTOM_DOMAINS_REDIRECT_CACHE_KEY_PREFIX = 'custom_domains_redirects'

settings.COPY_SEGMENT_EVENT_PROPERTIES_TO_TOP_LEVEL = False

# Appsembler allows generating honor certs
settings.FEATURES['TAHOE_AUTO_GENERATE_HONOR_CERTS'] = True
72 changes: 70 additions & 2 deletions openedx/core/djangoapps/appsembler/sites/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from django.test import TestCase
import unittest
from mock import patch

from openedx.core.djangoapps.appsembler.sites.utils import get_initial_page_elements
from django.core.exceptions import ImproperlyConfigured, MultipleObjectsReturned
from django.test import TestCase, override_settings
from django.test.client import RequestFactory

from openedx.core.djangoapps.appsembler.api.tests.factories import OrganizationFactory
from openedx.core.djangoapps.appsembler.sites.utils import get_current_organization, get_initial_page_elements
from openedx.core.djangoapps.site_configuration.tests.factories import SiteFactory
from organizations.models import Organization


class JSONMigrationUtilsTestCase(TestCase):
Expand All @@ -14,3 +22,63 @@ def test_initial_page_elements(self):
self.assertEqual(element['options']['text-content'], {
'en': 'Welcome to your Tahoe trial LMS site!',
})


class OrganizationByRequestTestCase(TestCase):
def setUp(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryanlandia Is it intended that two orgs map to one site and one site is not supposed to have any orgs? If so, it would be really helpful to document what the expectations are for these tests, especially given the state of "M:M sites and orgs yes or no conversation and practice. cc @OmarIthawi @melvinsoft

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnbaldwin the original pull request that made this change is #785. We have another related pull request appsembler/edx-organizations#11 . Please add your feedback there.

As for this pull request it'll get whatever there's in appsembler/tahoe/develop let it merged into main.

super(OrganizationByRequestTestCase, self).setUp()
self.siteFoo = SiteFactory.create(domain='foo.dev', name='foo.dev')
self.siteBar = SiteFactory.create(domain='bar.dev', name='bar.dev')
self.siteBaz = SiteFactory.create(domain='baz.dev', name='baz.dev')
self.organizationA = OrganizationFactory(sites=[self.siteFoo])
self.organizationB = OrganizationFactory(sites=[self.siteFoo])
self.organizationC = OrganizationFactory(sites=[self.siteBar])
self.request = RequestFactory().post('dummy_url')
self.request.session = {}
for patch_req in (
'openedx.core.djangoapps.appsembler.sites.utils.get_current_request',
'openedx.core.djangoapps.theming.helpers.get_current_request'
):
patcher = patch(patch_req)
patched_req = patcher.start()
patched_req.return_value = self.request
self.addCleanup(patcher.stop)

@unittest.skip
def test_amc_admin_user_no_org_in_request(self):
# TODO: would be good to test
pass

@patch.dict('django.conf.settings.FEATURES', {'TAHOE_ENABLE_MULTI_ORGS_PER_SITE': False})
def test_single_organization_multiorg_feature_off(self):
self.request.site = self.siteBar
current_org = get_current_organization()
self.assertEqual(current_org, self.organizationC)

@patch.dict('django.conf.settings.FEATURES', {'TAHOE_ENABLE_MULTI_ORGS_PER_SITE': False})
def test_multiple_organization_multiorg_feature_off(self):
self.request.site = self.siteFoo
# fail raising exception if more than one org found for site when feature not enabled
with self.assertRaises(MultipleObjectsReturned):
get_current_organization()

@patch.dict('django.conf.settings.FEATURES', {'TAHOE_ENABLE_MULTI_ORGS_PER_SITE': True})
def test_multiple_organizations_multiorg_feature_on(self):
self.request.site = self.siteFoo
# return one org from Site's org relations
current_org = get_current_organization()
self.assertIn(current_org, (self.organizationA, self.organizationB))

def test_no_org_for_site(self):
self.request.site = self.siteBaz
with self.assertRaises(Organization.DoesNotExist):
get_current_organization()

@patch.dict('django.conf.settings.FEATURES', {
'TAHOE_ENABLE_MULTI_ORGS_PER_SITE': True,
'APPSEMBLER_MULTI_TENANT_EMAILS': True
})
def test_raises_if_multiorg_feature_and_multitenant_email_feature_on(self):
self.request.site = self.siteFoo
with self.assertRaises(ImproperlyConfigured):
get_current_organization()
21 changes: 17 additions & 4 deletions openedx/core/djangoapps/appsembler/sites/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core.exceptions import ImproperlyConfigured
from django.db.models.query import Q
from provider.oauth2.models import AccessToken, RefreshToken, Client
from django.utils.text import slugify
Expand Down Expand Up @@ -275,10 +276,22 @@ def get_current_organization(failure_return_none=False):
)
else:
try:
# TODO: Using `get` is expected to fail when multiple-orgs found for a site.
# Maybe catch MultipleObjectsReturned?
current_org = current_site.organizations.get()
except Organization.DoesNotExist:
if settings.FEATURES.get('TAHOE_ENABLE_MULTI_ORGS_PER_SITE', False):
if settings.FEATURES.get('APPSEMBLER_MULTI_TENANT_EMAILS', False):
raise ImproperlyConfigured(
'TAHOE_ENABLE_MULTI_ORGS_PER_SITE and '
'APPSEMBLER_MULTI_TENANT_EMAILS are incompatible as '
'we are not able to determine the exact Org when more than one '
'is associated with a Site.')
current_org = current_site.organizations.first()
if not current_org:
raise Organization.DoesNotExist(
'TAHOE_ENABLE_MULTI_ORGS_PER_SITE: Could not find current '
'organization for site `{}`'.format(repr(current_site))
)
else:
current_org = current_site.organizations.get()
except (Organization.DoesNotExist, ImproperlyConfigured):
if not failure_return_none:
raise # Re-raise the exception
else:
Expand Down