-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
fix(alerts): restrict list view and gamma perms #21765
Changes from all commits
e6b6799
9d928a8
8678320
ca2939f
fbd2e2d
24409b0
4bdcfee
cb951b1
c2761a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,7 +68,7 @@ | |
from superset.reports.notifications.base import NotificationContent | ||
from superset.reports.notifications.exceptions import NotificationError | ||
from superset.utils.celery import session_scope | ||
from superset.utils.core import HeaderDataType | ||
from superset.utils.core import HeaderDataType, override_user | ||
from superset.utils.csv import get_chart_csv_data, get_chart_dataframe | ||
from superset.utils.screenshots import ChartScreenshot, DashboardScreenshot | ||
from superset.utils.urls import get_url_path | ||
|
@@ -77,6 +77,13 @@ | |
logger = logging.getLogger(__name__) | ||
|
||
|
||
def _get_user() -> User: | ||
user = security_manager.find_user(username=app.config["THUMBNAIL_SELENIUM_USER"]) | ||
if not user: | ||
raise ReportScheduleSelleniumUserNotFoundError() | ||
return user | ||
|
||
|
||
class BaseReportState: | ||
current_states: List[ReportState] = [] | ||
initial: bool = False | ||
|
@@ -193,22 +200,13 @@ def _get_url( | |
**kwargs, | ||
) | ||
|
||
@staticmethod | ||
def _get_user() -> User: | ||
user = security_manager.find_user( | ||
username=app.config["THUMBNAIL_SELENIUM_USER"] | ||
) | ||
if not user: | ||
raise ReportScheduleSelleniumUserNotFoundError() | ||
return user | ||
|
||
def _get_screenshots(self) -> List[bytes]: | ||
""" | ||
Get chart or dashboard screenshots | ||
:raises: ReportScheduleScreenshotFailedError | ||
""" | ||
url = self._get_url() | ||
user = self._get_user() | ||
user = _get_user() | ||
if self._report_schedule.chart: | ||
screenshot: Union[ChartScreenshot, DashboardScreenshot] = ChartScreenshot( | ||
url, | ||
|
@@ -239,7 +237,7 @@ def _get_screenshots(self) -> List[bytes]: | |
def _get_csv_data(self) -> bytes: | ||
url = self._get_url(result_format=ChartDataResultFormat.CSV) | ||
auth_cookies = machine_auth_provider_factory.instance.get_auth_cookies( | ||
self._get_user() | ||
_get_user() | ||
) | ||
|
||
if self._report_schedule.chart.query_context is None: | ||
|
@@ -265,7 +263,7 @@ def _get_embedded_data(self) -> pd.DataFrame: | |
""" | ||
url = self._get_url(result_format=ChartDataResultFormat.JSON) | ||
auth_cookies = machine_auth_provider_factory.instance.get_auth_cookies( | ||
self._get_user() | ||
_get_user() | ||
) | ||
|
||
if self._report_schedule.chart.query_context is None: | ||
|
@@ -679,12 +677,13 @@ def __init__(self, task_id: str, model_id: int, scheduled_dttm: datetime): | |
def run(self) -> None: | ||
with session_scope(nullpool=True) as session: | ||
try: | ||
self.validate(session=session) | ||
if not self._model: | ||
raise ReportScheduleExecuteUnexpectedError() | ||
ReportScheduleStateMachine( | ||
session, self._execution_id, self._model, self._scheduled_dttm | ||
).run() | ||
with override_user(_get_user()): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this method always runs on a celery async context I see no issue here, but what are we trying to solve? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think it for switching current user to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @zhaoyongjie yes it switches the user, just wondering why we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
self.validate(session=session) | ||
if not self._model: | ||
raise ReportScheduleExecuteUnexpectedError() | ||
ReportScheduleStateMachine( | ||
session, self._execution_id, self._model, self._scheduled_dttm | ||
).run() | ||
except CommandException as ex: | ||
raise ex | ||
except Exception as ex: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@villebro I wonder if someone were to read this entry without seeing your explanation in the PR, if they would think that they need to grant access to Gamma users to keep the same functionality that we have now. This is tricky, because to most people it won't look like a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point - I'll make the entry more explicit, specifically scoping this to deployments that have enabled the "ALERT_REPORTS" feature flag.