platform-plugin-aspects 1.0.2__tar.gz → 1.1.1__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.
Files changed (51) hide show
  1. {platform_plugin_aspects-1.0.2/platform_plugin_aspects.egg-info → platform_plugin_aspects-1.1.1}/PKG-INFO +55 -18
  2. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/README.rst +53 -17
  3. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/__init__.py +1 -1
  4. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/extensions/filters.py +6 -15
  5. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/settings/common.py +41 -0
  6. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/settings/production.py +8 -0
  7. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/urls.py +10 -1
  8. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/utils.py +66 -18
  9. platform_plugin_aspects-1.1.1/platform_plugin_aspects/views.py +250 -0
  10. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1/platform_plugin_aspects.egg-info}/PKG-INFO +55 -18
  11. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects.egg-info/requires.txt +1 -0
  12. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/requirements/base.in +1 -0
  13. platform_plugin_aspects-1.0.2/platform_plugin_aspects/views.py +0 -124
  14. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/LICENSE +0 -0
  15. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/MANIFEST.in +0 -0
  16. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/apps.py +0 -0
  17. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/extensions/__init__.py +0 -0
  18. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/management/__init__.py +0 -0
  19. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/management/commands/__init__.py +0 -0
  20. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/management/commands/dump_data_to_clickhouse.py +0 -0
  21. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/management/commands/load_test_tracking_events.py +0 -0
  22. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/management/commands/monitor_load_test_tracking.py +0 -0
  23. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/settings/__init__.py +0 -0
  24. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/signals.py +0 -0
  25. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/__init__.py +0 -0
  26. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/base_sink.py +0 -0
  27. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/course_enrollment_sink.py +0 -0
  28. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/course_overview_sink.py +0 -0
  29. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/external_id_sink.py +0 -0
  30. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/serializers.py +0 -0
  31. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/tag_sink.py +0 -0
  32. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/user_profile_sink.py +0 -0
  33. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/sinks/user_retire_sink.py +0 -0
  34. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/static/css/superset.css +0 -0
  35. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/static/html/superset.html +0 -0
  36. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/static/html/superset_student.html +0 -0
  37. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/static/js/embed_dashboard.js +0 -0
  38. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/static/js/install_required.js +0 -0
  39. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/static/js/superset.js +0 -0
  40. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/tasks.py +0 -0
  41. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/templates/instructor_dashboard/aspects.html +0 -0
  42. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/waffle.py +0 -0
  43. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects/xblock.py +0 -0
  44. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects.egg-info/SOURCES.txt +0 -0
  45. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects.egg-info/dependency_links.txt +0 -0
  46. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects.egg-info/entry_points.txt +0 -0
  47. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects.egg-info/not-zip-safe +0 -0
  48. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/platform_plugin_aspects.egg-info/top_level.txt +0 -0
  49. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/requirements/constraints.txt +0 -0
  50. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/setup.cfg +0 -0
  51. {platform_plugin_aspects-1.0.2 → platform_plugin_aspects-1.1.1}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: platform-plugin-aspects
3
- Version: 1.0.2
3
+ Version: 1.1.1
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
@@ -58,8 +59,8 @@ dashboards back into the platform.
58
59
  Version Compatibility
59
60
  *********************
60
61
 
61
- `platform-plugin-aspects` version 1.x: Nutmeg to Sumac
62
- `platform-plugin-aspects` version 2.x: Redwood and above
62
+ - ``platform-plugin-aspects`` version 1.x: Nutmeg to Sumac
63
+ - ``platform-plugin-aspects`` version 2.x: Redwood (with in-context metrics turned off), or Sumac and above
63
64
 
64
65
  Sinks
65
66
  *****
@@ -70,16 +71,21 @@ events are emitted by the Open edX platform via `Open edX events`_ or Django sig
70
71
  Available Sinks
71
72
  ===============
72
73
 
