mirror of https://github.com/apache/superset.git
chore(thumbnails): change default executor to logged in user (#22801)
This commit is contained in:
parent
66fb4867dc
commit
7114bba718
|
@ -50,6 +50,7 @@ assists people when migrating to a new version.
|
|||
|
||||
### Breaking Changes
|
||||
|
||||
- [22801](https://github.com/apache/superset/pull/22801): The Thumbnails feature has been changed to execute as the currently logged in user by default, falling back to the selenium user for anonymous users. To continue always using the selenium user, please add the following to your `superset_config.py`: `THUMBNAILS_EXECUTE_AS = ["selenium"]`
|
||||
- [22799](https://github.com/apache/superset/pull/22799): Alerts & Reports has been changed to execute as the owner of the alert/report by default, giving priority to the last modifier and then the creator if either is contained within the list of owners, otherwise the first owner will be used. To continue using the selenium user, please add the following to your `superset_config.py`: `ALERT_REPORTS_EXECUTE_AS = ["selenium"]`
|
||||
- [23651](https://github.com/apache/superset/pull/23651): Removes UX_BETA feature flag.
|
||||
- [23663](https://github.com/apache/superset/pull/23663): Removes deprecated feature flags `ALLOW_DASHBOARD_DOMAIN_SHARDING`, `DISPLAY_MARKDOWN_HTML`, and `FORCE_DATABASE_CONNECTIONS_SSL`.
|
||||
|
|
|
@ -90,13 +90,17 @@ FEATURE_FLAGS = {
|
|||
}
|
||||
```
|
||||
|
||||
By default thumbnails are rendered using the `THUMBNAIL_SELENIUM_USER` user account. To render thumbnails as the
|
||||
logged in user (e.g. in environments that are using user impersonation), use the following configuration:
|
||||
By default thumbnails are rendered per user, and will fall back to the Selenium user for anonymous users.
|
||||
To always render thumbnails as a fixed user (`admin` in this example), use the following configuration:
|
||||
|
||||
```python
|
||||
THUMBNAIL_EXECUTE_AS = [ExecutorType.CURRENT_USER]
|
||||
from superset.tasks.types import ExecutorType
|
||||
|
||||
THUMBNAIL_SELENIUM_USER = "admin"
|
||||
THUMBNAIL_EXECUTE_AS = [ExecutorType.SELENIUM]
|
||||
```
|
||||
|
||||
|
||||
For this feature you will need a cache system and celery workers. All thumbnails are stored on cache
|
||||
and are processed asynchronously by the workers.
|
||||
|
||||
|
|
|
@ -619,16 +619,14 @@ EXTRA_SEQUENTIAL_COLOR_SCHEMES: List[Dict[str, Any]] = []
|
|||
# ---------------------------------------------------
|
||||
# Thumbnail config (behind feature flag)
|
||||
# ---------------------------------------------------
|
||||
# When executing Alerts & Reports or Thumbnails as the Selenium user, this defines
|
||||
# the username of the account used to render the queries and dashboards/charts
|
||||
# By default, thumbnails are rendered per user, and will fall back to the Selenium
|
||||
# user for anonymous users. Similar to Alerts & Reports, thumbnails
|
||||
# can be configured to always be rendered as a fixed user. See
|
||||
# `superset.tasks.types.ExecutorType` for a full list of executor options.
|
||||
# To always use a fixed user account, use the following configuration:
|
||||
# THUMBNAIL_EXECUTE_AS = [ExecutorType.SELENIUM]
|
||||
THUMBNAIL_SELENIUM_USER: Optional[str] = "admin"
|
||||
|
||||
# To be able to have different thumbnails for different users, use these configs to
|
||||
# define which user to execute the thumbnails and potentially custom functions for
|
||||
# calculating thumbnail digests. To have unique thumbnails for all users, use the
|
||||
# following config:
|
||||
# THUMBNAIL_EXECUTE_AS = [ExecutorType.CURRENT_USER]
|
||||
THUMBNAIL_EXECUTE_AS = [ExecutorType.SELENIUM]
|
||||
THUMBNAIL_EXECUTE_AS = [ExecutorType.CURRENT_USER, ExecutorType.SELENIUM]
|
||||
|
||||
# By default, thumbnail digests are calculated based on various parameters in the
|
||||
# chart/dashboard metadata, and in the case of user-specific thumbnails, the
|
||||
|
|
|
@ -36,7 +36,7 @@ from superset.models.dashboard import Dashboard
|
|||
from superset.models.core import FavStar, FavStarClassName
|
||||
from superset.reports.models import ReportSchedule, ReportScheduleType
|
||||
from superset.models.slice import Slice
|
||||
from superset.utils.core import backend
|
||||
from superset.utils.core import backend, override_user
|
||||
from superset.views.base import generate_download_headers
|
||||
|
||||
from tests.integration_tests.base_api_tests import ApiOwnersTestCaseMixin
|
||||
|
@ -404,39 +404,41 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
|
|||
uri = f"api/v1/dashboard/{dashboard.id}"
|
||||
rv = self.get_assert_metric(uri, "get")
|
||||
self.assertEqual(rv.status_code, 200)
|
||||
expected_result = {
|
||||
"certified_by": None,
|
||||
"certification_details": None,
|
||||
"changed_by": None,
|
||||
"changed_by_name": "",
|
||||
"changed_by_url": "",
|
||||
"charts": [],
|
||||
"created_by": {
|
||||
"id": 1,
|
||||
"first_name": "admin",
|
||||
"last_name": "user",
|
||||
},
|
||||
"id": dashboard.id,
|
||||
"css": "",
|
||||
"dashboard_title": "title",
|
||||
"datasources": [],
|
||||
"json_metadata": "",
|
||||
"owners": [
|
||||
{
|
||||
with override_user(admin):
|
||||
expected_result = {
|
||||
"certified_by": None,
|
||||
"certification_details": None,
|
||||
"changed_by": None,
|
||||
"changed_by_name": "",
|
||||
"changed_by_url": "",
|
||||
"charts": [],
|
||||
"created_by": {
|
||||
"id": 1,
|
||||
"first_name": "admin",
|
||||
"last_name": "user",
|
||||
}
|
||||
],
|
||||
"roles": [],
|
||||
"position_json": "",
|
||||
"published": False,
|
||||
"url": "/superset/dashboard/slug1/",
|
||||
"slug": "slug1",
|
||||
"tags": [],
|
||||
"thumbnail_url": dashboard.thumbnail_url,
|
||||
"is_managed_externally": False,
|
||||
}
|
||||
},
|
||||
"id": dashboard.id,
|
||||
"css": "",
|
||||
"dashboard_title": "title",
|
||||
"datasources": [],
|
||||
"json_metadata": "",
|
||||
"owners": [
|
||||
{
|
||||
"id": 1,
|
||||
"username": "admin",
|
||||
"first_name": "admin",
|
||||
"last_name": "user",
|
||||
}
|
||||
],
|
||||
"roles": [],
|
||||
"position_json": "",
|
||||
"published": False,
|
||||
"url": "/superset/dashboard/slug1/",
|
||||
"slug": "slug1",
|
||||
"tags": [],
|
||||
"thumbnail_url": dashboard.thumbnail_url,
|
||||
"is_managed_externally": False,
|
||||
}
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertIn("changed_on", data["result"])
|
||||
self.assertIn("changed_on_delta_humanized", data["result"])
|
||||
|
|
|
@ -58,13 +58,12 @@ def test_report_for_dashboard_with_tabs(
|
|||
).run()
|
||||
dashboard_state = report_schedule.extra.get("dashboard", {})
|
||||
permalink_key = CreateDashboardPermalinkCommand(
|
||||
dashboard.id, dashboard_state
|
||||
str(dashboard.id), dashboard_state
|
||||
).run()
|
||||
|
||||
assert dashboard_screenshot_mock.call_count == 1
|
||||
(url, digest) = dashboard_screenshot_mock.call_args.args
|
||||
url = dashboard_screenshot_mock.call_args.args[0]
|
||||
assert url.endswith(f"/superset/dashboard/p/{permalink_key}/")
|
||||
assert digest == dashboard.digest
|
||||
assert send_email_smtp_mock.call_count == 1
|
||||
assert len(send_email_smtp_mock.call_args.kwargs["images"]) == 1
|
||||
|
||||
|
@ -101,9 +100,8 @@ def test_report_with_header_data(
|
|||
).run()
|
||||
|
||||
assert dashboard_screenshot_mock.call_count == 1
|
||||
(url, digest) = dashboard_screenshot_mock.call_args.args
|
||||
url = dashboard_screenshot_mock.call_args.args[0]
|
||||
assert url.endswith(f"/superset/dashboard/p/{permalink_key}/")
|
||||
assert digest == dashboard.digest
|
||||
assert send_email_smtp_mock.call_count == 1
|
||||
header_data = send_email_smtp_mock.call_args.kwargs["header_data"]
|
||||
assert header_data.get("dashboard_id") == dashboard.id
|
||||
|
|
|
@ -238,7 +238,12 @@ class TestThumbnails(SupersetTestCase):
|
|||
Thumbnails: Simple get async dashboard screenshot as selenium user
|
||||
"""
|
||||
self.login(username="alpha")
|
||||
with patch(
|
||||
with patch.dict(
|
||||
"superset.thumbnails.digest.current_app.config",
|
||||
{
|
||||
"THUMBNAIL_EXECUTE_AS": [ExecutorType.SELENIUM],
|
||||
},
|
||||
), patch(
|
||||
"superset.thumbnails.digest._adjust_string_for_executor"
|
||||
) as mock_adjust_string:
|
||||
mock_adjust_string.return_value = self.digest_return_value
|
||||
|
@ -305,7 +310,12 @@ class TestThumbnails(SupersetTestCase):
|
|||
Thumbnails: Simple get async chart screenshot as selenium user
|
||||
"""
|
||||
self.login(username="alpha")
|
||||
with patch(
|
||||
with patch.dict(
|
||||
"superset.thumbnails.digest.current_app.config",
|
||||
{
|
||||
"THUMBNAIL_EXECUTE_AS": [ExecutorType.SELENIUM],
|
||||
},
|
||||
), patch(
|
||||
"superset.thumbnails.digest._adjust_string_for_executor"
|
||||
) as mock_adjust_string:
|
||||
mock_adjust_string.return_value = self.digest_return_value
|
||||
|
|
Loading…
Reference in New Issue