platform-plugin-aspects 2.0.1__py3-none-any.whl

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/__init__.py +11 -0
  2. platform_plugin_aspects/apps.py +77 -0
  3. platform_plugin_aspects/conf/locale/babel_mako.cfg +10 -0
  4. platform_plugin_aspects/conf/locale/config.yaml +85 -0
  5. platform_plugin_aspects/conf/locale/en/LC_MESSAGES/django.mo +0 -0
  6. platform_plugin_aspects/conf/locale/en/LC_MESSAGES/django.po +99 -0
  7. platform_plugin_aspects/conf/locale/en/LC_MESSAGES/mako.mo +0 -0
  8. platform_plugin_aspects/conf/locale/en/LC_MESSAGES/mako.po +23 -0
  9. platform_plugin_aspects/conf/locale/eo/LC_MESSAGES/django.mo +0 -0
  10. platform_plugin_aspects/conf/locale/eo/LC_MESSAGES/django.po +70 -0
  11. platform_plugin_aspects/conf/locale/eo/LC_MESSAGES/mako.mo +0 -0
  12. platform_plugin_aspects/conf/locale/eo/LC_MESSAGES/mako.po +23 -0
  13. platform_plugin_aspects/extensions/__init__.py +0 -0
  14. platform_plugin_aspects/extensions/filters.py +108 -0
  15. platform_plugin_aspects/management/__init__.py +0 -0
  16. platform_plugin_aspects/management/commands/__init__.py +0 -0
  17. platform_plugin_aspects/management/commands/dump_data_to_clickhouse.py +214 -0
  18. platform_plugin_aspects/management/commands/load_test_tracking_events.py +310 -0
  19. platform_plugin_aspects/management/commands/monitor_load_test_tracking.py +440 -0
  20. platform_plugin_aspects/settings/__init__.py +0 -0
  21. platform_plugin_aspects/settings/common.py +147 -0
  22. platform_plugin_aspects/settings/production.py +38 -0
  23. platform_plugin_aspects/signals.py +305 -0
  24. platform_plugin_aspects/sinks/__init__.py +11 -0
  25. platform_plugin_aspects/sinks/base_sink.py +381 -0
  26. platform_plugin_aspects/sinks/course_enrollment_sink.py +20 -0
  27. platform_plugin_aspects/sinks/course_overview_sink.py +286 -0
  28. platform_plugin_aspects/sinks/external_id_sink.py +20 -0
  29. platform_plugin_aspects/sinks/serializers.py +274 -0
  30. platform_plugin_aspects/sinks/tag_sink.py +47 -0
  31. platform_plugin_aspects/sinks/user_profile_sink.py +20 -0
  32. platform_plugin_aspects/sinks/user_retire_sink.py +50 -0
  33. platform_plugin_aspects/static/css/superset.css +53 -0
  34. platform_plugin_aspects/static/html/superset.html +39 -0
  35. platform_plugin_aspects/static/html/superset_student.html +5 -0
  36. platform_plugin_aspects/static/js/embed_dashboard.js +94 -0
  37. platform_plugin_aspects/static/js/install_required.js +11 -0
  38. platform_plugin_aspects/static/js/superset.js +38 -0
  39. platform_plugin_aspects/tasks.py +64 -0
  40. platform_plugin_aspects/templates/instructor_dashboard/aspects.html +22 -0
  41. platform_plugin_aspects/urls.py +39 -0
  42. platform_plugin_aspects/utils.py +359 -0
  43. platform_plugin_aspects/views.py +296 -0
  44. platform_plugin_aspects/waffle.py +5 -0
  45. platform_plugin_aspects/xblock.py +239 -0
  46. platform_plugin_aspects-2.0.1.dist-info/METADATA +335 -0
  47. platform_plugin_aspects-2.0.1.dist-info/RECORD +51 -0
  48. platform_plugin_aspects-2.0.1.dist-info/WHEEL +5 -0
  49. platform_plugin_aspects-2.0.1.dist-info/entry_points.txt +8 -0
  50. platform_plugin_aspects-2.0.1.dist-info/licenses/LICENSE +201 -0
  51. platform_plugin_aspects-2.0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,50 @@