73
- - `CourseOverviewSink` - Listens for the `COURSE_PUBLISHED` event and stores the
74
- course structure data through `XBlockSink` in ClickHouse.
75
- - `ExternalIdSink` - Listens for the `post_save` Django signal on the `ExternalId`
76
- model and stores the external id data in ClickHouse.
77
- - `UserProfile` - Listens for the `post_save` Django signal on the `UserProfile`
78
- model and stores the user profile data in ClickHouse.
79
- - `UserRetirementSink` - Listen for the `USER_RETIRE_LMS_MISC` Django signal and
80
- remove the user PII information from ClickHouse.
81
- - `CourseEnrollmentSink` - Listen for the `ENROLL_STATUS_CHANGE` event and stores
82
- the course enrollment data.
74
+ Below are the existing sink names, and their corresponding object names (as needed for the
75
+ ``dump_data_to_clickhouse`` command below.
76
+
77
+ - ``CourseOverviewSink`` - Listens for the `COURSE_PUBLISHED` event and stores the
78
+ course structure including ordering data through `XBlockSink` in ClickHouse. Object name:
79
+ ``course_overviews``
80
+ - ``ExternalIdSink`` - Listens for the `post_save` Django signal on the `ExternalId`
81
+ model and stores the external id data in ClickHouse. This model stores the relationships
82
+ between users and their xAPI unique identifiers. Object name: ``external_id``
83
+ - ``UserProfile`` - Listens for the `post_save` Django signal on the ``UserProfile``
84
+ model and stores the user profile data in ClickHouse. Object name: ``user_profile``
85
+ - ``CourseEnrollmentSink`` - Listen for the `ENROLL_STATUS_CHANGE` event and stores
86
+ the course enrollment data. Object name: ``course_enrollment``
87
+ - ``UserRetirementSink`` - Listen for the `USER_RETIRE_LMS_MISC` Django signal and
88
+ remove the user PII information from ClickHouse. This is a special sink and has no object name.
83
89
 
84
90
  Commands
85
91
  ========
@@ -87,9 +93,34 @@ Commands
87
93
  In addition to being an event listener, this package provides the following commands:
88
94
 
89
95
  - `dump_data_to_clickhouse` - This command allows bulk export of the data from the Sinks.
90
- Allows bootstrapping a new data platform or backfilling lost or missing data. More information can be found in the `Aspects backfill documentation`_.
96
+ Allows bootstrapping a new data platform or backfilling lost or missing data. Each sink object
97
+ is dumped individually. For large dumps you can use the --batch_size and --sleep_time to control
98
+ how much load is placed on your LMS / Studio servers. Examples:
91
99
 
92
- ``python manage.py cms dump_data_to_clickhouse``
100
+ Dump any courses that the systems thinks are out of date (last publish time is newer than the
101
+ last dump time in ClickHouse):
102
+
103
+ ``python manage.py cms dump_data_to_clickhouse --object course_overviews``
104
+
105
+ The ``force`` option willl dump all objects, regardless of the data ClickHouse currently has
106
+ so this command will push all course data for all courses:
107
+
108
+ ``python manage.py cms dump_data_to_clickhouse --object course_overviews --force``
109
+
110
+ These commands will dump the user data Aspects uses when PII is turned on:
111
+
112
+ ``python manage.py cms dump_data_to_clickhouse --object external_id``
113
+ ``python manage.py cms dump_data_to_clickhouse --object user_profile``
114
+
115
+ To reduce server load, this command will dump 1000 user profiles at a time, with a 5 second
116
+ sleep in between:
117
+
118
+ ``python manage.py cms dump_data_to_clickhouse --object user_profile --batch_size 1000 --sleep_time 5``
119
+
120
+ There are many more options that can be used for different circumstances. Please refer to
121
+ the commands help for more information. There is also a Tutor command that wraps this, so
122
+ that you don't need to get shell on a container to execute this command. More information on
123
+ that can be found in the `Aspects backfill documentation`_.
93
124
 
94
125
  - `load_test_tracking_events` - This command allows loading test tracking events into
95
126
  ClickHouse. This is useful for testing the ClickHouse connection to measure the performance of the
@@ -173,6 +204,14 @@ superset pipeline into the filter as follows:
173
204
  - `SUPERSET_DASHBOARD_LOCALES` - This setting is used to configure the available locales
174
205
  for the dashboards. The configuration is a list of supported locales by `Aspects`_.
175
206
 
207
+ - `ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS` - This setting turns on and off the in-context
208
+ metrics feature. It must be turned off in Open edX releases before Sumac and when using
209
+ tutor-contrib-aspects before v2.2.0 as those dashboards will not exist, causing errors in
210
+ the embedded Instructor Dashboards.
211
+
212
+ - `ASPECTS_IN_CONTEXT_DASHBOARDS` - This setting mirrors the `ASPECTS_INSTRUCTOR_DASHBOARDS` but
213
+ with additional keys used for filtering the boards to specific courses and blocks.
214
+
176
215
  Event Sink Configuration
177
216
  ========================
178
217
 
@@ -208,12 +247,10 @@ Getting Help
208
247
  Documentation
209
248
  =============
210
249
 
211
- PLACEHOLDER: Start by going through `the documentation`_. If you need more help see below.
250
+ Start by going through `the documentation`_. If you need more help see below.
212
251
 
213
252
  .. _the documentation: https://docs.openedx.org/projects/platform-plugin-aspects
214
253
 
215
- (TODO: `Set up documentation <https://openedx.atlassian.net/wiki/spaces/DOC/pages/21627535/Publish+Documentation+on+Read+the+Docs>`_)
216
-
217
254
  More Help
218
255
  =========
219
256
 
@@ -11,8 +11,8 @@ dashboards back into the platform.
11
11
  Version Compatibility
12
12
  *********************
13
13
 
14
- `platform-plugin-aspects` version 1.x: Nutmeg to Sumac
15
- `platform-plugin-aspects` version 2.x: Redwood and above
14
+ - ``platform-plugin-aspects`` version 1.x: Nutmeg to Sumac
15
+ - ``platform-plugin-aspects`` version 2.x: Redwood (with in-context metrics turned off), or Sumac and above
16
16
 
17
17
  Sinks
18
18
  *****
@@ -23,16 +23,21 @@ events are emitted by the Open edX platform via `Open edX events`_ or Django sig
23
23
  Available Sinks
24
24
  ===============
25
25
 
26
- - `CourseOverviewSink` - Listens for the `COURSE_PUBLISHED` event and stores the
27
- course structure data through `XBlockSink` in ClickHouse.
28
- - `ExternalIdSink` - Listens for the `post_save` Django signal on the `ExternalId`
29
- model and stores the external id data in ClickHouse.
30
- - `UserProfile` - Listens for the `post_save` Django signal on the `UserProfile`
31
- model and stores the user profile data in ClickHouse.
32
- - `UserRetirementSink` - Listen for the `USER_RETIRE_LMS_MISC` Django signal and
33
- remove the user PII information from ClickHouse.
34
- - `CourseEnrollmentSink` - Listen for the `ENROLL_STATUS_CHANGE` event and stores
35
- the course enrollment data.
26
+ Below are the existing sink names, and their corresponding object names (as needed for the
27
+ ``dump_data_to_clickhouse`` command below.
28
+
29
+ - ``CourseOverviewSink`` - Listens for the `COURSE_PUBLISHED` event and stores the
30
+ course structure including ordering data through `XBlockSink` in ClickHouse. Object name:
31
+ ``course_overviews``
32
+ - ``ExternalIdSink`` - Listens for the `post_save` Django signal on the `ExternalId`
33
+ model and stores the external id data in ClickHouse. This model stores the relationships
34
+ between users and their xAPI unique identifiers. Object name: ``external_id``
35
+ - ``UserProfile`` - Listens for the `post_save` Django signal on the ``UserProfile``
36
+ model and stores the user profile data in ClickHouse. Object name: ``user_profile``
37
+ - ``CourseEnrollmentSink`` - Listen for the `ENROLL_STATUS_CHANGE` event and stores
38
+ the course enrollment data. Object name: ``course_enrollment``
39
+ - ``UserRetirementSink`` - Listen for the `USER_RETIRE_LMS_MISC` Django signal and
40
+ remove the user PII information from ClickHouse. This is a special sink and has no object name.
36
41
 
37
42
  Commands
38
43
  ========
@@ -40,9 +45,34 @@ Commands
40
45
  In addition to being an event listener, this package provides the following commands:
41
46
 
42
47
  - `dump_data_to_clickhouse` - This command allows bulk export of the data from the Sinks.
43
- Allows bootstrapping a new data platform or backfilling lost or missing data. More information can be found in the `Aspects backfill documentation`_.
48
+ Allows bootstrapping a new data platform or backfilling lost or missing data. Each sink object
49
+ is dumped individually. For large dumps you can use the --batch_size and --sleep_time to control
50
+ how much load is placed on your LMS / Studio servers. Examples:
44
51
 
45
- ``python manage.py cms dump_data_to_clickhouse``
52
+ Dump any courses that the systems thinks are out of date (last publish time is newer than the
53
+ last dump time in ClickHouse):
54
+
55
+ ``python manage.py cms dump_data_to_clickhouse --object course_overviews``
56
+
57
+ The ``force`` option willl dump all objects, regardless of the data ClickHouse currently has
58
+ so this command will push all course data for all courses:
59
+
60
+ ``python manage.py cms dump_data_to_clickhouse --object course_overviews --force``
61
+
62
+ These commands will dump the user data Aspects uses when PII is turned on:
63
+
64
+ ``python manage.py cms dump_data_to_clickhouse --object external_id``
65
+ ``python manage.py cms dump_data_to_clickhouse --object user_profile``
66
+
67
+ To reduce server load, this command will dump 1000 user profiles at a time, with a 5 second
68
+ sleep in between:
69
+
70
+ ``python manage.py cms dump_data_to_clickhouse --object user_profile --batch_size 1000 --sleep_time 5``
71
+
72
+ There are many more options that can be used for different circumstances. Please refer to
73
+ the commands help for more information. There is also a Tutor command that wraps this, so
74
+ that you don't need to get shell on a container to execute this command. More information on
75
+ that can be found in the `Aspects backfill documentation`_.
46
76
 
47
77
  - `load_test_tracking_events` - This command allows loading test tracking events into
48
78
  ClickHouse. This is useful for testing the ClickHouse connection to measure the performance of the
@@ -126,6 +156,14 @@ superset pipeline into the filter as follows:
126
156
  - `SUPERSET_DASHBOARD_LOCALES` - This setting is used to configure the available locales
127
157
  for the dashboards. The configuration is a list of supported locales by `Aspects`_.
128
158
 
159
+ - `ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS` - This setting turns on and off the in-context
160
+ metrics feature. It must be turned off in Open edX releases before Sumac and when using
161
+ tutor-contrib-aspects before v2.2.0 as those dashboards will not exist, causing errors in
162
+ the embedded Instructor Dashboards.
163
+
164
+ - `ASPECTS_IN_CONTEXT_DASHBOARDS` - This setting mirrors the `ASPECTS_INSTRUCTOR_DASHBOARDS` but
165
+ with additional keys used for filtering the boards to specific courses and blocks.
166
+
129
167
  Event Sink Configuration
130
168
  ========================
131
169
 
@@ -161,12 +199,10 @@ Getting Help
161
199
  Documentation
162
200
  =============
163
201
 
164
- PLACEHOLDER: Start by going through `the documentation`_. If you need more help see below.
202
+ Start by going through `the documentation`_. If you need more help see below.
165
203
 
166
204
  .. _the documentation: https://docs.openedx.org/projects/platform-plugin-aspects
167
205
 
168
- (TODO: `Set up documentation <https://openedx.atlassian.net/wiki/spaces/DOC/pages/21627535/Publish+Documentation+on+Read+the+Docs>`_)
169
-
170
206
  More Help
171
207
  =========
172
208
 
@@ -5,6 +5,6 @@ Aspects plugins for edx-platform.
5
5
  import os
6
6
  from pathlib import Path
7
7
 
8
- __version__ = "1.0.2"
8
+ __version__ = "1.1.1"
9
9
 
10
10
  ROOT_DIRECTORY = Path(os.path.dirname(os.path.abspath(__file__)))
@@ -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 _, generate_superset_context, get_model
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,44 @@ def plugin_settings(settings):
104
104
  "model": "ObjectTag",
105
105
  },
106
106
  }
