Skip to content
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: do not render favorite favStars and filters for anonymous user #14120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions superset-frontend/src/explore/components/ExploreChartHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,15 @@ export class ExploreChartHeader extends React.PureComponent {

{this.props.slice && (
<StyledButtons>
<FaveStar
itemId={this.props.slice.slice_id}
fetchFaveStar={this.props.actions.fetchFaveStar}
saveFaveStar={this.props.actions.saveFaveStar}
isStarred={this.props.isStarred}
showTooltip
/>
{this.props.userId && (
<FaveStar
itemId={this.props.slice.slice_id}
fetchFaveStar={this.props.actions.fetchFaveStar}
saveFaveStar={this.props.actions.saveFaveStar}
isStarred={this.props.isStarred}
showTooltip
/>
)}
<PropertiesModal
show={this.state.isPropertiesModalOpen}
onHide={this.closePropertiesModal}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ const ExploreChartPanel = props => {
form_data={props.form_data}
timeout={props.timeout}
chart={props.chart}
userId={props.userId}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ function mapStateToProps(state) {
timeout: explore.common.conf.SUPERSET_WEBSERVER_TIMEOUT,
ownState: dataMask[form_data.slice_id]?.ownState,
impressionId,
userId: explore.user_id,
};
}

Expand Down
72 changes: 42 additions & 30 deletions superset-frontend/src/views/CRUD/chart/ChartList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import SubMenu, { SubMenuProps } from 'src/components/Menu/SubMenu';
import FaveStar from 'src/components/FaveStar';
import ListView, {
ListViewProps,
Filter,
Filters,
SelectOption,
FilterOperator,
Expand Down Expand Up @@ -195,23 +196,27 @@ function ChartList(props: ChartListProps) {

const columns = useMemo(
() => [
{
Cell: ({
row: {
original: { id },
},
}: any) => (
<FaveStar
itemId={id}
saveFaveStar={saveFavoriteStatus}
isStarred={favoriteStatus[id]}
/>
),
Header: '',
id: 'id',
disableSortBy: true,
size: 'xs',
},
...(props.user.userId
? [
{
Cell: ({
row: {
original: { id },
},
}: any) => (
<FaveStar
itemId={id}
saveFaveStar={saveFavoriteStatus}
isStarred={favoriteStatus[id]}
/>
),
Header: '',
id: 'id',
disableSortBy: true,
size: 'xs',
},
]
: []),
{
Cell: ({
row: {
Expand Down Expand Up @@ -377,9 +382,27 @@ function ChartList(props: ChartListProps) {
hidden: !canEdit && !canDelete,
},
],
[canEdit, canDelete, canExport, favoriteStatus],
[
canEdit,
canDelete,
canExport,
...(props.user.userId ? [favoriteStatus] : []),
],
);

const favoritesFilter: Filter = {
Header: t('Favorite'),
id: 'id',
urlDisplay: 'favorite',
input: 'select',
operator: FilterOperator.chartIsFav,
unfilteredLabel: t('Any'),
selects: [
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
],
};

const filters: Filters = [
{
Header: t('Owner'),
Expand Down Expand Up @@ -465,18 +488,7 @@ function ChartList(props: ChartListProps) {
),
paginate: false,
},
{
Header: t('Favorite'),
id: 'id',
urlDisplay: 'favorite',
input: 'select',
operator: FilterOperator.chartIsFav,
unfilteredLabel: t('Any'),
selects: [
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
],
},
...(props.user.userId ? [favoritesFilter] : []),
{
Header: t('Search'),
id: 'slice_name',
Expand Down
72 changes: 42 additions & 30 deletions superset-frontend/src/views/CRUD/dashboard/DashboardList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import ConfirmStatusChange from 'src/components/ConfirmStatusChange';
import SubMenu, { SubMenuProps } from 'src/components/Menu/SubMenu';
import ListView, {
ListViewProps,
Filter,
Filters,
FilterOperator,
} from 'src/components/ListView';
Expand Down Expand Up @@ -189,23 +190,27 @@ function DashboardList(props: DashboardListProps) {

const columns = useMemo(
() => [
{
Cell: ({
row: {
original: { id },
},
}: any) => (
<FaveStar
itemId={id}
saveFaveStar={saveFavoriteStatus}
isStarred={favoriteStatus[id]}
/>
),
Header: '',
id: 'id',
disableSortBy: true,
size: 'xs',
},
...(props.user.userId
? [
{
Cell: ({
row: {
original: { id },
},
}: any) => (
<FaveStar
itemId={id}
saveFaveStar={saveFavoriteStatus}
isStarred={favoriteStatus[id]}
/>
),
Header: '',
id: 'id',
disableSortBy: true,
size: 'xs',
},
]
: []),
{
Cell: ({
row: {
Expand Down Expand Up @@ -357,9 +362,27 @@ function DashboardList(props: DashboardListProps) {
disableSortBy: true,
},
],
[canEdit, canDelete, canExport, favoriteStatus],
[
canEdit,
canDelete,
canExport,
...(props.user.userId ? [favoriteStatus] : []),
],
);

const favoritesFilter: Filter = {
Header: t('Favorite'),
id: 'id',
urlDisplay: 'favorite',
input: 'select',
operator: FilterOperator.dashboardIsFav,
unfilteredLabel: t('Any'),
selects: [
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
],
};

const filters: Filters = [
{
Header: t('Owner'),
Expand Down Expand Up @@ -414,18 +437,7 @@ function DashboardList(props: DashboardListProps) {
{ label: t('Draft'), value: false },
],
},
{
Header: t('Favorite'),
id: 'id',
urlDisplay: 'favorite',
input: 'select',
operator: FilterOperator.dashboardIsFav,
unfilteredLabel: t('Any'),
selects: [
{ label: t('Yes'), value: true },
{ label: t('No'), value: false },
],
},
...(props.user.userId ? [favoritesFilter] : []),
{
Header: t('Search'),
id: 'dashboard_title',
Expand Down
2 changes: 2 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,8 @@ def favstar( # pylint: disable=no-self-use
self, class_name: str, obj_id: int, action: str
) -> FlaskResponse:
"""Toggle favorite stars on Slices and Dashboard"""
if not g.user.get_id():
return json_error_response("ERROR: Favstar toggling denied", status=403)
session = db.session()
count = 0
favs = (
Expand Down