Skip to content

feat: allow to embed translated dashboard #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[run]
branch = True
relative_files = True
data_file = .coverage
source=platform_plugin_aspects
omit =
Expand All @@ -9,3 +10,4 @@ omit =
*/static/*
*/templates/*
**/tests/*
*/settings/*
26 changes: 23 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ jobs:
os: [ubuntu-20.04]
python-version: ['3.8']
toxenv: [quality, docs, pii_check, django32, django40]
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for pushing data to the
# python-coverage-comment-action branch, and for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write

steps:
- uses: actions/checkout@v4
Expand All @@ -38,7 +46,19 @@ jobs:

- name: Run coverage
if: matrix.python-version == '3.8' && matrix.toxenv == 'django32'
uses: codecov/codecov-action@v3
uses: py-cov-action/python-coverage-comment-action@v3
with:
flags: unittests
fail_ci_if_error: true
GITHUB_TOKEN: ${{ github.token }}
MINIMUM_GREEN: 90
MINIMUM_ORANGE: 85
ANNOTATE_MISSING_LINES: true
ANNOTATION_TYPE: error

- name: Store Pull Request comment to be posted
uses: actions/upload-artifact@v4
if: steps.coverage_comment.outputs.COMMENT_FILE_WRITTEN == 'true'
with:
# If you use a different name, update COMMENT_ARTIFACT_NAME accordingly
name: python-coverage-comment-action
# If you use a different name, update COMMENT_FILENAME accordingly
path: python-coverage-comment-action.txt
36 changes: 36 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# .github/workflows/coverage.yml
name: Post coverage comment

on:
workflow_run:
workflows: ["Python CI"]
types:
- completed

jobs:
test:
name: Run tests & display coverage
runs-on: ubuntu-latest
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
permissions:
# Gives the action the necessary permissions for publishing new
# comments in pull requests.
pull-requests: write
# Gives the action the necessary permissions for editing existing
# comments (to avoid publishing multiple comments in the same PR)
contents: write
# Gives the action the necessary permissions for looking up the
# workflow that launched this workflow, and download the related
# artifact that contains the comment to be published
actions: read
steps:
# DO NOT run actions/checkout here, for security reasons
# For details, refer to https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
- name: Post comment
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_PR_RUN_ID: ${{ github.event.workflow_run.id }}
# Update those if you changed the default values:
# COMMENT_ARTIFACT_NAME: python-coverage-comment-action
# COMMENT_FILENAME: python-coverage-comment-action.txt
11 changes: 10 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ Unreleased

*

0.6.0 - 2024-04-08
******************

Added
=====

* Allow to embed translated Superset Dashboards.

0.5.0 - 2024-04-01
******************

Expand All @@ -24,7 +32,6 @@ Added

* Load testing and test monitoring scripts.


0.4.0 - 2024-03-18
******************

Expand All @@ -43,13 +50,15 @@ Added

0.3.0 – 2024-03-10
******************

Added
=====

* Imported XBlock code from platform-plugin-superset

0.2.0 – 2024-03-05
******************

Added
=====

Expand Down
2 changes: 1 addition & 1 deletion platform_plugin_aspects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import os
from pathlib import Path

__version__ = "0.5.0"
__version__ = "0.6.0"

ROOT_DIRECTORY = Path(os.path.dirname(os.path.abspath(__file__)))
12 changes: 10 additions & 2 deletions platform_plugin_aspects/extensions/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from openedx_filters import PipelineStep
from web_fragments.fragment import Fragment

from platform_plugin_aspects.utils import generate_superset_context
from platform_plugin_aspects.utils import _, generate_superset_context, get_model

TEMPLATE_ABSOLUTE_PATH = "/instructor_dashboard/"
BLOCK_CATEGORY = "aspects"
Expand Down Expand Up @@ -42,11 +42,19 @@ def run_filter(

user = get_current_user()

user_language = (
get_model("user_preference").get_value(user, "pref-lang") or "en_US"
)
formatted_language = user_language.replace("-", "_")
if formatted_language not in settings.SUPERSET_DASHBOARD_LOCALES:
formatted_language = "en_US"

context = generate_superset_context(
context,
user,
dashboards=dashboards,
filters=filters,
language=formatted_language,
)

template = Template(self.resource_string("static/html/superset.html"))
Expand All @@ -57,7 +65,7 @@ def run_filter(
section_data = {
"fragment": frag,
"section_key": BLOCK_CATEGORY,
"section_display_name": BLOCK_CATEGORY.title(),
"section_display_name": _("Analytics"),
"course_id": str(course.id),
"superset_url": str(context.get("superset_url")),
"template_path_prefix": TEMPLATE_ABSOLUTE_PATH,
Expand Down
43 changes: 40 additions & 3 deletions platform_plugin_aspects/extensions/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
Tests for the filters module.
"""

from unittest import TestCase
from unittest.mock import Mock, patch

from django.test import TestCase

from platform_plugin_aspects.extensions.filters import BLOCK_CATEGORY, AddSupersetTab


Expand All @@ -22,7 +23,10 @@ def setUp(self) -> None:
self.context = {"course": Mock()}

@patch("platform_plugin_aspects.extensions.filters.generate_superset_context")
def test_run_filter(self, mock_generate_superset_context):
@patch("platform_plugin_aspects.extensions.filters.get_model")
def test_run_filter_with_language(
self, mock_get_model, mock_generate_superset_context
):
"""
Check the filter is not executed when there are no LimeSurvey blocks in the course.

Expand All @@ -34,13 +38,46 @@ def test_run_filter(self, mock_generate_superset_context):
"superset_url": "http://superset.testing",
}

mock_get_model.return_value.get_value.return_value = "not-a-language"

context = self.filter.run_filter(self.context, self.template_name)

self.assertDictContainsSubset(
{
"course_id": str(self.context["course"].id),
"section_key": BLOCK_CATEGORY,
"section_display_name": "Analytics",
"superset_url": "http://superset.testing",
"template_path_prefix": "/instructor_dashboard/",
},
context["context"]["sections"][0],
)

@patch("platform_plugin_aspects.extensions.filters.generate_superset_context")
@patch("platform_plugin_aspects.extensions.filters.get_model")
def test_run_filter_without_language(
self, mock_get_model, mock_generate_superset_context
):
"""
Check the filter is not executed when there are no LimeSurvey blocks in the course.

Expected result:
- The context is returned without modifications.
"""
mock_generate_superset_context.return_value = {
"sections": [],
"superset_url": "http://superset.testing",
}

mock_get_model.return_value.get_value.return_value = None

context = self.filter.run_filter(self.context, self.template_name)

self.assertDictContainsSubset(
{
"course_id": str(self.context["course"].id),
"section_key": BLOCK_CATEGORY,
"section_display_name": BLOCK_CATEGORY.title(),
"section_display_name": "Analytics",
"superset_url": "http://superset.testing",
"template_path_prefix": "/instructor_dashboard/",
},
Expand Down
7 changes: 7 additions & 0 deletions platform_plugin_aspects/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ def plugin_settings(settings):
settings.ASPECTS_INSTRUCTOR_DASHBOARDS = [
{
"name": "Instructor Dashboard",
"slug": "instructor-dashboard",
"uuid": "1d6bf904-f53f-47fd-b1c9-6cd7e284d286",
"allow_translations": True,
},
]
settings.SUPERSET_EXTRA_FILTERS_FORMAT = []
settings.SUPERSET_DASHBOARD_LOCALES = ["en_US"]
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG = {
# URL to a running ClickHouse server's HTTP interface. ex: https://foo.openedx.org:8443/ or
# http://foo.openedx.org:8123/ . Note that we only support the ClickHouse HTTP interface
Expand Down Expand Up @@ -64,4 +67,8 @@ def plugin_settings(settings):
"module": "lms.djangoapps.ccx.models",
"model": "CustomCourseForEdX",
},
"user_preference": {
"module": "openedx.core.djangoapps.user_api.models",
"model": "UserPreference",
},
}
3 changes: 3 additions & 0 deletions platform_plugin_aspects/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def plugin_settings(settings):
settings.SUPERSET_EXTRA_FILTERS_FORMAT = getattr(settings, "ENV_TOKENS", {}).get(
"SUPERSET_EXTRA_FILTERS_FORMAT", settings.SUPERSET_EXTRA_FILTERS_FORMAT
)
settings.SUPERSET_DASHBOARD_LOCALES = getattr(settings, "ENV_TOKENS", {}).get(
"SUPERSET_DASHBOARD_LOCALES", settings.SUPERSET_DASHBOARD_LOCALES
)
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG = settings.ENV_TOKENS.get(
"EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG",
settings.EVENT_SINK_CLICKHOUSE_BACKEND_CONFIG,
Expand Down
85 changes: 0 additions & 85 deletions platform_plugin_aspects/settings/tests/test_settings.py

This file was deleted.

Loading
Loading