107
+
108
+ # This is on by default here, off by default in tutor-contrib-aspects until we only
109
+ # support versions Sumac and beyond
110
+ settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS = True
111
+
112
+ settings.ASPECTS_IN_CONTEXT_DASHBOARDS = {
113
+ "course": {
114
+ "name": _("Course"),
115
+ "slug": "in-context-course",
116
+ "uuid": "f2880cc1-63e9-48d7-ac3c-d2ff6f6698e2",
117
+ "allow_translations": True,
118
+ "course_filter_ids": ["NATIVE_FILTER-QLQbulmHH"],
119
+ "block_filter_ids": [],
120
+ },
121
+ "sequential": {
122
+ "name": _("Graded Subsection"),
123
+ "slug": "in-context-graded-subsection",
124
+ "uuid": "f0321087-6428-4b97-b32e-2dae7d9cc447",
125
+ "allow_translations": True,
126
+ "course_filter_ids": ["NATIVE_FILTER-oPAuR7ahy"],
127
+ "block_filter_ids": ["NATIVE_FILTER-CBWbI7uLq"],
128
+ },
129
+ "problem": {
130
+ "name": _("Problem"),
131
+ "slug": "in-context-problem",
132
+ "uuid": "98ff33ff-18dd-48f9-8c58-629ae4f4194b",
133
+ "allow_translations": True,
134
+ "course_filter_ids": ["NATIVE_FILTER-29CPcbirK"],
135
+ "block_filter_ids": ["NATIVE_FILTER-TJwItQhUI"],
136
+ },
137
+ "video": {
138
+ "name": _("Video"),
139
+ "slug": "in-context-video",
140
+ "uuid": "bc6510fb-027f-4026-a333-d0c42d3cc35c",
141
+ "allow_translations": True,
142
+ "course_filter_ids": ["NATIVE_FILTER-uaxvZkSAg"],
143
+ "block_filter_ids": ["NATIVE_FILTER-Fse4rzDW0"],
144
+ },
145
+ }
146
+ settings.IN_CONTEXT_DASHBOARD_COURSE_KEY_COLUMN = "course_key"
147
+ settings.IN_CONTEXT_DASHBOARD_BLOCK_ID_COLUMN = "block_id"
@@ -28,3 +28,11 @@ def plugin_settings(settings):
28
28
  "EVENT_SINK_CLICKHOUSE_PII_MODELS",