1
+ """User retirement sink"""
2
+
3
+ import requests
4
+ from django.conf import settings
5
+
6
+ from platform_plugin_aspects.sinks.base_sink import ModelBaseSink
7
+ from platform_plugin_aspects.sinks.serializers import UserRetirementSerializer
8
+
9
+
10
+ class UserRetirementSink(ModelBaseSink): # pylint: disable=abstract-method
11
+ """
12
+ Sink for user retirement events
13
+ """
14
+
15
+ model = "auth_user"
16
+ unique_key = "id"
17
+ clickhouse_table_name = (
18
+ "dummy" # uses settings.EVENT_SINK_CLICKHOUSE_PII_MODELS instead
19
+ )
20
+ timestamp_field = "modified"
21
+ name = "User Retirement"
22
+ serializer_class = UserRetirementSerializer
23
+
24
+ def send_item(self, serialized_item, many=False):
25
+ """
26
+ Unlike the other data sinks, the User Retirement sink deletes records from the user PII tables in Clickhouse.
27
+
28
+ Send delete queries to remove the serialized User from ClickHouse.
29
+ """
30
+ if many:
31
+ users = serialized_item
32
+ else:
33
+ users = [serialized_item]
34
+ user_ids = {str(user["user_id"]) for user in users}
35
+ user_ids_str = ",".join(sorted(user_ids))
36
+ clickhouse_pii_tables = getattr(
37
+ settings, "EVENT_SINK_CLICKHOUSE_PII_MODELS", []
38
+ )
39
+
40
+ for table in clickhouse_pii_tables:
41
+ params = {
42
+ "query": f"ALTER TABLE {self.ch_database}.{table} DELETE WHERE user_id in ({user_ids_str})",
43
+ }
44
+ request = requests.Request(
45
+ "POST",
46
+ self.ch_url,
47
+ params=params,
48
+ auth=self.ch_auth,
49
+ )
50
+ self._send_clickhouse_request(request)
@@ -0,0 +1,53 @@
1
+ .superset-embedded-container>iframe {
2
+ height: 920px;
3
+ width: 100%;
4
+ display: block;
5
+ border: none;
6
+ }
7
+
8
+ .aspects-tabs {
9
+ position: relative;
10
+ min-height: 920px;
11
+ /* This part sucks */
12
+ clear: both;
13
+ margin: 25px 0;
14
+ }
15
+
16
+ .aspects-tab {
17
+ float: left;
18
+ }
19
+
20
+ .aspects-tab label {
21
+ background: #eee;
22
+ padding: 10px;
23
+ border: 1px solid #ccc;
24
+ margin-left: -1px;
25
+ position: relative;
26
+ left: 1px;
27
+ bottom: 5px;
28
+ }
29
+
30
+ .aspects-tab [type=radio] {
31
+ display: none;
32
+ }
33
+
34
+ .aspects-content {
35
+ position: absolute;
36
+ top: 28px;
37
+ left: 0;
38
+ background: white;
39
+ right: 0;
40
+ bottom: 0;
41
+ padding: 0;
42
+ border: 1px solid #ccc;
43
+ }
44
+
45
+ [type=radio]:checked~label {
46
+ background: white;
47
+ border-bottom: 1px solid white;
48
+ z-index: 2;
49
+ }
50
+
51
+ [type=radio]:checked~label~.aspects-content {
52
+ z-index: 1;
53
+ }
@@ -0,0 +1,39 @@
1
+ {% load i18n %}
2
+
3
+ <script src="https://unpkg.com/@superset-ui/embedded-sdk"></script>
4
+
5
+ <div class="aspects-wrapper" width="fit-content">
6
+ <h2>{{display_name}}</h2>
7
+
8
+ {% if exception %}
9
+ <p>{% trans 'Superset is not configured properly. Please contact your system administrator.'%}</p>
10
+ <p>{{exception}}</p>
11
+ {% elif not superset_dashboards %}
12
+ <p>Dashboard UUID is not set. Please set the dashboard UUID in the Studio.</p>
13
+ {% elif superset_url %} {% if xblock_id %}
14
+ <div class="superset-embedded-container" id="superset-embedded-container-{{xblock_id}}"></div>
15
+ {% else %}
16
+ <div class="aspects-tabs">
17
+ {% for dashboard in superset_dashboards %}
18
+ <div class="aspects-tab">
19
+ {% if forloop.counter == 1 %}
20
+ <input type="radio" id="tab-{{forloop.counter}}" name="tab-group-1" checked="checked" />
21
+ {% else %}
22
+ <input type="radio" id="tab-{{forloop.counter}}" name="tab-group-1" />
23
+ {% endif %}
24
+ <label for="tab-{{forloop.counter}}">{% trans dashboard.name %}</label>
25
+ <div class="aspects-content superset-embedded-container" id="superset-embedded-container-{{dashboard.uuid}}"></div>
26
+ </div>
27
+ {% endfor %}
28
+ </div>
29
+ {% endif %}
30
+
31
+ {{superset_dashboards|json_script:"superset_dashboards"}}
32
+
33
+ <script type="text/javascript">
34
+ window.superset_dashboards = JSON.parse(document.getElementById('superset_dashboards').textContent);
35
+ window.superset_url = "{{superset_url}}";
36
+ window.superset_guest_token_url = "{{superset_guest_token_url}}";
37
+ </script>
38
+ {% endif %}
39
+ </div>
@@ -0,0 +1,5 @@
1
+ {% load i18n %}
2
+ <div class="email-notifier-instructor-wrapper" width="parent">
3
+ <h2>{{display_name}}</h2>
4
+ <p>{% trans 'Superset is only visible to course staff and instructors. Please contact your system administrator.'%}</p>
5
+ </div>
@@ -0,0 +1,94 @@
1
+ function getCookie(name) {
2
+ let cookieValue = null;
3
+ if (document.cookie && document.cookie !== "") {
4
+ const cookies = document.cookie.split(";");
5
+ for (let i = 0; i < cookies.length; i++) {
6
+ const cookie = cookies[i].trim();
7
+ // Does this cookie string begin with the name we want?
8
+ if (cookie.substring(0, name.length + 1) === name + "=") {
9
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
10
+ break;
11
+ }
12
+ }
13
+ }
14
+ return cookieValue;
15
+ }
16
+
17
+ async function fetchGuestToken() {
18
+ let response;
19
+ if (window.from_xblock){
20
+ // XBlock handler requires a POST request and a JSON body
21
+ body = JSON.stringify({});
22
+ method = 'POST';
23
+ }else {
24
+ body = null;
25
+ method = 'GET';
26
+ }
27
+
28
+ response = await fetch(window.superset_guest_token_url, {
29
+ method: method,
30
+ headers: {
31
+ "X-CSRFToken": getCookie("csrftoken"),
32
+ },
33
+ credentials: 'include',
34
+ body: body,
35
+ });
36
+
37
+ if (!response.ok) {
38
+ console.error(await response.json());
39
+ // TODO: Handle error
40
+ return null;
41
+ }
42
+
43
+ const data = await response.json();
44
+ return data.guestToken;
45
+ }
46
+
47
+ function _embedDashboard(dashboard_uuid, superset_url, xblock_id){
48
+ window.supersetEmbeddedSdk
49
+ .embedDashboard({
50
+ id: dashboard_uuid, // given by the Superset embedding UI
51
+ supersetDomain: superset_url, // your Superset instance
52
+ mountPoint: document.getElementById(`superset-embedded-container-${xblock_id}`), // any html element that can contain an iframe
53
+ fetchGuestToken: fetchGuestToken,
54
+ dashboardUiConfig: {
55
+ // dashboard UI config: hideTitle, hideTab, hideChartControls, filters.visible, filters.expanded (optional)
56
+ hideTitle: true,
57
+ filters: {
58
+ expanded: false,
59
+ },
60
+ hideTab: true,
61
+ hideChartControls: false,
62
+ hideFilters: true,
63
+ },
64
+ })
65
+ .then((dashboard) => {
66
+ mountPoint = document.getElementById("superset-embedded-container");
67
+ /*
68
+ Perform extra operations on the dashboard object or the container
69
+ when the dashboard is loaded
70
+ */
71
+ });
72
+ }
73
+
74
+ function embedDashboard(dashboard, superset_url, xblock_id, index) {
75
+ xblock_id = xblock_id || "";
76
+ let radio = document.querySelector(`#tab-${index+1}`)
77
+ if (index == 0){
78
+ dashboard.loaded = true;
79
+ _embedDashboard(dashboard.uuid, superset_url, xblock_id)
80
+ }
81
+ radio.addEventListener("change", () => {
82
+ if (dashboard.loaded){
83
+ return
84
+ }
85
+ dashboard.loaded = true;
86
+ _embedDashboard(dashboard.uuid, superset_url, xblock_id)
87
+ });
88
+ };
89
+
90
+ if (window.superset_dashboards !== undefined) {
91
+ window.superset_dashboards.forEach(function(dashboard, i) {
92
+ embedDashboard(dashboard, window.superset_url, dashboard.uuid, i);
93
+ });
94
+ }
@@ -0,0 +1,11 @@
1
+ try {
2
+ (function (require) {
3
+ require.config({
4
+ paths: {
5
+ supersetEmbeddedSdk: "https://cdn.jsdelivr.net/npm/@superset-ui/embedded-sdk@0.1.0-alpha.10/bundle/index.min",
6
+ },
7
+ });
8
+ }).call(this, require || RequireJS.require);
9
+ } catch (e) {
10
+ console.log("Unable to load embedded_sdk via requirejs");
11
+ }
@@ -0,0 +1,38 @@
1
+ /* Javascript for SupersetXBlock. */
2
+ function SupersetXBlock(runtime, element, context) {
3
+ const dashboard_uuid = context.dashboard_uuid;
4
+ const superset_url = context.superset_url;
5
+ const xblock_id = context.xblock_id;
6
+
7
+ window.superset_guest_token_url = runtime.handlerUrl(element, 'get_superset_guest_token');
8
+ window.from_xblock = true;
9
+
10
+ function initSuperset(supersetEmbeddedSdk) {
11
+ _embedDashboard(dashboard_uuid, superset_url, xblock_id);
12
+ }
13
+
14
+ if (typeof require === "function") {
15
+ require(["supersetEmbeddedSdk"], function (supersetEmbeddedSdk) {
16
+ window.supersetEmbeddedSdk = supersetEmbeddedSdk;
17
+ initSuperset();
18
+ });
19
+ } else {
20
+ loadJS(function () {
21
+ initSuperset();
22
+ });
23
+ }
24
+ }
25
+
26
+ function loadJS(callback) {
27
+ if (window.supersetEmbeddedSdk) {
28
+ callback();
29
+ } else {
30
+ $.getScript("https://cdn.jsdelivr.net/npm/@superset-ui/embedded-sdk@0.1.0-alpha.10/bundle/index.min.js")
31
+ .done(function () {
32
+ callback();
33
+ })
34
+ .fail(function () {
35
+ console.error("Error loading supersetEmbeddedSdk.");
36
+ });
37
+ }
38
+ }
@@ -0,0 +1,64 @@
1
+ """
2
+ This file contains a management command for exporting course modulestore data to ClickHouse.
3
+ """
4
+
5
+ import logging
6
+ from importlib import import_module
7
+
8
+ from celery import shared_task
9
+ from edx_django_utils.monitoring import set_code_owner_attribute
10
+ from opaque_keys.edx.keys import CourseKey
11
+
12
+ from platform_plugin_aspects.sinks import CourseOverviewSink
13
+ from platform_plugin_aspects.utils import get_ccx_courses
14
+
15
+ log = logging.getLogger(__name__)
16
+ celery_log = logging.getLogger("edx.celery.task")
17
+
18
+
19
+ @shared_task
20
+ @set_code_owner_attribute
21
+ def dump_course_to_clickhouse(course_key_string, connection_overrides=None):
22
+ """
23
+ Serialize a course and writes it to ClickHouse.
24
+
25
+ Arguments:
26
+ course_key_string: course key for the course to be exported
27
+ connection_overrides (dict): overrides to ClickHouse connection
28
+ parameters specified in `settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG`.
29
+ """
30
+ if CourseOverviewSink.is_enabled(): # pragma: no cover
31
+ course_key = CourseKey.from_string(course_key_string)
32
+ sink = CourseOverviewSink(
33
+ connection_overrides=connection_overrides, log=celery_log
34
+ )
35
+ sink.dump(course_key)
36
+
37
+ ccx_courses = get_ccx_courses(course_key)
38
+ for ccx_course in ccx_courses:
39
+ ccx_course_key = str(ccx_course.locator)
40
+ sink.dump(ccx_course_key)
41
+
42
+
43
+ @shared_task
44
+ @set_code_owner_attribute
45
+ def dump_data_to_clickhouse(
46
+ sink_module, sink_name, object_id, connection_overrides=None
47
+ ):
48
+ """
49
+ Serialize a data and writes it to ClickHouse.
50
+
51
+ Arguments:
52
+ sink_module: module path of sink
53
+ sink_name: name of sink class
54
+ object_id: id of object
55
+ connection_overrides (dict): overrides to ClickHouse connection
56
+ """
57
+ Sink = getattr(import_module(sink_module), sink_name)
58
+
59
+ if Sink.is_enabled():
60
+ sink = Sink(connection_overrides=connection_overrides, log=celery_log)
61
+ sink.dump(object_id)
62
+ return "Dumped"
63
+
64
+ return "Disabled"
@@ -0,0 +1,22 @@
1
+ ## mako
2
+
3
+ <%page args="section_data" expression_filter="h"/>
4
+ <%!
5
+ from django.utils.translation import gettext as _
6
+ from openedx.core.djangolib.markup import HTML
7
+ %>
8
+
9
+ <%include file="/courseware/xqa_interface.html/"/>
10
+ <%
11
+ superset_url = section_data.get("superset_url")
12
+ show_superset_link = superset_url and section_data.get("show_dashboard_link")
13
+ %>
14
+
15
+ <section class="superset">
16
+ % if show_superset_link:
17
+ <div class="superset-link">
18
+ <a href="${superset_url}login/openedxsso">${_("View dashboards in Superset")}</a>
19
+ </div>
20
+ % endif
21
+ ${HTML(section_data['fragment'].body_html())}
22
+ </section>
@@ -0,0 +1,39 @@
1
+ """
2
+ Urls for the Aspects plugin.
3
+ """
4
+
5
+ from django.urls import include, path, re_path
6
+
7
+ from . import views
8
+
9
+ # Copied from openedx.core.constants
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
+ )
15
+
16
+ app_url_patterns = (
17
+ [
18
+ re_path(
19
+ rf"superset_guest_token/{COURSE_ID_PATTERN}/?$",
20
+ views.SupersetTokenView.as_view(),
21
+ name="superset_guest_token",
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
+ ),
28
+ re_path(
29
+ rf"superset_instructor_dashboard/{COURSE_ID_PATTERN}/?$",
30
+ views.SupersetInstructorDashboardView.as_view(),
31
+ name="superset_instructor_dashboard",
32
+ ),
33
+ ],
34
+ "platform_plugin_aspects",
35
+ )
36
+
37
+ urlpatterns = [
38
+ path("", include(app_url_patterns)),
39
+ ]