mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
feat(reports): execute as other than selenium user (#21931)
Co-authored-by: Ville Brofeldt <ville.brofeldt@apple.com>
This commit is contained in:
@@ -35,26 +35,27 @@ from superset.reports.models import (
|
||||
ReportScheduleType,
|
||||
ReportState,
|
||||
)
|
||||
from superset.utils.core import override_user
|
||||
from tests.integration_tests.test_app import app
|
||||
from tests.integration_tests.utils import read_fixture
|
||||
|
||||
TEST_ID = str(uuid4())
|
||||
CSV_FILE = read_fixture("trends.csv")
|
||||
SCREENSHOT_FILE = read_fixture("sample.png")
|
||||
OWNER_EMAIL = "admin@fab.org"
|
||||
DEFAULT_OWNER_EMAIL = "admin@fab.org"
|
||||
|
||||
|
||||
def insert_report_schedule(
|
||||
type: str,
|
||||
name: str,
|
||||
crontab: str,
|
||||
owners: List[User],
|
||||
timezone: Optional[str] = None,
|
||||
sql: Optional[str] = None,
|
||||
description: Optional[str] = None,
|
||||
chart: Optional[Slice] = None,
|
||||
dashboard: Optional[Dashboard] = None,
|
||||
database: Optional[Database] = None,
|
||||
owners: Optional[List[User]] = None,
|
||||
validator_type: Optional[str] = None,
|
||||
validator_config_json: Optional[str] = None,
|
||||
log_retention: Optional[int] = None,
|
||||
@@ -70,28 +71,30 @@ def insert_report_schedule(
|
||||
recipients = recipients or []
|
||||
logs = logs or []
|
||||
last_state = last_state or ReportState.NOOP
|
||||
report_schedule = ReportSchedule(
|
||||
type=type,
|
||||
name=name,
|
||||
crontab=crontab,
|
||||
timezone=timezone,
|
||||
sql=sql,
|
||||
description=description,
|
||||
chart=chart,
|
||||
dashboard=dashboard,
|
||||
database=database,
|
||||
owners=owners,
|
||||
validator_type=validator_type,
|
||||
validator_config_json=validator_config_json,
|
||||
log_retention=log_retention,
|
||||
grace_period=grace_period,
|
||||
recipients=recipients,
|
||||
logs=logs,
|
||||
last_state=last_state,
|
||||
report_format=report_format,
|
||||
extra=extra,
|
||||
force_screenshot=force_screenshot,
|
||||
)
|
||||
|
||||
with override_user(owners[0]):
|
||||
report_schedule = ReportSchedule(
|
||||
type=type,
|
||||
name=name,
|
||||
crontab=crontab,
|
||||
timezone=timezone,
|
||||
sql=sql,
|
||||
description=description,
|
||||
chart=chart,
|
||||
dashboard=dashboard,
|
||||
database=database,
|
||||
owners=owners,
|
||||
validator_type=validator_type,
|
||||
validator_config_json=validator_config_json,
|
||||
log_retention=log_retention,
|
||||
grace_period=grace_period,
|
||||
recipients=recipients,
|
||||
logs=logs,
|
||||
last_state=last_state,
|
||||
report_format=report_format,
|
||||
extra=extra,
|
||||
force_screenshot=force_screenshot,
|
||||
)
|
||||
db.session.add(report_schedule)
|
||||
db.session.commit()
|
||||
return report_schedule
|
||||
@@ -112,12 +115,16 @@ def create_report_notification(
|
||||
name: Optional[str] = None,
|
||||
extra: Optional[Dict[str, Any]] = None,
|
||||
force_screenshot: bool = False,
|
||||
owners: Optional[List[User]] = None,
|
||||
) -> ReportSchedule:
|
||||
owner = (
|
||||
db.session.query(security_manager.user_model)
|
||||
.filter_by(email=OWNER_EMAIL)
|
||||
.one_or_none()
|
||||
)
|
||||
if not owners:
|
||||
owners = [
|
||||
(
|
||||
db.session.query(security_manager.user_model)
|
||||
.filter_by(email=DEFAULT_OWNER_EMAIL)
|
||||
.one_or_none()
|
||||
)
|
||||
]
|
||||
|
||||
if slack_channel:
|
||||
recipient = ReportRecipients(
|
||||
@@ -147,7 +154,7 @@ def create_report_notification(
|
||||
dashboard=dashboard,
|
||||
database=database,
|
||||
recipients=[recipient],
|
||||
owners=[owner],
|
||||
owners=owners,
|
||||
validator_type=validator_type,
|
||||
validator_config_json=validator_config_json,
|
||||
grace_period=grace_period,
|
||||
|
||||
Reference in New Issue
Block a user