Skip to content

Commit

Permalink
Move AuditEvent.path to being a UrlPath
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodearnest committed Mar 26, 2024
1 parent 3e9595d commit cf51b6f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 3 additions & 3 deletions airlock/business_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AuditEvent:
user: str
workspace: str | None = None
request: str | None = None
path: str | None = None
path: UrlPath | None = None
extra: dict[str, str] = field(default_factory=dict)
# this is used when querying the db for audit log times
created_at: datetime = field(default_factory=timezone.now, compare=False)
Expand All @@ -110,7 +110,7 @@ def from_request(
extra=kwargs,
)
if path:
event.path = str(path)
event.path = path

return event

Expand Down Expand Up @@ -902,7 +902,7 @@ def audit_workspace_file_access(
type=AuditEventType.WORKSPACE_FILE_VIEW,
user=user.username,
workspace=workspace.name,
path=str(path),
path=path,
)
bll._dal.audit_event(audit)

Expand Down
4 changes: 2 additions & 2 deletions local_db/data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _create_audit_log(self, audit: AuditEvent) -> AuditLog:
user=audit.user,
workspace=audit.workspace,
request=audit.request,
path=audit.path,
path=str(audit.path) if audit.path else None,
extra=audit.extra,
created_at=audit.created_at,
)
Expand Down Expand Up @@ -263,7 +263,7 @@ def get_audit_log(
user=audit.user,
workspace=audit.workspace,
request=audit.request,
path=audit.path,
path=UrlPath(audit.path) if audit.path else None,
extra=audit.extra,
created_at=audit.created_at,
)
Expand Down
6 changes: 3 additions & 3 deletions tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings

from airlock.business_logic import AuditEvent, RequestFileType, Workspace, bll
from airlock.business_logic import AuditEvent, RequestFileType, UrlPath, Workspace, bll
from airlock.users import User


Expand Down Expand Up @@ -98,15 +98,15 @@ def create_audit_event(
user="user",
workspace="workspace",
request="request",
path="foo/bar",
path=UrlPath("foo/bar"),
extra={"foo": "bar"},
):
event = AuditEvent(
type=type_,
user=user,
workspace=workspace,
request=request,
path=path,
path=UrlPath(path) if path else None,
extra=extra,
)
bll._dal.audit_event(event)
Expand Down
12 changes: 9 additions & 3 deletions tests/integration/views/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import pytest
import requests

from airlock.business_logic import AuditEventType, RequestFileType, RequestStatus, bll
from airlock.business_logic import (
AuditEventType,
RequestFileType,
RequestStatus,
UrlPath,
bll,
)
from tests import factories
from tests.conftest import get_trace

Expand Down Expand Up @@ -180,7 +186,7 @@ def test_request_contents_file(airlock_client):
request=release_request.id,
)
assert audit_log[0].type == AuditEventType.REQUEST_FILE_VIEW
assert audit_log[0].path == "default/file.txt"
assert audit_log[0].path == UrlPath("default/file.txt")
assert audit_log[0].extra["group"] == "default"


Expand Down Expand Up @@ -223,7 +229,7 @@ def test_request_download_file(airlock_client):
request=release_request.id,
)
assert audit_log[0].type == AuditEventType.REQUEST_FILE_DOWNLOAD
assert audit_log[0].path == "default/file.txt"
assert audit_log[0].path == UrlPath("default/file.txt")
assert audit_log[0].extra["group"] == "default"


Expand Down
2 changes: 1 addition & 1 deletion tests/integration/views/test_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def test_workspace_contents_file(airlock_client):
workspace="workspace",
)
assert audit[0].type == AuditEventType.WORKSPACE_FILE_VIEW
assert audit[0].path == "file.txt"
assert audit[0].path == UrlPath("file.txt")


def test_workspace_contents_dir(airlock_client):
Expand Down

0 comments on commit cf51b6f

Please sign in to comment.