29
29
  settings.EVENT_SINK_CLICKHOUSE_PII_MODELS,
30
30
  )
31
+ settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS = settings.ENV_TOKENS.get(
32
+ "ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS",
33
+ settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS,
34
+ )
35
+ settings.ASPECTS_IN_CONTEXT_DASHBOARDS = settings.ENV_TOKENS.get(
36
+ "ASPECTS_IN_CONTEXT_DASHBOARDS",
37
+ settings.ASPECTS_IN_CONTEXT_DASHBOARDS,
38
+ )
@@ -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.SupersetView.as_view(),
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
  )
@@ -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,
@@ -152,26 +155,23 @@ def generate_guest_token(user, course, dashboards, filters) -> str:
152
155
  token = response.json().get("token")
153
156
  return token
154
157
 
155
- except HTTPError as err:
156
- # Superset server errors sometimes come with messages, so log the response.
157
- logger.error(
158
- f"{err.response.status_code} {err.response.json()} for url: {err.response.url}, data: {data}"
159
- )
160
- raise ImproperlyConfigured(
161
- _(
162
- "Unable to fetch Superset guest token, "
163
- "Superset server error {server_response}"
164
- ).format(server_response=err.response.json())
165
- ) from err
158
+ # We manually log the error message here because ImproperlyConfigured is eaten up the stack
159
+ except HTTPError as exc:
160
+ err = f"""Unable to fetch Superset guest token, mostly likely due to invalid
161
+ settings.SUPERSET_CONFIG or because one of the dashboard UUIDs requested does not
162
+ exist in Superset.\n
163
+ {exc.response.status_code} {exc.response.json()} for url:
164
+ {exc.response.url}, data: {data}\n\n dashboards: {dashboards}"""
165
+
166
+ logger.error(err)
167
+ raise ImproperlyConfigured(err) from exc
166
168
 
