platform-plugin-aspects 1.0.2__tar.gz → 1.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {platform_plugin_aspects-1.0.2/platform_plugin_aspects.egg-info → platform_plugin_aspects-1.1.0}/PKG-INFO +2 -1
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/__init__.py +1 -1
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/extensions/filters.py +6 -15
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/settings/common.py +37 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/settings/production.py +4 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/urls.py +10 -1
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/utils.py +51 -0
- platform_plugin_aspects-1.1.0/platform_plugin_aspects/views.py +243 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0/platform_plugin_aspects.egg-info}/PKG-INFO +2 -1
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects.egg-info/requires.txt +1 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/requirements/base.in +1 -0
- platform_plugin_aspects-1.0.2/platform_plugin_aspects/views.py +0 -124
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/LICENSE +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/MANIFEST.in +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/README.rst +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/apps.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/extensions/__init__.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/management/__init__.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/management/commands/__init__.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/management/commands/dump_data_to_clickhouse.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/management/commands/load_test_tracking_events.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/management/commands/monitor_load_test_tracking.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/settings/__init__.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/signals.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/__init__.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/base_sink.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/course_enrollment_sink.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/course_overview_sink.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/external_id_sink.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/serializers.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/tag_sink.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/user_profile_sink.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/sinks/user_retire_sink.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/static/css/superset.css +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/static/html/superset.html +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/static/html/superset_student.html +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/static/js/embed_dashboard.js +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/static/js/install_required.js +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/static/js/superset.js +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/tasks.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/templates/instructor_dashboard/aspects.html +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/waffle.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/xblock.py +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects.egg-info/SOURCES.txt +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects.egg-info/dependency_links.txt +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects.egg-info/entry_points.txt +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects.egg-info/not-zip-safe +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects.egg-info/top_level.txt +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/requirements/constraints.txt +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/setup.cfg +0 -0
- {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: platform-plugin-aspects
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Aspects plugins for edx-platform
|
|
5
5
|
Home-page: https://github.com/openedx/platform-plugin-aspects
|
|
6
6
|
Author: Open edX Project
|
|
@@ -29,6 +29,7 @@ Requires-Dist: edx-opaque-keys
|
|
|
29
29
|
Requires-Dist: edx-toggles
|
|
30
30
|
Requires-Dist: openedx-atlas
|
|
31
31
|
Requires-Dist: openedx-filters
|
|
32
|
+
Requires-Dist: prison
|
|
32
33
|
Requires-Dist: redis
|
|
33
34
|
Requires-Dist: requests
|
|
34
35
|
Requires-Dist: superset-api-client
|
|
@@ -10,7 +10,11 @@ from django.template import Context, Template
|
|
|
10
10
|
from openedx_filters import PipelineStep
|
|
11
11
|
from web_fragments.fragment import Fragment
|
|
12
12
|
|
|
13
|
-
from platform_plugin_aspects.utils import
|
|
13
|
+
from platform_plugin_aspects.utils import (
|
|
14
|
+
_,
|
|
15
|
+
generate_superset_context,
|
|
16
|
+
get_user_dashboard_locale,
|
|
17
|
+
)
|
|
14
18
|
|
|
15
19
|
TEMPLATE_ABSOLUTE_PATH = "/instructor_dashboard/"
|
|
16
20
|
BLOCK_CATEGORY = "aspects"
|
|
@@ -34,20 +38,7 @@ class AddSupersetTab(PipelineStep):
|
|
|
34
38
|
show_dashboard_link = settings.SUPERSET_SHOW_INSTRUCTOR_DASHBOARD_LINK
|
|
35
39
|
|
|
36
40
|
user = get_current_user()
|
|
37
|
-
|
|
38
|
-
try:
|
|
39
|
-
user_language = (
|
|
40
|
-
get_model("user_preference").get_value(user, "pref-lang") or "en"
|
|
41
|
-
)
|
|
42
|
-
# If there is no user_preferences model defined this will get thrown
|
|
43
|
-
except AttributeError:
|
|
44
|
-
user_language = "en"
|
|
45
|
-
|
|
46
|
-
formatted_language = user_language.lower().replace("-", "_")
|
|
47
|
-
if formatted_language not in [
|
|
48
|
-
loc.lower().replace("-", "_") for loc in settings.SUPERSET_DASHBOARD_LOCALES
|
|
49
|
-
]:
|
|
50
|
-
formatted_language = "en"
|
|
41
|
+
formatted_language = get_user_dashboard_locale(user)
|
|
51
42
|
|
|
52
43
|
context["course_id"] = course.id
|
|
53
44
|
context = generate_superset_context(
|
|
@@ -104,3 +104,40 @@ def plugin_settings(settings):
|
|
|
104
104
|
"model": "ObjectTag",
|
|
105
105
|
},
|
|
106
106
|
}
|
|
107
|
+
|
|
108
|
+
settings.ASPECTS_IN_CONTEXT_DASHBOARDS = {
|
|
109
|
+
"course": {
|
|
110
|
+
"name": _("Course"),
|
|
111
|
+
"slug": "in-context-course",
|
|
112
|
+
"uuid": "f2880cc1-63e9-48d7-ac3c-d2ff6f6698e2",
|
|
113
|
+
"allow_translations": True,
|
|
114
|
+
"course_filter_ids": ["NATIVE_FILTER-QLQbulmHH"],
|
|
115
|
+
"block_filter_ids": [],
|
|
116
|
+
},
|
|
117
|
+
"sequential": {
|
|
118
|
+
"name": _("Graded Subsection"),
|
|
119
|
+
"slug": "in-context-graded-subsection",
|
|
120
|
+
"uuid": "f0321087-6428-4b97-b32e-2dae7d9cc447",
|
|
121
|
+
"allow_translations": True,
|
|
122
|
+
"course_filter_ids": ["NATIVE_FILTER-oPAuR7ahy"],
|
|
123
|
+
"block_filter_ids": ["NATIVE_FILTER-CBWbI7uLq"],
|
|
124
|
+
},
|
|
125
|
+
"problem": {
|
|
126
|
+
"name": _("Problem"),
|
|
127
|
+
"slug": "in-context-problem",
|
|
128
|
+
"uuid": "98ff33ff-18dd-48f9-8c58-629ae4f4194b",
|
|
129
|
+
"allow_translations": True,
|
|
130
|
+
"course_filter_ids": ["NATIVE_FILTER-29CPcbirK"],
|
|
131
|
+
"block_filter_ids": ["NATIVE_FILTER-TJwItQhUI"],
|
|
132
|
+
},
|
|
133
|
+
"video": {
|
|
134
|
+
"name": _("Video"),
|
|
135
|
+
"slug": "in-context-video",
|
|
136
|
+
"uuid": "bc6510fb-027f-4026-a333-d0c42d3cc35c",
|
|
137
|
+
"allow_translations": True,
|
|
138
|
+
"course_filter_ids": ["NATIVE_FILTER-uaxvZkSAg"],
|
|
139
|
+
"block_filter_ids": ["NATIVE_FILTER-Fse4rzDW0"],
|
|
140
|
+
},
|
|
141
|
+
}
|
|
142
|
+
settings.IN_CONTEXT_DASHBOARD_COURSE_KEY_COLUMN = "course_key"
|
|
143
|
+
settings.IN_CONTEXT_DASHBOARD_BLOCK_ID_COLUMN = "block_id"
|
|
@@ -28,3 +28,7 @@ def plugin_settings(settings):
|
|
|
28
28
|
"EVENT_SINK_CLICKHOUSE_PII_MODELS",
|
|
29
29
|
settings.EVENT_SINK_CLICKHOUSE_PII_MODELS,
|
|
30
30
|
)
|
|
31
|
+
settings.ASPECTS_IN_CONTEXT_DASHBOARDS = settings.ENV_TOKENS.get(
|
|
32
|
+
"ASPECTS_IN_CONTEXT_DASHBOARDS",
|
|
33
|
+
settings.ASPECTS_IN_CONTEXT_DASHBOARDS,
|
|
34
|
+
)
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/urls.py
RENAMED
|
@@ -8,14 +8,23 @@ from . import views
|
|
|
8
8
|
|
|
9
9
|
# Copied from openedx.core.constants
|
|
10
10
|
COURSE_ID_PATTERN = r"(?P<course_id>[^/+]+(/|\+)[^/+]+(/|\+)[^/?]+)"
|
|
11
|
+
# Copied from lms.envs.common
|
|
12
|
+
USAGE_ID_PATTERN = (
|
|
13
|
+
r"(?P<usage_id>(?:i4x://?[^/]+/[^/]+/[^/]+/[^@]+(?:@[^/]+)?)|(?:[^/]+))"
|
|
14
|
+
)
|
|
11
15
|
|
|
12
16
|
app_url_patterns = (
|
|
13
17
|
[
|
|
14
18
|
re_path(
|
|
15
19
|
rf"superset_guest_token/{COURSE_ID_PATTERN}/?$",
|
|
16
|
-
views.
|
|
20
|
+
views.SupersetTokenView.as_view(),
|
|
17
21
|
name="superset_guest_token",
|
|
18
22
|
),
|
|
23
|
+
re_path(
|
|
24
|
+
rf"superset_in_context_dashboard/{USAGE_ID_PATTERN}/?$",
|
|
25
|
+
views.SupersetInContextDashboardView.as_view(),
|
|
26
|
+
name="superset_in_context_dashboard",
|
|
27
|
+
),
|
|
19
28
|
],
|
|
20
29
|
"platform_plugin_aspects",
|
|
21
30
|
)
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/utils.py
RENAMED
|
@@ -37,6 +37,9 @@ DEFAULT_FILTERS_FORMAT = [
|
|
|
37
37
|
]
|
|
38
38
|
|
|
39
39
|
|
|
40
|
+
DEFAULT_USER_LANGUAGE = "en"
|
|
41
|
+
|
|
42
|
+
|
|
40
43
|
def generate_superset_context(
|
|
41
44
|
context,
|
|
42
45
|
dashboards,
|
|
@@ -309,3 +312,51 @@ def get_tags_for_block(usage_key) -> set:
|
|
|
309
312
|
tag = tag.parent
|
|
310
313
|
|
|
311
314
|
return list(serialized_tags)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
def get_user_dashboard_locale(user):
|
|
318
|
+
"""
|
|
319
|
+
|
|
320
|
+
Get the Superset dashboard locale from the user preference.
|
|
321
|
+
|
|
322
|
+
"""
|
|
323
|
+
try:
|
|
324
|
+
user_language = (
|
|
325
|
+
get_model("user_preference").get_value(user, "pref-lang")
|
|
326
|
+
or DEFAULT_USER_LANGUAGE
|
|
327
|
+
)
|
|
328
|
+
# If there is no user_preferences model defined this will get thrown
|
|
329
|
+
except AttributeError:
|
|
330
|
+
user_language = DEFAULT_USER_LANGUAGE
|
|
331
|
+
|
|
332
|
+
formatted_language = user_language.lower().replace("-", "_")
|
|
333
|
+
if formatted_language not in [
|
|
334
|
+
loc.lower().replace("-", "_") for loc in settings.SUPERSET_DASHBOARD_LOCALES
|
|
335
|
+
]:
|
|
336
|
+
formatted_language = DEFAULT_USER_LANGUAGE
|
|
337
|
+
|
|
338
|
+
return formatted_language
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def build_filter(filter_id, column, operator, value):
|
|
342
|
+
"""
|
|
343
|
+
|
|
344
|
+
Build a Superset native filter option.
|
|
345
|
+
|
|
346
|
+
"""
|
|
347
|
+
return {
|
|
348
|
+
"id": filter_id,
|
|
349
|
+
"extraFormData": {
|
|
350
|
+
"filters": [
|
|
351
|
+
{
|
|
352
|
+
"col": column,
|
|
353
|
+
"op": operator,
|
|
354
|
+
"val": value,
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
"filterState": {
|
|
359
|
+
"value": value,
|
|
360
|
+
},
|
|
361
|
+
"ownState": {},
|
|
362
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Endpoints for the Aspects platform plugin.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from collections import namedtuple
|
|
6
|
+
|
|
7
|
+
import prison
|
|
8
|
+
from django.conf import settings
|
|
9
|
+
from django.core.exceptions import ImproperlyConfigured
|
|
10
|
+
from opaque_keys import InvalidKeyError
|
|
11
|
+
from opaque_keys.edx.keys import CourseKey, UsageKey
|
|
12
|
+
from rest_framework import permissions
|
|
13
|
+
from rest_framework.authentication import SessionAuthentication
|
|
14
|
+
from rest_framework.exceptions import APIException, NotFound
|
|
15
|
+
from rest_framework.generics import GenericAPIView
|
|
16
|
+
from rest_framework.response import Response
|
|
17
|
+
|
|
18
|
+
from .utils import (
|
|
19
|
+
DEFAULT_FILTERS_FORMAT,
|
|
20
|
+
_,
|
|
21
|
+
build_filter,
|
|
22
|
+
generate_guest_token,
|
|
23
|
+
get_localized_uuid,
|
|
24
|
+
get_model,
|
|
25
|
+
get_user_dashboard_locale,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
from openedx.core.lib.api.permissions import (
|
|
30
|
+
IsCourseStaffInstructor,
|
|
31
|
+
IsStaffOrReadOnly,
|
|
32
|
+
)
|
|
33
|
+
except ImportError:
|
|
34
|
+
|
|
35
|
+
class IsCourseStaffInstructor(permissions.BasePermission):
|
|
36
|
+
"""
|
|
37
|
+
Permission class to use during tests.
|
|
38
|
+
|
|
39
|
+
Importing from edx-platform doesn't work when running tests,
|
|
40
|
+
so we declare our own permission class here.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def has_object_permission(self, request, view, obj):
|
|
44
|
+
"""
|
|
45
|
+
Return False for security; mock this out during tests.
|
|
46
|
+
"""
|
|
47
|
+
return False
|
|
48
|
+
|
|
49
|
+
class IsStaffOrReadOnly(permissions.BasePermission):
|
|
50
|
+
"""
|
|
51
|
+
Permission class to use during tests.
|
|
52
|
+
|
|
53
|
+
Importing from edx-platform doesn't work when running tests,
|
|
54
|
+
so we declare our own permission class here.
|
|
55
|
+
"""
|
|
56
|
+
|
|
57
|
+
def has_object_permission(self, request, view, obj):
|
|
58
|
+
"""
|
|
59
|
+
Return False for security; mock this out during tests.
|
|
60
|
+
"""
|
|
61
|
+
return False
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
# Course fields:
|
|
65
|
+
# * course_id: CourseKey; required by IsCourseStaffInstructor
|
|
66
|
+
# * display_name: str; optionally fetched from CourseOverview
|
|
67
|
+
Course = namedtuple("Course", ["course_id", "display_name"])
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _get_course(course_key):
|
|
71
|
+
"""
|
|
72
|
+
Return a Course-like object for the requested course id.
|
|
73
|
+
|
|
74
|
+
Raise NotFound if the corresponding course does not exist.
|
|
75
|
+
"""
|
|
76
|
+
# Fetch the CourseOverview (if we're running in edx-platform)
|
|
77
|
+
display_name = ""
|
|
78
|
+
CourseOverview = get_model("course_overviews")
|
|
79
|
+
if CourseOverview:
|
|
80
|
+
try:
|
|
81
|
+
course_overview = CourseOverview.objects.only("display_name").get(
|
|
82
|
+
id=course_key
|
|
83
|
+
)
|
|
84
|
+
display_name = course_overview.display_name
|
|
85
|
+
except CourseOverview.DoesNotExist as exc:
|
|
86
|
+
raise NotFound(
|
|
87
|
+
_("Course not found: '{course_id}'").format(course_id=course_key)
|
|
88
|
+
) from exc
|
|
89
|
+
return Course(course_id=course_key, display_name=display_name)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class SupersetTokenView(GenericAPIView):
|
|
93
|
+
"""
|
|
94
|
+
Superset guest token endpoint.
|
|
95
|
+
"""
|
|
96
|
+
|
|
97
|
+
authentication_classes = (SessionAuthentication,)
|
|
98
|
+
permission_classes = (
|
|
99
|
+
permissions.IsAuthenticated,
|
|
100
|
+
IsStaffOrReadOnly | IsCourseStaffInstructor,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
lookup_field = "course_id"
|
|
104
|
+
|
|
105
|
+
def get_object(self):
|
|
106
|
+
"""
|
|
107
|
+
Return a Course-like object for the requested course_id.
|
|
108
|
+
"""
|
|
109
|
+
course_id = self.kwargs.get(self.lookup_field, "")
|
|
110
|
+
try:
|
|
111
|
+
course_key = CourseKey.from_string(course_id)
|
|
112
|
+
except InvalidKeyError as exc:
|
|
113
|
+
raise NotFound(
|
|
114
|
+
_("Invalid course id: '{course_id}'").format(course_id=course_id)
|
|
115
|
+
) from exc
|
|
116
|
+
|
|
117
|
+
course = _get_course(course_key)
|
|
118
|
+
|
|
119
|
+
# May raise a permission denied
|
|
120
|
+
self.check_object_permissions(self.request, course)
|
|
121
|
+
|
|
122
|
+
return course_key
|
|
123
|
+
|
|
124
|
+
def get(self, request, *args, **kwargs):
|
|
125
|
+
"""
|
|
126
|
+
Return a guest token for accessing the Superset API.
|
|
127
|
+
"""
|
|
128
|
+
course = self.get_object()
|
|
129
|
+
|
|
130
|
+
dashboards = settings.ASPECTS_INSTRUCTOR_DASHBOARDS.copy()
|
|
131
|
+
dashboards.extend(settings.ASPECTS_IN_CONTEXT_DASHBOARDS.values())
|
|
132
|
+
extra_filters_format = settings.SUPERSET_EXTRA_FILTERS_FORMAT
|
|
133
|
+
|
|
134
|
+
try:
|
|
135
|
+
guest_token = generate_guest_token(
|
|
136
|
+
user=request.user,
|
|
137
|
+
course=course,
|
|
138
|
+
dashboards=dashboards,
|
|
139
|
+
filters=DEFAULT_FILTERS_FORMAT + extra_filters_format,
|
|
140
|
+
)
|
|
141
|
+
except ImproperlyConfigured as exc:
|
|
142
|
+
raise APIException() from exc
|
|
143
|
+
|
|
144
|
+
return Response({"guestToken": guest_token})
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class SupersetInContextDashboardView(GenericAPIView):
|
|
148
|
+
"""
|
|
149
|
+
Endpoint for in-context analytics embedded Superset dashboard parameters.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
authentication_classes = (SessionAuthentication,)
|
|
153
|
+
permission_classes = (
|
|
154
|
+
permissions.IsAuthenticated,
|
|
155
|
+
IsStaffOrReadOnly | IsCourseStaffInstructor,
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
lookup_field = "usage_id"
|
|
159
|
+
|
|
160
|
+
def get_object(self):
|
|
161
|
+
"""
|
|
162
|
+
Return a usage key or course key for the requested usage_key.
|
|
163
|
+
"""
|
|
164
|
+
usage_id = self.kwargs.get(self.lookup_field, "")
|
|
165
|
+
try:
|
|
166
|
+
usage_key = UsageKey.from_string(usage_id)
|
|
167
|
+
except InvalidKeyError as exc:
|
|
168
|
+
try:
|
|
169
|
+
course_key = usage_key = CourseKey.from_string(usage_id)
|
|
170
|
+
except InvalidKeyError:
|
|
171
|
+
raise NotFound(
|
|
172
|
+
_("Invalid usage id: '{usage_id}'").format(usage_id=usage_id)
|
|
173
|
+
) from exc
|
|
174
|
+
else:
|
|
175
|
+
course_key = usage_key.course_key
|
|
176
|
+
|
|
177
|
+
course = _get_course(course_key)
|
|
178
|
+
self.check_object_permissions(self.request, course)
|
|
179
|
+
|
|
180
|
+
return usage_key
|
|
181
|
+
|
|
182
|
+
def get(self, request, *args, **kwargs):
|
|
183
|
+
"""
|
|
184
|
+
Return Superset context for embedding the dashboard for the requested block.
|
|
185
|
+
"""
|
|
186
|
+
usage_key = self.get_object()
|
|
187
|
+
if isinstance(usage_key, CourseKey):
|
|
188
|
+
block_type = "course"
|
|
189
|
+
course_key = usage_key
|
|
190
|
+
else:
|
|
191
|
+
block_type = usage_key.block_type
|
|
192
|
+
course_key = usage_key.course_key
|
|
193
|
+
|
|
194
|
+
course_key_col = settings.IN_CONTEXT_DASHBOARD_COURSE_KEY_COLUMN
|
|
195
|
+
block_id_col = settings.IN_CONTEXT_DASHBOARD_BLOCK_ID_COLUMN
|
|
196
|
+
|
|
197
|
+
dashboards = settings.ASPECTS_IN_CONTEXT_DASHBOARDS
|
|
198
|
+
dashboard = dashboards.get(block_type)
|
|
199
|
+
if dashboard is None:
|
|
200
|
+
raise NotFound(
|
|
201
|
+
_("No dashboard for block type: '{block_type}'").format(
|
|
202
|
+
block_type=block_type
|
|
203
|
+
)
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
block_filter = {}
|
|
207
|
+
if not isinstance(usage_key, CourseKey):
|
|
208
|
+
for filter_id in dashboard["block_filter_ids"]:
|
|
209
|
+
block_filter[filter_id] = build_filter(
|
|
210
|
+
filter_id, block_id_col, "IN", [usage_key.block_id]
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
course_runs = {}
|
|
214
|
+
# In the future we might provide other course runs so that the
|
|
215
|
+
# embedding application can apply their corresponding filters
|
|
216
|
+
# instead of needing the Superset filter UI.
|
|
217
|
+
for course_run in [course_key.run]:
|
|
218
|
+
course_filter = block_filter.copy()
|
|
219
|
+
for filter_id in dashboard["course_filter_ids"]:
|
|
220
|
+
course_filter[filter_id] = build_filter(
|
|
221
|
+
filter_id, course_key_col, "IN", [str(course_key)]
|
|
222
|
+
)
|
|
223
|
+
course_runs[course_run] = {
|
|
224
|
+
# Superset filter URL parameter is encoded as Rison.
|
|
225
|
+
"native_filters": prison.dumps(course_filter),
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if dashboard.get("allow_translations"):
|
|
229
|
+
language = get_user_dashboard_locale(request.user)
|
|
230
|
+
dashboard = dashboard.copy()
|
|
231
|
+
dashboard["uuid"] = get_localized_uuid(dashboard["uuid"], language)
|
|
232
|
+
|
|
233
|
+
superset_config = settings.SUPERSET_CONFIG
|
|
234
|
+
superset_url = superset_config.get("service_url")
|
|
235
|
+
|
|
236
|
+
return Response(
|
|
237
|
+
{
|
|
238
|
+
"dashboardId": dashboard["uuid"],
|
|
239
|
+
"supersetUrl": superset_url,
|
|
240
|
+
"courseRuns": course_runs,
|
|
241
|
+
"defaultCourseRun": course_key.run,
|
|
242
|
+
}
|
|
243
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: platform-plugin-aspects
|
|
3
|
-
Version: 1.0
|
|
3
|
+
Version: 1.1.0
|
|
4
4
|
Summary: Aspects plugins for edx-platform
|
|
5
5
|
Home-page: https://github.com/openedx/platform-plugin-aspects
|
|
6
6
|
Author: Open edX Project
|
|
@@ -29,6 +29,7 @@ Requires-Dist: edx-opaque-keys
|
|
|
29
29
|
Requires-Dist: edx-toggles
|
|
30
30
|
Requires-Dist: openedx-atlas
|
|
31
31
|
Requires-Dist: openedx-filters
|
|
32
|
+
Requires-Dist: prison
|
|
32
33
|
Requires-Dist: redis
|
|
33
34
|
Requires-Dist: requests
|
|
34
35
|
Requires-Dist: superset-api-client
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Endpoints for the Aspects platform plugin.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from collections import namedtuple
|
|
6
|
-
|
|
7
|
-
from django.conf import settings
|
|
8
|
-
from django.core.exceptions import ImproperlyConfigured
|
|
9
|
-
from opaque_keys import InvalidKeyError
|
|
10
|
-
from opaque_keys.edx.keys import CourseKey
|
|
11
|
-
from rest_framework import permissions
|
|
12
|
-
from rest_framework.authentication import SessionAuthentication
|
|
13
|
-
from rest_framework.exceptions import APIException, NotFound
|
|
14
|
-
from rest_framework.generics import GenericAPIView
|
|
15
|
-
from rest_framework.response import Response
|
|
16
|
-
|
|
17
|
-
from .utils import DEFAULT_FILTERS_FORMAT, _, generate_guest_token, get_model
|
|
18
|
-
|
|
19
|
-
try:
|
|
20
|
-
from openedx.core.lib.api.permissions import (
|
|
21
|
-
IsCourseStaffInstructor,
|
|
22
|
-
IsStaffOrReadOnly,
|
|
23
|
-
)
|
|
24
|
-
except ImportError:
|
|
25
|
-
|
|
26
|
-
class IsCourseStaffInstructor(permissions.BasePermission):
|
|
27
|
-
"""
|
|
28
|
-
Permission class to use during tests.
|
|
29
|
-
|
|
30
|
-
Importing from edx-platform doesn't work when running tests,
|
|
31
|
-
so we declare our own permission class here.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
def has_object_permission(self, request, view, obj):
|
|
35
|
-
"""
|
|
36
|
-
Return False for security; mock this out during tests.
|
|
37
|
-
"""
|
|
38
|
-
return False
|
|
39
|
-
|
|
40
|
-
class IsStaffOrReadOnly(permissions.BasePermission):
|
|
41
|
-
"""
|
|
42
|
-
Permission class to use during tests.
|
|
43
|
-
|
|
44
|
-
Importing from edx-platform doesn't work when running tests,
|
|
45
|
-
so we declare our own permission class here.
|
|
46
|
-
"""
|
|
47
|
-
|
|
48
|
-
def has_object_permission(self, request, view, obj):
|
|
49
|
-
"""
|
|
50
|
-
Return False for security; mock this out during tests.
|
|
51
|
-
"""
|
|
52
|
-
return False
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
# Course fields:
|
|
56
|
-
# * course_id: CourseKey; required by IsCourseStaffInstructor
|
|
57
|
-
# * display_name: str; optionally fetched from CourseOverview
|
|
58
|
-
Course = namedtuple("Course", ["course_id", "display_name"])
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
class SupersetView(GenericAPIView):
|
|
62
|
-
"""
|
|
63
|
-
Superset-related endpoints provided by the aspects platform plugin.
|
|
64
|
-
"""
|
|
65
|
-
|
|
66
|
-
authentication_classes = (SessionAuthentication,)
|
|
67
|
-
permission_classes = (
|
|
68
|
-
permissions.IsAuthenticated,
|
|
69
|
-
IsStaffOrReadOnly | IsCourseStaffInstructor,
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
lookup_field = "course_id"
|
|
73
|
-
|
|
74
|
-
def get_object(self):
|
|
75
|
-
"""
|
|
76
|
-
Return a Course-like object for the requested course_id.
|
|
77
|
-
"""
|
|
78
|
-
course_id = self.kwargs.get(self.lookup_field, "")
|
|
79
|
-
try:
|
|
80
|
-
course_key = CourseKey.from_string(course_id)
|
|
81
|
-
except InvalidKeyError as exc:
|
|
82
|
-
raise NotFound(
|
|
83
|
-
_("Invalid course id: '{course_id}'").format(course_id=course_id)
|
|
84
|
-
) from exc
|
|
85
|
-
|
|
86
|
-
# Fetch the CourseOverview (if we're running in edx-platform)
|
|
87
|
-
display_name = ""
|
|
88
|
-
CourseOverview = get_model("course_overviews")
|
|
89
|
-
if CourseOverview:
|
|
90
|
-
try:
|
|
91
|
-
course_overview = CourseOverview.objects.get(id=course_key)
|
|
92
|
-
display_name = course_overview.display_name
|
|
93
|
-
except CourseOverview.DoesNotExist as exc:
|
|
94
|
-
raise NotFound(
|
|
95
|
-
_("Course not found: '{course_id}'").format(course_id=course_id)
|
|
96
|
-
) from exc
|
|
97
|
-
|
|
98
|
-
course = Course(course_id=course_key, display_name=display_name)
|
|
99
|
-
|
|
100
|
-
# May raise a permission denied
|
|
101
|
-
self.check_object_permissions(self.request, course)
|
|
102
|
-
|
|
103
|
-
return course_key
|
|
104
|
-
|
|
105
|
-
def get(self, request, *args, **kwargs):
|
|
106
|
-
"""
|
|
107
|
-
Return a guest token for accessing the Superset API.
|
|
108
|
-
"""
|
|
109
|
-
course = self.get_object()
|
|
110
|
-
|
|
111
|
-
dashboards = settings.ASPECTS_INSTRUCTOR_DASHBOARDS
|
|
112
|
-
extra_filters_format = settings.SUPERSET_EXTRA_FILTERS_FORMAT
|
|
113
|
-
|
|
114
|
-
try:
|
|
115
|
-
guest_token = generate_guest_token(
|
|
116
|
-
user=request.user,
|
|
117
|
-
course=course,
|
|
118
|
-
dashboards=dashboards,
|
|
119
|
-
filters=DEFAULT_FILTERS_FORMAT + extra_filters_format,
|
|
120
|
-
)
|
|
121
|
-
except ImproperlyConfigured as exc:
|
|
122
|
-
raise APIException() from exc
|
|
123
|
-
|
|
124
|
-
return Response({"guestToken": guest_token})
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/apps.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/signals.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/tasks.py
RENAMED
|
File without changes
|
|
File without changes
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/waffle.py
RENAMED
|
File without changes
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/platform_plugin_aspects/xblock.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.0}/requirements/constraints.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|