This is an automated email from the ASF dual-hosted git repository. ephraimanierobi pushed a commit to branch v2-6-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 93442efedfc82c83f92f9bc697911fec7f7c862a Author: Emil Ejbyfeldt <[email protected]> AuthorDate: Sat Apr 22 19:10:49 2023 +0200 Reenable clear on TaskInstanceModelView for role User (#30415) * Reenable clear on TaskInstanceModelView for role User The action was disable in https://github.com/apache/airflow/pull/20659 which resolved https://github.com/apache/airflow/issues/20655. The issue only mentions that the edit is broken and should be disabled. So it seem like the disabling of the clear action was unintentional. Also based on the discussion in the PR https://github.com/apache/airflow/issues/20655 further reinforces this. That the author believed it still worked could be explain by that using a user with role `Admin` the action was still available and therefore one could easily make a mistake believing it still worked as expected. This PR reenables it action and modifies and existing test case to also verify that clearing is possible using a user with the role `User`. * Add back other set state actions * fix static checks --------- Co-authored-by: eladkal <[email protected]> (cherry picked from commit b140c4473335e4e157ff2db85148dd120c0ed893) --- airflow/www/views.py | 6 ++++++ tests/www/views/test_views_tasks.py | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/airflow/www/views.py b/airflow/www/views.py index cabc8e9e1a..62bde217ee 100644 --- a/airflow/www/views.py +++ b/airflow/www/views.py @@ -5378,7 +5378,13 @@ class TaskInstanceModelView(AirflowPrivilegeVerifierModelView): class_permission_name = permissions.RESOURCE_TASK_INSTANCE method_permission_name = { "list": "read", + "action_clear": "edit", "action_muldelete": "delete", + "action_set_running": "edit", + "action_set_failed": "edit", + "action_set_success": "edit", + "action_set_retry": "edit", + "action_set_skipped": "edit", } base_permissions = [ permissions.ACTION_CAN_CREATE, diff --git a/tests/www/views/test_views_tasks.py b/tests/www/views/test_views_tasks.py index 6f7d70f19d..35538e5bf9 100644 --- a/tests/www/views/test_views_tasks.py +++ b/tests/www/views/test_views_tasks.py @@ -706,26 +706,37 @@ def test_task_instance_delete_permission_denied(session, client_ti_without_dag_e assert session.query(TaskInstance).filter(TaskInstance.task_id == task_id).count() == 1 -def test_task_instance_clear(session, admin_client): [email protected]( + "client_fixture, should_succeed", + [ + ("admin_client", True), + ("user_client", True), + ("viewer_client", False), + ("anonymous_client", False), + ], +) +def test_task_instance_clear(session, request, client_fixture, should_succeed): + client = request.getfixturevalue(client_fixture) task_id = "runme_0" + initial_state = State.SUCCESS # Set the state to success for clearing. ti_q = session.query(TaskInstance).filter(TaskInstance.task_id == task_id) - ti_q.update({"state": State.SUCCESS}) + ti_q.update({"state": initial_state}) session.commit() # Send a request to clear. rowid = _get_appbuilder_pk_string(TaskInstanceModelView, ti_q.one()) - resp = admin_client.post( + resp = client.post( "/taskinstance/action_post", data={"action": "clear", "rowid": rowid}, follow_redirects=True, ) - assert resp.status_code == 200 + assert resp.status_code == (200 if should_succeed else 404) # Now the state should be None. state = session.query(TaskInstance.state).filter(TaskInstance.task_id == task_id).scalar() - assert state == State.NONE + assert state == (State.NONE if should_succeed else initial_state) def test_task_instance_clear_failure(admin_client):
