Skip to content

Commit

Permalink
Fix Mark Instance state buttons stay disabled if user lacks permission (
Browse files Browse the repository at this point in the history
#37451). (#38732)

(cherry picked from commit c8c97b5)
  • Loading branch information
RodrigoGanancia authored and ephraimbuddy committed Jun 4, 2024
1 parent ebb74b2 commit 670b255
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import keyboardShortcutIdentifier from "src/dag/keyboardShortcutIdentifier";
import ActionButton from "./ActionButton";
import ActionModal from "./ActionModal";

const canEditTaskInstance = getMetaValue("can_edit_taskinstance") === "True";
const canEdit = getMetaValue("can_edit") === "True";
const dagId = getMetaValue("dag_id");

Expand Down Expand Up @@ -248,15 +249,15 @@ const ClearInstance = ({
<Button
title={clearLabel}
aria-label={clearLabel}
isDisabled={!canEdit}
isDisabled={!canEdit || !canEditTaskInstance}
colorScheme="blue"
onClick={onOpen}
{...otherProps}
>
Clear task
</Button>
{/* Only mount modal if user can edit */}
{canEdit && (
{canEdit && canEditTaskInstance && (
<ClearModal
runId={runId}
taskId={taskId}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { SimpleStatus } from "../../../StatusBox";
import ActionButton from "./ActionButton";
import ActionModal from "./ActionModal";

const canEditTaskInstance = getMetaValue("can_edit_taskinstance") === "True";
const canEdit = getMetaValue("can_edit") === "True";
const dagId = getMetaValue("dag_id");

Expand Down Expand Up @@ -288,7 +289,7 @@ const MarkInstanceAs = ({
transition="all 0.2s"
title={markLabel}
aria-label={markLabel}
disabled={!canEdit}
disabled={!canEdit || !canEditTaskInstance}
{...otherProps}
>
<Flex>
Expand All @@ -308,7 +309,7 @@ const MarkInstanceAs = ({
</MenuList>
</Menu>
{/* Only load modal is user can edit */}
{canEdit && (
{canEdit && canEditTaskInstance && (
<MarkAsModal
runId={runId}
taskId={taskId}
Expand Down
1 change: 1 addition & 0 deletions airflow/www/templates/airflow/grid.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<meta name="base_date" content="{{ request.args.get('base_date') if request.args.get('base_date') else '' }}">
<meta name="default_wrap" content="{{ default_wrap }}">
<meta name="dataset_events_api" content="{{ url_for('/api/v1.airflow_api_connexion_endpoints_dataset_endpoint_get_dataset_events') }}">
<meta name="can_edit_taskinstance" content="{{ can_edit_taskinstance }}">
{% endblock %}

{% block content %}
Expand Down
6 changes: 6 additions & 0 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2825,13 +2825,19 @@ def grid(self, dag_id: str, session: Session = NEW_SESSION):
if default_dag_run_display_number not in num_runs_options:
insort_left(num_runs_options, default_dag_run_display_number)

can_edit_taskinstance = get_auth_manager().is_authorized_dag(
method="PUT",
access_entity=DagAccessEntity.TASK_INSTANCE,
)

return self.render_template(
"airflow/grid.html",
show_trigger_form_if_no_params=conf.getboolean("webserver", "show_trigger_form_if_no_params"),
root=root,
dag=dag,
doc_md=doc_md,
num_runs=num_runs,
can_edit_taskinstance=can_edit_taskinstance,
show_external_log_redirect=task_log_reader.supports_external_link,
external_log_name=external_log_name,
dag_model=dag_model,
Expand Down

0 comments on commit 670b255

Please sign in to comment.