Skip to content

Commit

Permalink
Merge branch 'main' into enable-drf-root
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Izquierdo authored Jun 21, 2024
2 parents 43d598d + 79413ee commit bda312f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
11 changes: 6 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Taskfile.dist.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion src/aap_eda/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/aap_eda/api/serializers/rulebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ class Meta:
fields = [
"id",
"name",
"description",
"status",
"created_at",
"fired_at",
Expand All @@ -101,7 +100,6 @@ class Meta:
"activation_instance_id",
"job_instance_id",
"organization_id",
"definition",
]
read_only_fields = ["id", "organization_id", "created_at"]

Expand Down
14 changes: 10 additions & 4 deletions tests/integration/dab_rbac/test_crud_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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
Expand Down

0 comments on commit bda312f

Please sign in to comment.