Merge pull request #19688 from edx/juliasq/remove_dop_from_notes

Read client ID/secret from DOT application instead of DOP client.
This commit is contained in:
Julia Eskew
2019-01-31 15:40:12 -05:00
committed by GitHub
5 changed files with 52 additions and 47 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,15 +1,18 @@
[
{
"pk": 1,
"model": "oauth2.client",
"model": "oauth2_provider.application",
"fields": {
"name": "edx-notes",
"url": "http://example.com/",
"client_type": 1,
"redirect_uri": "http://example.com/welcome",
"client_type": "confidential",
"user": null,
"client_id": "22a9e15e3d3b115e4d43",
"client_secret": "7969f769a1fe21ecd6cf8a1c105f250f70a27131"
"client_secret": "7969f769a1fe21ecd6cf8a1c105f250f70a27131",
"redirect_uris":"",
"authorization_grant_type":"client-credentials",
"skip_authorization":false,
"created":"2018-10-25T14:53:08.054Z",
"updated":"2018-10-25T14:53:08.054Z"
}
}
]

View File

@@ -16,7 +16,7 @@ from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse
from django.utils.translation import ugettext as _
from opaque_keys.edx.keys import UsageKey
from provider.oauth2.models import Client
from oauth2_provider.models import Application
from requests.exceptions import RequestException
from courseware.access import has_access
@@ -52,14 +52,15 @@ def get_edxnotes_id_token(user):
"""
Returns generated ID Token for edxnotes.
"""
# TODO: Use the system's JWT_AUDIENCE and JWT_SECRET_KEY instead of client ID and name.
try:
client = Client.objects.get(name=CLIENT_NAME)
except Client.DoesNotExist:
notes_application = Application.objects.get(name=CLIENT_NAME)
except Application.DoesNotExist:
raise ImproperlyConfigured(
'OAuth2 Client with name [{}] does not exist.'.format(CLIENT_NAME)
)
return create_jwt_for_user(user, secret=client.client_secret, aud=client.client_id)
return create_jwt_for_user(
user, secret=notes_application.client_secret, aud=notes_application.client_id
)
def get_token_url(course_id):
@@ -246,7 +247,7 @@ def get_module_context(course, item):
"""
item_dict = {
'location': unicode(item.location),
'display_name': item.display_name_with_default_escaped,
'display_name': item.display_name_with_default,
}
if item.category == 'chapter' and item.get_parent():
# course is a locator w/o branch and version
@@ -425,7 +426,7 @@ def get_course_position(course_module):
urlargs['chapter'] = chapter.url_name
if course_module.position is not None:
return {
'display_name': chapter.display_name_with_default_escaped,
'display_name': chapter.display_name_with_default,
'url': reverse('courseware_chapter', kwargs=urlargs),
}
@@ -437,7 +438,7 @@ def get_course_position(course_module):
urlargs['section'] = section.url_name
return {
'display_name': section.display_name_with_default_escaped,
'display_name': section.display_name_with_default,
'url': reverse('courseware_section', kwargs=urlargs)
}

View File

@@ -15,9 +15,8 @@ from django.core.exceptions import ImproperlyConfigured
from django.urls import reverse
from django.test.client import RequestFactory
from django.test.utils import override_settings
from edx_oauth2_provider.tests.factories import ClientFactory
from mock import MagicMock, patch
from provider.oauth2.models import Client
from oauth2_provider.models import Application
from courseware.model_data import FieldDataCache
from courseware.module_render import get_module_for_descriptor
@@ -28,6 +27,7 @@ from edxnotes.decorators import edxnotes
from edxnotes.exceptions import EdxNotesParseError, EdxNotesServiceUnavailable
from edxnotes.plugins import EdxNotesTab
from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user
from openedx.core.djangoapps.oauth_dispatch.tests.factories import ApplicationFactory
from openedx.core.djangoapps.user_api.models import RetirementState, UserRetirementStatus
from openedx.core.lib.tests import attr
from student.tests.factories import CourseEnrollmentFactory, SuperuserFactory, UserFactory
@@ -100,7 +100,7 @@ class EdxNotesDecoratorTest(ModuleStoreTestCase):
def setUp(self):
super(EdxNotesDecoratorTest, self).setUp()
ClientFactory(name="edx-notes")
ApplicationFactory(name="edx-notes")
# Using old mongo because of locator comparison issues (see longer
# note below in EdxNotesHelpersTest setUp.
self.course = CourseFactory(edxnotes=True, default_store=ModuleStoreEnum.Type.mongo)
@@ -204,7 +204,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
# comparison values do not. This needs further investigation in order to enable these tests
# with the split modulestore.
with self.store.default_store(ModuleStoreEnum.Type.mongo):
ClientFactory(name="edx-notes")
ApplicationFactory(name="edx-notes")
self.course = CourseFactory.create()
self.chapter = ItemFactory.create(category="chapter", parent_location=self.course.location)
self.chapter_2 = ItemFactory.create(category="chapter", parent_location=self.course.location)
@@ -347,13 +347,13 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u"quote": u"quote text",
u"text": u"text",
u"chapter": {
u"display_name": self.chapter.display_name_with_default_escaped,
u"display_name": self.chapter.display_name_with_default,
u"index": 0,
u"location": unicode(self.chapter.location),
u"children": [unicode(self.sequential.location)]
},
u"section": {
u"display_name": self.sequential.display_name_with_default_escaped,
u"display_name": self.sequential.display_name_with_default,
u"location": unicode(self.sequential.location),
u"children": [
unicode(self.vertical.location), unicode(self.vertical_with_container.location)
@@ -361,7 +361,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
},
u"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u"usage_id": unicode(self.html_module_2.location),
@@ -371,13 +371,13 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u"quote": u"quote text",
u"text": u"text",
u"chapter": {
u"display_name": self.chapter.display_name_with_default_escaped,
u"display_name": self.chapter.display_name_with_default,
u"index": 0,
u"location": unicode(self.chapter.location),
u"children": [unicode(self.sequential.location)]
},
u"section": {
u"display_name": self.sequential.display_name_with_default_escaped,
u"display_name": self.sequential.display_name_with_default,
u"location": unicode(self.sequential.location),
u"children": [
unicode(self.vertical.location),
@@ -385,7 +385,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
},
u"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u"usage_id": unicode(self.html_module_1.location),
@@ -453,13 +453,13 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u"quote": u"quote text",
u"text": u"text",
u"chapter": {
u"display_name": self.chapter.display_name_with_default_escaped,
u"display_name": self.chapter.display_name_with_default,
u"index": 0,
u"location": unicode(self.chapter.location),
u"children": [unicode(self.sequential.location)]
},
u"section": {
u"display_name": self.sequential.display_name_with_default_escaped,
u"display_name": self.sequential.display_name_with_default,
u"location": unicode(self.sequential.location),
u"children": [
unicode(self.vertical.location),
@@ -467,7 +467,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
},
u"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u"usage_id": unicode(self.html_module_2.location),
@@ -477,13 +477,13 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u"quote": u"quote text",
u"text": u"text",
u"chapter": {
u"display_name": self.chapter.display_name_with_default_escaped,
u"display_name": self.chapter.display_name_with_default,
u"index": 0,
u"location": unicode(self.chapter.location),
u"children": [unicode(self.sequential.location)]
},
u"section": {
u"display_name": self.sequential.display_name_with_default_escaped,
u"display_name": self.sequential.display_name_with_default,
u"location": unicode(self.sequential.location),
u"children": [
unicode(self.vertical.location),
@@ -491,7 +491,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
},
u"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u"usage_id": unicode(self.html_module_1.location),
@@ -576,19 +576,19 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u"quote": u"quote text",
u"text": u"text",
u"chapter": {
u"display_name": self.chapter.display_name_with_default_escaped,
u"display_name": self.chapter.display_name_with_default,
u"index": 0,
u"location": unicode(self.chapter.location),
u"children": [unicode(self.sequential.location)]
},
u"section": {
u"display_name": self.sequential.display_name_with_default_escaped,
u"display_name": self.sequential.display_name_with_default,
u"location": unicode(self.sequential.location),
u"children": [unicode(self.vertical.location), unicode(self.vertical_with_container.location)]
},
u"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u"usage_id": unicode(self.html_module_1.location),
@@ -622,19 +622,19 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
u"quote": u"quote text",
u"text": u"text",
u"chapter": {
u"display_name": self.chapter.display_name_with_default_escaped,
u"display_name": self.chapter.display_name_with_default,
u"index": 0,
u"location": unicode(self.chapter.location),
u"children": [unicode(self.sequential.location)]
},
u"section": {
u"display_name": self.sequential.display_name_with_default_escaped,
u"display_name": self.sequential.display_name_with_default,
u"location": unicode(self.sequential.location),
u"children": [unicode(self.vertical.location), unicode(self.vertical_with_container.location)]
},
u"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u"usage_id": unicode(self.html_module_1.location),
@@ -692,7 +692,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
'chapter': {},
"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u'text': u'text1',
@@ -705,7 +705,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
'chapter': {},
"unit": {
u"url": self._get_unit_url(self.course, self.chapter, self.sequential),
u"display_name": self.vertical.display_name_with_default_escaped,
u"display_name": self.vertical.display_name_with_default,
u"location": unicode(self.vertical.location),
},
u'text': u'text2',
@@ -723,7 +723,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
"""
self.assertDictEqual(
{
u"display_name": self.sequential.display_name_with_default_escaped,
u"display_name": self.sequential.display_name_with_default,
u"location": unicode(self.sequential.location),
u"children": [unicode(self.vertical.location), unicode(self.vertical_with_container.location)],
},
@@ -736,7 +736,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
"""
self.assertDictEqual(
{
u"display_name": self.html_module_1.display_name_with_default_escaped,
u"display_name": self.html_module_1.display_name_with_default,
u"location": unicode(self.html_module_1.location),
},
helpers.get_module_context(self.course, self.html_module_1)
@@ -748,7 +748,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
"""
self.assertDictEqual(
{
u"display_name": self.chapter.display_name_with_default_escaped,
u"display_name": self.chapter.display_name_with_default,
u"index": 0,
u"location": unicode(self.chapter.location),
u"children": [unicode(self.sequential.location)],
@@ -757,7 +757,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
)
self.assertDictEqual(
{
u"display_name": self.chapter_2.display_name_with_default_escaped,
u"display_name": self.chapter_2.display_name_with_default,
u"index": 1,
u"location": unicode(self.chapter_2.location),
u"children": [],
@@ -846,7 +846,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
mock_chapter = MagicMock()
mock_chapter.url_name = 'chapter_url_name'
mock_chapter.display_name_with_default_escaped = 'Test Chapter Display Name'
mock_chapter.display_name_with_default = 'Test Chapter Display Name'
mock_course_module.get_display_items.return_value = [mock_chapter]
@@ -876,7 +876,7 @@ class EdxNotesHelpersTest(ModuleStoreTestCase):
mock_section = MagicMock()
mock_section.url_name = 'section_url_name'
mock_section.display_name_with_default_escaped = 'Test Section Display Name'
mock_section.display_name_with_default = 'Test Section Display Name'
mock_chapter.get_display_items.return_value = [mock_section]
mock_section.get_display_items.return_value = [MagicMock()]
@@ -962,7 +962,7 @@ class EdxNotesViewsTest(ModuleStoreTestCase):
Tests for EdxNotes views.
"""
def setUp(self):
ClientFactory(name="edx-notes")
ApplicationFactory(name="edx-notes")
super(EdxNotesViewsTest, self).setUp()
self.course = CourseFactory(edxnotes=True)
self.user = UserFactory()
@@ -1089,7 +1089,7 @@ class EdxNotesViewsTest(ModuleStoreTestCase):
"""
response = self.client.get(self.get_token_url)
self.assertEqual(response.status_code, 200)
client = Client.objects.get(name='edx-notes')
client = Application.objects.get(name='edx-notes')
jwt.decode(response.content, client.client_secret, audience=client.client_id)
@patch.dict("django.conf.settings.FEATURES", {"ENABLE_EDXNOTES": True})
@@ -1156,7 +1156,7 @@ class EdxNotesRetireAPITest(ModuleStoreTestCase):
Tests for EdxNotes retirement API.
"""
def setUp(self):
ClientFactory(name="edx-notes")
ApplicationFactory(name="edx-notes")
super(EdxNotesRetireAPITest, self).setUp()
# setup relevant states

View File

@@ -23,6 +23,7 @@ class ApplicationFactory(DjangoModelFactory):
client_secret = 'some_secret'
client_type = 'confidential'
authorization_grant_type = 'Client credentials'
name = FuzzyText(prefix='name', length=8)
class ApplicationAccessFactory(DjangoModelFactory):