Skip to content

Commit

Permalink
adding permissions changed action
Browse files Browse the repository at this point in the history
  • Loading branch information
nilbacardit26 committed Mar 6, 2024
1 parent fec2c1a commit 2e6a721
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
2.0.3 (unreleased)
------------------

- Nothing changed yet.
- Adding permissions_changed action when permissions are changed


2.0.2 (2024-03-06)
Expand Down
12 changes: 12 additions & 0 deletions guillotina_audit/tests/test_audit_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ async def test_permissions_modified_without_indexing(guillotina_es):
assert status == 200
# There should be the same number of documents since indexing_permission_changes is False
assert len(resp["hits"]["hits"]) == 2
response, status = await guillotina_es(
"PATCH",
"/db/guillotina/foo_item",
data=json.dumps({"title": "Another title"})
)
assert status == 204
await asyncio.sleep(2)
# Let's make sure ObjectModifiedEvent adds a document
resp, status = await guillotina_es("GET", "/db/guillotina/@audit")
assert status == 200
assert len(resp["hits"]["hits"]) == 3


@pytest.mark.app_settings(
Expand Down Expand Up @@ -319,3 +330,4 @@ async def test_permissions_modified_with_indexing(guillotina_es):
assert status == 200
# There should be one more document since indexing_permission_changes is True
assert len(resp["hits"]["hits"]) == 3
assert resp["hits"]["hits"][-1]["_source"]["action"] == "permissions_changed"
4 changes: 4 additions & 0 deletions guillotina_audit/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from guillotina.interfaces import IObjectModifiedEvent
from guillotina.interfaces import IObjectMovedEvent
from guillotina.interfaces import IObjectRemovedEvent
from guillotina.interfaces import IObjectPermissionsModifiedEvent
from guillotina.utils.auth import get_authenticated_user
from guillotina.utils.content import get_content_path
from guillotina_audit.models import AuditDocument
Expand Down Expand Up @@ -94,6 +95,9 @@ def log_entry(self, obj, event):
elif IObjectMovedEvent.providedBy(event):
document["action"] = "moved"
document["creation_date"] = datetime.datetime.now(timezone.utc)
elif IObjectPermissionsModifiedEvent.providedBy(event):
document["action"] = "permissions_changed"
document["creation_date"] = datetime.datetime.now(timezone.utc)
elif IObjectModifiedEvent.providedBy(event):
document["action"] = "modified"
document["creation_date"] = obj.modification_date
Expand Down

0 comments on commit 2e6a721

Please sign in to comment.