Skip to content

Commit

Permalink
Make model history (audits) public on unembargo
Browse files Browse the repository at this point in the history
Make linting corrections
  • Loading branch information
superbuggy committed Dec 11, 2024
1 parent 7bc59d2 commit 1bc3d26
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
25 changes: 24 additions & 1 deletion osidb/mixins.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import pghistory
import pgtrigger
import uuid
from functools import cached_property
from itertools import chain

from django.apps import apps
from django.conf import settings
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -532,7 +535,27 @@ def unembargo(self):

# unembargo
self.set_public()

refs = pghistory.models.Events.objects.references(self).all()
for ref in refs:
db, model_name = ref.pgh_model.split(".")
model_audit = apps.get_model(db, model_name).objects.filter(
pgh_id=ref.pgh_id
)
with pgtrigger.ignore(
"osidb.FlawAudit:append_only",
"osidb.SnippetAudit:append_only",
"osidb.AffectAudit:append_only",
"osidb.AffectCVSSAudit:append_only",
"osidb.TrackerAudit:append_only",
"osidb.FlawAcknowledgmentAudit:append_only",
"osidb.FlawCommentAudit:append_only",
"osidb.FlawCVSSAudit:append_only",
"osidb.FlawReferenceAudit:append_only",
):
model_audit.update(
acl_read=list(self.acls_public_read),
acl_write=list(self.acls_public_write),
)
kwargs = {}
if issubclass(type(self), AlertMixin):
# suppress the validation errors as we expect that during
Expand Down
6 changes: 6 additions & 0 deletions osidb/tests/endpoints/flaws/test_unembargo.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ def test_complex(self, auth_client, test_api_uri):
)
)

assert (
flaw["acls_read"] == settings.PUBLIC_READ_GROUPS
and flaw["acls_write"] == [settings.PUBLIC_WRITE_GROUP]
for flaw in Flaw.objects.all()
)

@freeze_time(datetime(2020, 10, 10, tzinfo=timezone.utc))
def test_combined(self, auth_client, test_api_uri):
"""
Expand Down

0 comments on commit 1bc3d26

Please sign in to comment.