167
169
  except Exception as exc:
168
- logger.error(exc)
169
- raise ImproperlyConfigured(
170
- _(
171
- "Unable to fetch Superset guest token, "
172
- "mostly likely due to invalid settings.SUPERSET_CONFIG"
173
- )
174
- ) from exc
170
+ err = f"""Error trying to fetch Superset guest token, mostly likely due to invalid
171
+ settings.SUPERSET_CONFIG or because one of the dashboard UUIDs requested does not
172
+ exist in Superset. data: {data} \n\n exception: {exc}"""
173
+ logger.error(err)
174
+ raise ImproperlyConfigured(err) from exc
175
175
 
176
176
 
177
177
  def _fix_service_url(url: str) -> str:
@@ -309,3 +309,51 @@ def get_tags_for_block(usage_key) -> set:
309
309
  tag = tag.parent
310
310
 
311
311
  return list(serialized_tags)
312
+
313
+
314
+ def get_user_dashboard_locale(user):
315
+ """
316
+
317
+ Get the Superset dashboard locale from the user preference.
318
+
319
+ """
320
+ try:
321
+ user_language = (
322
+ get_model("user_preference").get_value(user, "pref-lang")
323
+ or DEFAULT_USER_LANGUAGE
324
+ )
325
+ # If there is no user_preferences model defined this will get thrown
326
+ except AttributeError:
327
+ user_language = DEFAULT_USER_LANGUAGE
328
+
329
+ formatted_language = user_language.lower().replace("-", "_")
330
+ if formatted_language not in [
331
+ loc.lower().replace("-", "_") for loc in settings.SUPERSET_DASHBOARD_LOCALES
332
+ ]:
333
+ formatted_language = DEFAULT_USER_LANGUAGE
334
+
335
+ return formatted_language
336
+
337
+
338
+ def build_filter(filter_id, column, operator, value):
339
+ """
340
+
341
+ Build a Superset native filter option.
342
+
343
+ """
344
+ return {
345
+ "id": filter_id,
346
+ "extraFormData": {
347
+ "filters": [
348
+ {
349
+ "col": column,
350
+ "op": operator,
351
+ "val": value,
352
+ },
353
+ ],
354
+ },
355
+ "filterState": {
356
+ "value": value,
357
+ },
358
+ "ownState": {},
359
+ }
@@ -0,0 +1,250 @@
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
+
132
+ # Only include these dashboards if in-context metrics are on,
133
+ # otherwise this call will always fail in older releases without
134
+ # admin intervention. This can be removed when we stop supporting
135
+ # < Sumac.
136
+ if settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS:
137
+ dashboards.extend(settings.ASPECTS_IN_CONTEXT_DASHBOARDS.values())
138
+
139
+ extra_filters_format = settings.SUPERSET_EXTRA_FILTERS_FORMAT
140
+
141
+ try:
142
+ guest_token = generate_guest_token(
143
+ user=request.user,
144
+ course=course,
145
+ dashboards=dashboards,
146
+ filters=DEFAULT_FILTERS_FORMAT + extra_filters_format,
147
+ )
148
+ except ImproperlyConfigured as exc:
149
+ raise APIException() from exc
150
+
151
+ return Response({"guestToken": guest_token})
152
+
153
+
154
+ class SupersetInContextDashboardView(GenericAPIView):
155
+ """
156
+ Endpoint for in-context analytics embedded Superset dashboard parameters.
157
+ """
158
+
159
+ authentication_classes = (SessionAuthentication,)
160
+ permission_classes = (
161
+ permissions.IsAuthenticated,
162
+ IsStaffOrReadOnly | IsCourseStaffInstructor,
163
+ )
164
+
165
+ lookup_field = "usage_id"
166
+
167
+ def get_object(self):
168
+ """
169
+ Return a usage key or course key for the requested usage_key.
170
+ """
171
+ usage_id = self.kwargs.get(self.lookup_field, "")
172
+ try:
173
+ usage_key = UsageKey.from_string(usage_id)
174
+ except InvalidKeyError as exc:
175
+ try:
176
+ course_key = usage_key = CourseKey.from_string(usage_id)
177
+ except InvalidKeyError:
178
+ raise NotFound(
179
+ _("Invalid usage id: '{usage_id}'").format(usage_id=usage_id)
180
+ ) from exc
181
+ else:
182
+ course_key = usage_key.course_key
183
+
184
+ course = _get_course(course_key)
185
+ self.check_object_permissions(self.request, course)
186
+
187
+ return usage_key
188
+
189
+ def get(self, request, *args, **kwargs):
190
+ """
191
+ Return Superset context for embedding the dashboard for the requested block.
192
+ """
193
+ usage_key = self.get_object()
194
+ if isinstance(usage_key, CourseKey):
195
+ block_type = "course"
196
+ course_key = usage_key
197
+ else:
198
+ block_type = usage_key.block_type
199
+ course_key = usage_key.course_key
200
+
201
+ course_key_col = settings.IN_CONTEXT_DASHBOARD_COURSE_KEY_COLUMN
202
+ block_id_col = settings.IN_CONTEXT_DASHBOARD_BLOCK_ID_COLUMN
203
+
204
+ dashboards = settings.ASPECTS_IN_CONTEXT_DASHBOARDS
205
+ dashboard = dashboards.get(block_type)
206
+ if dashboard is None:
207
+ raise NotFound(
208
+ _("No dashboard for block type: '{block_type}'").format(
209
+ block_type=block_type
210
+ )
211
+ )
212
+
213
+ block_filter = {}
214
+ if not isinstance(usage_key, CourseKey):
215
+ for filter_id in dashboard["block_filter_ids"]:
216
+ block_filter[filter_id] = build_filter(
217
+ filter_id, block_id_col, "IN", [usage_key.block_id]
218
+ )
219
+
220
+ course_runs = {}
221
+ # In the future we might provide other course runs so that the
222
+ # embedding application can apply their corresponding filters
223
+ # instead of needing the Superset filter UI.
224
+ for course_run in [course_key.run]:
225
+ course_filter = block_filter.copy()
226
+ for filter_id in dashboard["course_filter_ids"]:
227
+ course_filter[filter_id] = build_filter(
228
+ filter_id, course_key_col, "IN", [str(course_key)]
229
+ )
230
+ course_runs[course_run] = {
231
+ # Superset filter URL parameter is encoded as Rison.
232
+ "native_filters": prison.dumps(course_filter),
233
+ }
234
+
235
+ if dashboard.get("allow_translations"):
236
+ language = get_user_dashboard_locale(request.user)
237
+ dashboard = dashboard.copy()
238
+ dashboard["uuid"] = get_localized_uuid(dashboard["uuid"], language)
239
+
240
+ superset_config = settings.SUPERSET_CONFIG
241
+ superset_url = superset_config.get("service_url")
242
+
243
+ return Response(
244
+ {
245
+ "dashboardId": dashboard["uuid"],
246
+ "supersetUrl": superset_url,
247
+ "courseRuns": course_runs,
248
+ "defaultCourseRun": course_key.run,
249
+ }
250
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: platform-plugin-aspects
3
- Version: 1.0.2
3
+ Version: 1.1.1
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
@@ -58,8 +59,8 @@ dashboards back into the platform.
58
59
  Version Compatibility
59
60
  *********************
60
61
 
61
- `platform-plugin-aspects` version 1.x: Nutmeg to Sumac
62
- `platform-plugin-aspects` version 2.x: Redwood and above
62
+ - ``platform-plugin-aspects`` version 1.x: Nutmeg to Sumac
63
+ - ``platform-plugin-aspects`` version 2.x: Redwood (with in-context metrics turned off), or Sumac and above
63
64
 
64
65
  Sinks
65
66
  *****
@@ -70,16 +71,21 @@ events are emitted by the Open edX platform via `Open edX events`_ or Django sig
70
71
  Available Sinks
71
72
  ===============
72
73
 
73
- - `CourseOverviewSink` - Listens for the `COURSE_PUBLISHED` event and stores the
74
- course structure data through `XBlockSink` in ClickHouse.
75
- - `ExternalIdSink` - Listens for the `post_save` Django signal on the `ExternalId`
76
- model and stores the external id data in ClickHouse.
77
- - `UserProfile` - Listens for the `post_save` Django signal on the `UserProfile`
78
- model and stores the user profile data in ClickHouse.
79
- - `UserRetirementSink` - Listen for the `USER_RETIRE_LMS_MISC` Django signal and
80
- remove the user PII information from ClickHouse.
81
- - `CourseEnrollmentSink` - Listen for the `ENROLL_STATUS_CHANGE` event and stores
82
- the course enrollment data.
74
+ Below are the existing sink names, and their corresponding object names (as needed for the
75
+ ``dump_data_to_clickhouse`` command below.
76
+
77
+ - ``CourseOverviewSink`` - Listens for the `COURSE_PUBLISHED` event and stores the
78
+ course structure including ordering data through `XBlockSink` in ClickHouse. Object name:
79
+ ``course_overviews``
80
+ - ``ExternalIdSink`` - Listens for the `post_save` Django signal on the `ExternalId`
81
+ model and stores the external id data in ClickHouse. This model stores the relationships
82
+ between users and their xAPI unique identifiers. Object name: ``external_id``
83
+ - ``UserProfile`` - Listens for the `post_save` Django signal on the ``UserProfile``
84
+ model and stores the user profile data in ClickHouse. Object name: ``user_profile``
85
+ - ``CourseEnrollmentSink`` - Listen for the `ENROLL_STATUS_CHANGE` event and stores
86
+ the course enrollment data. Object name: ``course_enrollment``
87
+ - ``UserRetirementSink`` - Listen for the `USER_RETIRE_LMS_MISC` Django signal and
88
+ remove the user PII information from ClickHouse. This is a special sink and has no object name.
83
89
 
84
90
  Commands
85
91
  ========
@@ -87,9 +93,34 @@ Commands
87
93
  In addition to being an event listener, this package provides the following commands:
88
94
 
89
95
  - `dump_data_to_clickhouse` - This command allows bulk export of the data from the Sinks.
90
- Allows bootstrapping a new data platform or backfilling lost or missing data. More information can be found in the `Aspects backfill documentation`_.
96
+ Allows bootstrapping a new data platform or backfilling lost or missing data. Each sink object
97
+ is dumped individually. For large dumps you can use the --batch_size and --sleep_time to control
98
+ how much load is placed on your LMS / Studio servers. Examples:
91
99
 
92
- ``python manage.py cms dump_data_to_clickhouse``
100
+ Dump any courses that the systems thinks are out of date (last publish time is newer than the
101
+ last dump time in ClickHouse):
102
+
103
+ ``python manage.py cms dump_data_to_clickhouse --object course_overviews``
104
+
105
+ The ``force`` option willl dump all objects, regardless of the data ClickHouse currently has
106
+ so this command will push all course data for all courses:
107
+
108
+ ``python manage.py cms dump_data_to_clickhouse --object course_overviews --force``
109
+
110
+ These commands will dump the user data Aspects uses when PII is turned on:
111
+
112
+ ``python manage.py cms dump_data_to_clickhouse --object external_id``
113
+ ``python manage.py cms dump_data_to_clickhouse --object user_profile``
114
+
115
+ To reduce server load, this command will dump 1000 user profiles at a time, with a 5 second
116
+ sleep in between:
117
+
118
+ ``python manage.py cms dump_data_to_clickhouse --object user_profile --batch_size 1000 --sleep_time 5``
119
+
120
+ There are many more options that can be used for different circumstances. Please refer to
121
+ the commands help for more information. There is also a Tutor command that wraps this, so
122
+ that you don't need to get shell on a container to execute this command. More information on
123
+ that can be found in the `Aspects backfill documentation`_.
93
124
 
94
125
  - `load_test_tracking_events` - This command allows loading test tracking events into
95
126
  ClickHouse. This is useful for testing the ClickHouse connection to measure the performance of the
@@ -173,6 +204,14 @@ superset pipeline into the filter as follows:
173
204
  - `SUPERSET_DASHBOARD_LOCALES` - This setting is used to configure the available locales
174
205
  for the dashboards. The configuration is a list of supported locales by `Aspects`_.
175
206
 
207
+ - `ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS` - This setting turns on and off the in-context
208
+ metrics feature. It must be turned off in Open edX releases before Sumac and when using
209
+ tutor-contrib-aspects before v2.2.0 as those dashboards will not exist, causing errors in
210
+ the embedded Instructor Dashboards.
211
+
212
+ - `ASPECTS_IN_CONTEXT_DASHBOARDS` - This setting mirrors the `ASPECTS_INSTRUCTOR_DASHBOARDS` but
213
+ with additional keys used for filtering the boards to specific courses and blocks.
214
+
176
215
  Event Sink Configuration
177
216
  ========================
178
217
 
@@ -208,12 +247,10 @@ Getting Help
208
247
  Documentation
209
248
  =============
210
249
 
211
- PLACEHOLDER: Start by going through `the documentation`_. If you need more help see below.
250
+ Start by going through `the documentation`_. If you need more help see below.
212
251
 
213
252
  .. _the documentation: https://docs.openedx.org/projects/platform-plugin-aspects
214
253
 
215
- (TODO: `Set up documentation <https://openedx.atlassian.net/wiki/spaces/DOC/pages/21627535/Publish+Documentation+on+Read+the+Docs>`_)
216
-
217
254
  More Help
218
255
  =========
219
256
 
@@ -8,6 +8,7 @@ edx-opaque-keys
8
8
  edx-toggles
9
9
  openedx-atlas
10
10
  openedx-filters
11
+ prison
11
12
  redis
12
13
  requests
13
14
  superset-api-client
@@ -16,3 +16,4 @@ edx-opaque-keys # Parsing library for course and usage keys
16
16
  djangorestframework # REST API framework
17
17
  edx-toggles
18
18
  XBlock
19
+ prison # Rison encoder, same one as used by Superset
@@ -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})