Skip to content

Commit

Permalink
Don't show grid actions if server would reject with permission denied (
Browse files Browse the repository at this point in the history
…#23332)

* Add edit permission check for grid actions

* Remove if wrapper for meta tag

* Use dag.can_edit

(cherry picked from commit 67e8bdd)
  • Loading branch information
bbovenzi authored and ephraimbuddy committed May 21, 2022
1 parent 427a125 commit 84021de
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 27 deletions.
33 changes: 19 additions & 14 deletions airflow/www/static/js/tree/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ const Table = ({
const lowerCount = (offset || 0) + 1;
const upperCount = lowerCount + data.length - 1;

// Don't show row selection if selectRows doesn't exist
const selectProps = selectRows
? [useRowSelect,
(hooks) => {
hooks.visibleColumns.push((cols) => [
{
id: 'selection',
Cell: ({ row }) => (
<div>
<IndeterminateCheckbox {...row.getToggleRowSelectedProps()} />
</div>
),
},
...cols,
]);
}]
: [];

const {
getTableProps,
getTableBodyProps,
Expand All @@ -98,20 +116,7 @@ const Table = ({
},
useSortBy,
usePagination,
useRowSelect,
(hooks) => {
hooks.visibleColumns.push((cols) => [
{
id: 'selection',
Cell: ({ row }) => (
<div>
<IndeterminateCheckbox {...row.getToggleRowSelectedProps()} />
</div>
),
},
...cols,
]);
},
...selectProps,
);

const handleNext = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const ConfirmDialog = ({

<AlertDialogBody>
<Text mb={2}>{description}</Text>
{body.map((ti) => (<Code key={ti} fontSize="lg">{ti}</Code>))}
{Array.isArray(body) && body.map((ti) => (<Code key={ti} fontSize="lg">{ti}</Code>))}
</AlertDialogBody>

<AlertDialogFooter>
Expand Down
11 changes: 10 additions & 1 deletion airflow/www/static/js/tree/details/content/dagRun/ClearRun.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { Button, useDisclosure } from '@chakra-ui/react';

import { useClearRun } from '../../../api';
import ConfirmDialog from '../ConfirmDialog';
import { getMetaValue } from '../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const ClearRun = ({ dagId, runId }) => {
const [affectedTasks, setAffectedTasks] = useState([]);
Expand All @@ -42,7 +45,13 @@ const ClearRun = ({ dagId, runId }) => {

return (
<>
<Button onClick={onClick} isLoading={isLoading}>Clear existing tasks</Button>
<Button
onClick={onClick}
isLoading={isLoading}
isDisabled={!canEdit}
>
Clear existing tasks
</Button>
<ConfirmDialog
isOpen={isOpen}
onClose={onClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { Button, useDisclosure } from '@chakra-ui/react';

import { useMarkFailedRun } from '../../../api';
import ConfirmDialog from '../ConfirmDialog';
import { getMetaValue } from '../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const MarkFailedRun = ({ dagId, runId }) => {
const [affectedTasks, setAffectedTasks] = useState([]);
Expand All @@ -42,7 +45,7 @@ const MarkFailedRun = ({ dagId, runId }) => {

return (
<>
<Button onClick={onClick} colorScheme="red" isLoading={isLoading}>Mark Failed</Button>
<Button onClick={onClick} colorScheme="red" isLoading={isLoading} isDisabled={!canEdit}>Mark Failed</Button>
<ConfirmDialog
isOpen={isOpen}
onClose={onClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { Button, useDisclosure } from '@chakra-ui/react';

import { useMarkSuccessRun } from '../../../api';
import ConfirmDialog from '../ConfirmDialog';
import { getMetaValue } from '../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const MarkSuccessRun = ({ dagId, runId }) => {
const [affectedTasks, setAffectedTasks] = useState([]);
Expand All @@ -42,7 +45,7 @@ const MarkSuccessRun = ({ dagId, runId }) => {

return (
<>
<Button onClick={onClick} colorScheme="green" isLoading={isLoading}>Mark Success</Button>
<Button onClick={onClick} colorScheme="green" isLoading={isLoading} isDisabled={!canEdit}>Mark Success</Button>
<ConfirmDialog
isOpen={isOpen}
onClose={onClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import { Button, useDisclosure } from '@chakra-ui/react';

import { useQueueRun } from '../../../api';
import ConfirmDialog from '../ConfirmDialog';
import { getMetaValue } from '../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const QueueRun = ({ dagId, runId }) => {
const [affectedTasks, setAffectedTasks] = useState([]);
Expand Down Expand Up @@ -49,6 +52,7 @@ const QueueRun = ({ dagId, runId }) => {
isLoading={isLoading}
ml="5px"
title="Queue up new tasks to make the DAG run up-to-date with any DAG file changes."
isDisabled={!canEdit}
>
Queue up new tasks
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { SimpleStatus } from '../../../StatusBox';
import Table from '../../../Table';
import Time from '../../../Time';

const canEdit = getMetaValue('can_edit') === 'True';
const renderedTemplatesUrl = getMetaValue('rendered_templates_url');
const logUrl = getMetaValue('log_url');
const taskUrl = getMetaValue('task_url');
Expand Down Expand Up @@ -148,7 +149,7 @@ const MappedInstances = ({
pageSize={limit}
setSortBy={setSortBy}
isLoading={isLoading}
selectRows={selectRows}
selectRows={canEdit && selectRows}
/>
</Box>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
import ActionButton from './ActionButton';
import ConfirmDialog from '../../ConfirmDialog';
import { useClearTask } from '../../../../api';
import { getMetaValue } from '../../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const Run = ({
dagId,
Expand Down Expand Up @@ -96,7 +99,7 @@ const Run = ({

return (
<Flex justifyContent="space-between" width="100%">
<ButtonGroup isAttached variant="outline">
<ButtonGroup isAttached variant="outline" isDisabled={!canEdit}>
<ActionButton bg={past && 'gray.100'} onClick={onTogglePast} name="Past" />
<ActionButton bg={future && 'gray.100'} onClick={onToggleFuture} name="Future" />
<ActionButton bg={upstream && 'gray.100'} onClick={onToggleUpstream} name="Upstream" />
Expand All @@ -108,6 +111,7 @@ const Run = ({
colorScheme="blue"
onClick={onClick}
isLoading={isLoading}
isDisabled={!canEdit}
title="Clearing deletes the previous state of the task instance, allowing it to get re-triggered by the scheduler or a backfill command"
>
Clear
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
import ActionButton from './ActionButton';
import { useConfirmMarkTask, useMarkFailedTask } from '../../../../api';
import ConfirmDialog from '../../ConfirmDialog';
import { getMetaValue } from '../../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const MarkFailed = ({
dagId,
Expand Down Expand Up @@ -90,13 +93,13 @@ const MarkFailed = ({

return (
<Flex justifyContent="space-between" width="100%">
<ButtonGroup isAttached variant="outline">
<ButtonGroup isAttached variant="outline" isDisabled={!canEdit}>
<ActionButton bg={past && 'gray.100'} onClick={onTogglePast} name="Past" />
<ActionButton bg={future && 'gray.100'} onClick={onToggleFuture} name="Future" />
<ActionButton bg={upstream && 'gray.100'} onClick={onToggleUpstream} name="Upstream" />
<ActionButton bg={downstream && 'gray.100'} onClick={onToggleDownstream} name="Downstream" />
</ButtonGroup>
<Button colorScheme="red" onClick={onClick} isLoading={isLoading}>
<Button colorScheme="red" onClick={onClick} isLoading={isLoading} isDisabled={!canEdit}>
Mark Failed
</Button>
<ConfirmDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
import ConfirmDialog from '../../ConfirmDialog';
import ActionButton from './ActionButton';
import { useMarkSuccessTask, useConfirmMarkTask } from '../../../../api';
import { getMetaValue } from '../../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const MarkSuccess = ({
dagId, runId, taskId, mapIndexes,
Expand Down Expand Up @@ -85,13 +88,13 @@ const MarkSuccess = ({

return (
<Flex justifyContent="space-between" width="100%">
<ButtonGroup isAttached variant="outline">
<ButtonGroup isAttached variant="outline" isDisabled={!canEdit}>
<ActionButton bg={past && 'gray.100'} onClick={onTogglePast} name="Past" />
<ActionButton bg={future && 'gray.100'} onClick={onToggleFuture} name="Future" />
<ActionButton bg={upstream && 'gray.100'} onClick={onToggleUpstream} name="Upstream" />
<ActionButton bg={downstream && 'gray.100'} onClick={onToggleDownstream} name="Downstream" />
</ButtonGroup>
<Button colorScheme="green" onClick={onClick} isLoading={isLoading}>
<Button colorScheme="green" onClick={onClick} isLoading={isLoading} isDisabled={!canEdit}>
Mark Success
</Button>
<ConfirmDialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
} from '@chakra-ui/react';

import { useRunTask } from '../../../../api';
import { getMetaValue } from '../../../../../utils';

const canEdit = getMetaValue('can_edit') === 'True';

const Run = ({
dagId,
Expand Down Expand Up @@ -54,7 +57,7 @@ const Run = ({

return (
<Flex justifyContent="space-between" width="100%">
<ButtonGroup isAttached variant="outline">
<ButtonGroup isAttached variant="outline" isDisabled={!canEdit}>
<Button
bg={ignoreAllDeps && 'gray.100'}
onClick={onToggleAllDeps}
Expand All @@ -77,7 +80,7 @@ const Run = ({
Ignore Task Deps
</Button>
</ButtonGroup>
<Button colorScheme="blue" onClick={onClick} isLoading={isLoading}>
<Button colorScheme="blue" onClick={onClick} isLoading={isLoading} isDisabled={!canEdit}>
Run
</Button>
</Flex>
Expand Down
3 changes: 2 additions & 1 deletion airflow/www/templates/airflow/dag.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
{% endif %}
{% if external_log_name is defined %}
<meta name="external_log_name" content="{{ external_log_name }}">
{% endif %}
{% endif %}
<meta name="can_edit" content="{{ dag.can_edit }}">
{% endblock %}

{% block content %}
Expand Down

0 comments on commit 84021de

Please sign in to comment.