From 8be667c095391cf760af5bde55cd633c67f5e218 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Fri, 21 Jun 2024 10:12:46 -0400 Subject: [PATCH 1/2] Allow using go-task instead of task (#943) Co-authored-by: Bill Wei --- .pre-commit-config.yaml | 11 ++++++----- Taskfile.dist.yaml | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 458340ab4..bcd6727fe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,32 +2,33 @@ repos: - repo: local hooks: + # CMD logic allows using task or go-task, depending on what is installed - id: black name: black language: system types: [python] - entry: task lint:black -- + entry: command -v task > /dev/null && CMD=task || CMD=go-task; ${CMD} lint:black -- - id: isort name: isort language: system types: [python] - entry: task lint:isort -- + entry: command -v task > /dev/null && CMD=task || CMD=go-task; ${CMD} lint:isort -- - id: ruff name: ruff language: system types: [python] - entry: task lint:ruff -- + entry: command -v task > /dev/null && CMD=task || CMD=go-task; ${CMD} lint:ruff -- - id: flake8 name: flake8 language: system types: [python] - entry: task lint:flake8 -- + entry: command -v task > /dev/null && CMD=task || CMD=go-task; ${CMD} lint:flake8 -- - id: migrations name: migrations language: system types: [python] pass_filenames: false - entry: task lint:migrations + entry: command -v task > /dev/null && CMD=task || CMD=go-task; ${CMD} lint:migrations - repo: https://github.com/python-poetry/poetry rev: '1.4.0' hooks: diff --git a/Taskfile.dist.yaml b/Taskfile.dist.yaml index e99b245bc..93f888ba7 100644 --- a/Taskfile.dist.yaml +++ b/Taskfile.dist.yaml @@ -15,7 +15,7 @@ tasks: default: desc: "Show this message and exit" cmds: - - task -l + - command -v task > /dev/null && CMD=task || CMD=go-task; ${CMD} -l silent: true dev:init: From 79413ee66dbf55c2548246c15673eeae33f0cf9d Mon Sep 17 00:00:00 2001 From: Bill Wei Date: Fri, 21 Jun 2024 10:58:10 -0400 Subject: [PATCH 2/2] fix: add GET to OPTIONS (#941) --- src/aap_eda/api/metadata.py | 4 +++- src/aap_eda/api/serializers/rulebook.py | 2 -- .../integration/dab_rbac/test_crud_permissions.py | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/aap_eda/api/metadata.py b/src/aap_eda/api/metadata.py index 79d4f9ac0..da378d57b 100644 --- a/src/aap_eda/api/metadata.py +++ b/src/aap_eda/api/metadata.py @@ -13,7 +13,9 @@ def determine_actions(self, request, view): the fields that are accepted for 'PUT' and 'POST' methods. """ actions = {} - for method in {"PUT", "PATCH", "POST"} & set(view.allowed_methods): + for method in {"GET", "PUT", "PATCH", "POST"} & set( + view.allowed_methods + ): view.request = clone_request(request, method) try: # Test global permissions diff --git a/src/aap_eda/api/serializers/rulebook.py b/src/aap_eda/api/serializers/rulebook.py index f6caa73e7..cbb48ad9e 100644 --- a/src/aap_eda/api/serializers/rulebook.py +++ b/src/aap_eda/api/serializers/rulebook.py @@ -91,7 +91,6 @@ class Meta: fields = [ "id", "name", - "description", "status", "created_at", "fired_at", @@ -101,7 +100,6 @@ class Meta: "activation_instance_id", "job_instance_id", "organization_id", - "definition", ] read_only_fields = ["id", "organization_id", "created_at"] diff --git a/tests/integration/dab_rbac/test_crud_permissions.py b/tests/integration/dab_rbac/test_crud_permissions.py index fec339c72..bc3ea0e57 100644 --- a/tests/integration/dab_rbac/test_crud_permissions.py +++ b/tests/integration/dab_rbac/test_crud_permissions.py @@ -149,10 +149,12 @@ def test_view_permissions( response = user_client.get(url, data={}) assert response.status_code == 200, response.data + # Assure GET action is on OPTIONS # Assure no POST action on OPTIONS since user has no add permission response = user_client.options(url) assert response.status_code == 200 - assert "actions" not in response.data + assert "GET" in response.data["actions"] + assert "POST" not in response.data["actions"] @pytest.mark.django_db @@ -175,7 +177,10 @@ def test_change_permissions( # Test OPTIONS without sufficient permissions response = user_client.options(url) assert response.status_code == 200 - assert "actions" not in response.data # no PATCH or PUT + actions = response.data["actions"] + assert "GET" in actions + assert "PATCH" not in actions # no PATCH or PUT + assert "PUT" not in actions # Give object change permission give_obj_perm(default_user, obj, "change") @@ -185,8 +190,9 @@ def test_change_permissions( # Test OPTIONS response = user_client.options(url) assert response.status_code == 200 - assert "actions" in response.data - assert "PATCH" in response.data["actions"] + actions = response.data["actions"] + assert "GET" in actions + assert "PATCH" in actions @pytest.mark.django_db