Skip to content

Commit

Permalink
disable forbidden actions
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Oct 14, 2022
1 parent 4bdcfee commit cb951b1
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions superset-frontend/src/views/CRUD/alert/AlertList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import {
useSingleViewResource,
} from 'src/views/CRUD/hooks';
import { createErrorHandler, createFetchRelated } from 'src/views/CRUD/utils';
import { isUserAdmin } from 'src/dashboard/util/permissionUtils';
import Owner from 'src/types/Owner';
import AlertReportModal from './AlertReportModal';
import { AlertObject, AlertState } from './types';

Expand Down Expand Up @@ -316,14 +318,21 @@ function AlertList({
size: 'xl',
},
{
Cell: ({ row: { original } }: any) => (
<Switch
data-test="toggle-active"
checked={original.active}
onClick={(checked: boolean) => toggleActive(original, checked)}
size="small"
/>
),
Cell: ({ row: { original } }: any) => {
const allowEdit =
original.owners.map((o: Owner) => o.id).includes(user.userId) ||
isUserAdmin(user);

return (
<Switch
disabled={!allowEdit}
data-test="toggle-active"
checked={original.active}
onClick={(checked: boolean) => toggleActive(original, checked)}
size="small"
/>
);
},
Header: t('Active'),
accessor: 'active',
id: 'active',
Expand All @@ -337,6 +346,10 @@ function AlertList({
const handleGotoExecutionLog = () =>
history.push(`/${original.type.toLowerCase()}/${original.id}/log`);

const allowEdit =
original.owners.map((o: Owner) => o.id).includes(user.userId) ||
isUserAdmin(user);

const actions = [
canEdit
? {
Expand All @@ -349,14 +362,14 @@ function AlertList({
: null,
canEdit
? {
label: 'edit-action',
tooltip: t('Edit'),
label: allowEdit ? 'edit-action' : 'preview-action',
tooltip: allowEdit ? t('Edit') : t('View'),
placement: 'bottom',
icon: 'Edit',
icon: allowEdit ? 'Edit' : 'Binoculars',
onClick: handleEdit,
}
: null,
canDelete
allowEdit && canDelete
? {
label: 'delete-action',
tooltip: t('Delete'),
Expand Down

0 comments on commit cb951b1

Please sign in to comment.