diff --git a/README.rst b/README.rst index dd5e82d..6809585 100644 --- a/README.rst +++ b/README.rst @@ -240,6 +240,21 @@ Postgresql/Superset settings - ``CAIRN_POSTGRESQL_PASSWORD`` (default: ``"{{ 20|random_string }}"``): Postgresql password. - ``CAIRN_SUPERSET_SECRET_KEY`` (default: ``"{{ 20|random_string }}"``): randomly-generated secret key for the Superset frontend. +Add/Update Superset Configurations +---------------------------------- + +Use ``cairn-superset-settings`` patch to add or update `Superset configurations `__. + +e.g, to customize visualizations, add following configurations in ``cairn-superset-settings`` patch:: + + APP_NAME = "" + APP_ICON = "" + APP_ICON_WIDTH = + +Then apply changes with:: + + tutor local launch + Troubleshooting --------------- diff --git a/changelog.d/20240416_165758_fahad.khalid.md b/changelog.d/20240416_165758_fahad.khalid.md new file mode 100644 index 0000000..26e2291 --- /dev/null +++ b/changelog.d/20240416_165758_fahad.khalid.md @@ -0,0 +1 @@ +- [Improvement] Added CORS for embeded Dashboards. (by @Fahadkhalid210) \ No newline at end of file diff --git a/changelog.d/20240429_155841_fahad.khalid_fahad_clickhouse_30.md b/changelog.d/20240429_155841_fahad.khalid_fahad_clickhouse_30.md new file mode 100644 index 0000000..40caf76 --- /dev/null +++ b/changelog.d/20240429_155841_fahad.khalid_fahad_clickhouse_30.md @@ -0,0 +1 @@ +- 💥[Feature] Upgrade Clickhouse version to `24.1.8.22` and fix query issues due to deprecation of Live views. (by @Fahadkhalid210) diff --git a/tutorcairn/templates/cairn/apps/clickhouse/migrations.d/0012_modify_course_enrollments.sql b/tutorcairn/templates/cairn/apps/clickhouse/migrations.d/0012_modify_course_enrollments.sql new file mode 100644 index 0000000..75cc839 --- /dev/null +++ b/tutorcairn/templates/cairn/apps/clickhouse/migrations.d/0012_modify_course_enrollments.sql @@ -0,0 +1,23 @@ +RENAME TABLE _openedx_course_enrollments TO openedx_course_enrollments; +RENAME TABLE _openedx_user_profiles TO openedx_user_profiles; +RENAME TABLE _openedx_users TO openedx_users; + +DROP TABLE course_enrollments; +CREATE VIEW course_enrollments AS +SELECT + openedx_course_enrollments.course_id AS course_id, + openedx_course_enrollments.created AS enrollment_created, + openedx_course_enrollments.is_active AS enrollment_is_active, + openedx_course_enrollments.mode AS enrollment_mode, + openedx_course_enrollments.user_id AS user_id, + openedx_users.username AS username, + openedx_users.email AS user_email, + openedx_user_profiles.year_of_birth AS user_year_of_birth, + openedx_user_profiles.gender AS user_gender, + openedx_user_profiles.level_of_education AS user_level_of_education, + openedx_user_profiles.city AS user_city, + openedx_user_profiles.state AS user_state, + openedx_user_profiles.country AS user_country +FROM openedx_course_enrollments +INNER JOIN openedx_user_profiles ON openedx_course_enrollments.user_id = openedx_user_profiles.user_id +INNER JOIN openedx_users ON openedx_course_enrollments.user_id = openedx_users.id; diff --git a/tutorcairn/templates/cairn/apps/clickhouse/migrations.d/0013_modify_course_block_completion.sql b/tutorcairn/templates/cairn/apps/clickhouse/migrations.d/0013_modify_course_block_completion.sql new file mode 100644 index 0000000..523530b --- /dev/null +++ b/tutorcairn/templates/cairn/apps/clickhouse/migrations.d/0013_modify_course_block_completion.sql @@ -0,0 +1,15 @@ +RENAME TABLE _openedx_block_completion TO openedx_block_completion; + +DROP TABLE course_block_completion; + +CREATE VIEW course_block_completion AS +SELECT + openedx_block_completion.course_key AS course_id, + openedx_block_completion.block_key AS block_key, + openedx_block_completion.user_id AS user_id, + openedx_block_completion.completion AS completion, + course_blocks.position as position, + course_blocks.display_name as display_name, + course_blocks.full_name as full_name +FROM openedx_block_completion +INNER JOIN course_blocks ON openedx_block_completion.block_key = course_blocks.block_key; diff --git a/tutorcairn/templates/cairn/apps/superset/superset_config.py b/tutorcairn/templates/cairn/apps/superset/superset_config.py index 30ae194..1aa11d6 100644 --- a/tutorcairn/templates/cairn/apps/superset/superset_config.py +++ b/tutorcairn/templates/cairn/apps/superset/superset_config.py @@ -84,6 +84,12 @@ db=REDIS_CACHE_DB, key_prefix="superset_results", ) +OPENEDX_LMS_ROOT_URL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}" +OPENEDX_CMS_ROOT_URL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ CMS_HOST }}" + +if os.environ.get("FLASK_ENV") == "development": + OPENEDX_LMS_ROOT_URL = "http://{{ LMS_HOST }}:8000" + OPENEDX_CMS_ROOT_URL = "http://{{ CMS_HOST }}:8001" {% if CAIRN_ENABLE_SSO %} # Authentication @@ -91,10 +97,9 @@ # https://flask-appbuilder.readthedocs.io/en/latest/security.html#authentication-oauth from flask_appbuilder.security.manager import AUTH_OAUTH AUTH_TYPE = AUTH_OAUTH -OPENEDX_LMS_ROOT_URL = "{% if ENABLE_HTTPS %}https{% else %}http{% endif %}://{{ LMS_HOST }}" + OPENEDX_SSO_CLIENT_ID = "{{ CAIRN_SSO_CLIENT_ID }}" if os.environ.get("FLASK_ENV") == "development": - OPENEDX_LMS_ROOT_URL = "http://{{ LMS_HOST }}:8000" OPENEDX_SSO_CLIENT_ID = "{{ CAIRN_SSO_CLIENT_ID }}-dev" OAUTH_PROVIDERS = [ { @@ -162,4 +167,12 @@ class CeleryConfig: # pylint: disable=too-few-public-methods "EMBEDDED_SUPERSET": True } +ENABLE_CORS=True +CORS_OPTIONS={ + "origins": [ + f"{OPENEDX_LMS_ROOT_URL}", + f"{OPENEDX_CMS_ROOT_URL}" + ], +} + {{ patch("cairn-superset-settings") }} diff --git a/tutorcairn/templates/cairn/build/cairn-clickhouse/Dockerfile b/tutorcairn/templates/cairn/build/cairn-clickhouse/Dockerfile index 32af310..ab8edf9 100644 --- a/tutorcairn/templates/cairn/build/cairn-clickhouse/Dockerfile +++ b/tutorcairn/templates/cairn/build/cairn-clickhouse/Dockerfile @@ -1,11 +1,6 @@ -# https://hub.docker.com/r/yandex/clickhouse-server/tags -FROM docker.io/yandex/clickhouse-server:22.1.3.7 +# https://hub.docker.com/r/clickhouse/clickhouse-server/tags +FROM docker.io/clickhouse/clickhouse-server:24.1.8.22 -# The clickhouse repo is currently unavailable in some parts of the world. If we don't -# remove this repo here then `apt update` will fail. Check if the problem is resolved with: -# curl https://repo.yandex.ru/clickhouse/deb/stable/ -# The above command should be a 200, and not a 404. -RUN rm /etc/apt/sources.list.d/clickhouse.list RUN apt update && apt install -y python3 COPY ./scripts /scripts RUN chmod a+x /scripts/* diff --git a/tutorcairn/templates/cairn/build/cairn-superset/cairn/bootstrap.py b/tutorcairn/templates/cairn/build/cairn-superset/cairn/bootstrap.py index 25ba62f..f88fab7 100644 --- a/tutorcairn/templates/cairn/build/cairn-superset/cairn/bootstrap.py +++ b/tutorcairn/templates/cairn/build/cairn-superset/cairn/bootstrap.py @@ -117,11 +117,17 @@ def grant_clickhouse_row_based_access(clickhouse_username, course_ids=None): for table in make_clickhouse_query("SHOW TABLES").split("\n"): if not table.startswith("_"): make_clickhouse_query( - f"""GRANT SELECT ON {table} TO '{clickhouse_username}';""" - ) - make_clickhouse_query( - f"""CREATE ROW POLICY OR REPLACE '{clickhouse_username}' ON {table} AS RESTRICTIVE FOR SELECT USING {condition} TO '{clickhouse_username}';""" - ) + f"""GRANT SELECT ON {table} TO '{clickhouse_username}';""" + ) + + if table in ["openedx_users", "openedx_user_profiles", "openedx_block_completion"]: + make_clickhouse_query( + f"""CREATE ROW POLICY OR REPLACE '{clickhouse_username}' ON {table} AS RESTRICTIVE FOR SELECT USING 1 TO '{clickhouse_username}';""" + ) + else: + make_clickhouse_query( + f"""CREATE ROW POLICY OR REPLACE '{clickhouse_username}' ON {table} AS RESTRICTIVE FOR SELECT USING {condition} TO '{clickhouse_username}';""" + ) def make_clickhouse_query(query):