Skip to content

Commit

Permalink
Reenable clear on TaskInstanceModelView for role User
Browse files Browse the repository at this point in the history
The action was disable in apache#20659
which resolved apache#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
apache#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`.
  • Loading branch information
Emil Ejbyfeldt committed Apr 12, 2023
1 parent 2ce1130 commit 69eb66b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5378,6 +5378,7 @@ class TaskInstanceModelView(AirflowPrivilegeVerifierModelView):
class_permission_name = permissions.RESOURCE_TASK_INSTANCE
method_permission_name = {
"list": "read",
"action_clear": "edit",
"action_muldelete": "delete",
}
base_permissions = [
Expand Down
21 changes: 16 additions & 5 deletions tests/www/views/test_views_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
@pytest.mark.parametrize(
"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):
Expand Down

0 comments on commit 69eb66b

Please sign in to comment.