Skip to content

Commit

Permalink
check roles before fetching reports (#16260)
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Aug 14, 2021
1 parent d46dc9a commit 3709131
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 49 deletions.
50 changes: 26 additions & 24 deletions superset-frontend/src/dashboard/components/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class Header extends React.PureComponent {
componentDidMount() {
const { refreshFrequency, user, dashboardInfo } = this.props;
this.startPeriodicRender(refreshFrequency * 1000);
if (user && isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
if (this.canAddReports()) {
// this is in case there is an anonymous user.
this.props.fetchUISpecificReport(
user.userId,
Expand All @@ -197,7 +197,10 @@ class Header extends React.PureComponent {
) {
this.props.setMaxUndoHistoryExceeded();
}
if (user && nextProps.dashboardInfo.id !== this.props.dashboardInfo.id) {
if (
this.canAddReports() &&
nextProps.dashboardInfo.id !== this.props.dashboardInfo.id
) {
// this is in case there is an anonymous user.
this.props.fetchUISpecificReport(
user.userId,
Expand Down Expand Up @@ -399,32 +402,31 @@ class Header extends React.PureComponent {

renderReportModal() {
const attachedReportExists = !!Object.keys(this.props.reports).length;
const canAddReports = isFeatureEnabled(FeatureFlag.ALERT_REPORTS);
return (
(canAddReports || null) &&
(attachedReportExists ? (
<HeaderReportActionsDropdown
showReportModal={this.showReportModal}
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
/>
) : (
<>
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={this.showReportModal}
>
<Icons.Calendar />
</span>
</>
))
return attachedReportExists ? (
<HeaderReportActionsDropdown
showReportModal={this.showReportModal}
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
/>
) : (
<>
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={this.showReportModal}
>
<Icons.Calendar />
</span>
</>
);
}

canAddReports() {
if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
return false;
}
const { user } = this.props;
if (!user) {
// this is in the case that there is an anonymous user.
Expand Down
49 changes: 24 additions & 25 deletions superset-frontend/src/explore/components/ExploreChartHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ export class ExploreChartHeader extends React.PureComponent {
}

componentDidMount() {
const { user, chart } = this.props;
if (user && isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
if (this.canAddReports()) {
const { user, chart } = this.props;
// this is in the case that there is an anonymous user.
this.props.fetchUISpecificReport(
user.userId,
Expand Down Expand Up @@ -165,33 +165,32 @@ export class ExploreChartHeader extends React.PureComponent {

renderReportModal() {
const attachedReportExists = !!Object.keys(this.props.reports).length;
const canAddReports = isFeatureEnabled(FeatureFlag.ALERT_REPORTS);
return (
(canAddReports || null) &&
(attachedReportExists ? (
<HeaderReportActionsDropdown
showReportModal={this.showReportModal}
hideReportModal={this.hideReportModal}
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
/>
) : (
<>
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={this.showReportModal}
>
<Icons.Calendar />
</span>
</>
))
return attachedReportExists ? (
<HeaderReportActionsDropdown
showReportModal={this.showReportModal}
hideReportModal={this.hideReportModal}
toggleActive={this.props.toggleActive}
deleteActiveReport={this.props.deleteActiveReport}
/>
) : (
<>
<span
role="button"
title={t('Schedule email report')}
tabIndex={0}
className="action-button"
onClick={this.showReportModal}
>
<Icons.Calendar />
</span>
</>
);
}

canAddReports() {
if (!isFeatureEnabled(FeatureFlag.ALERT_REPORTS)) {
return false;
}
const { user } = this.props;
if (!user) {
// this is in the case that there is an anonymous user.
Expand Down

0 comments on commit 3709131

Please sign in to comment.