Skip to content

Commit ebe84e7

Browse files
committed
Add event to log several revoked approvals on a PC
1 parent 1f1ba65 commit ebe84e7

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

backend/infrahub/core/constants/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class EventType(InfrahubStringEnum):
6666
PROPOSED_CHANGE_APPROVED = f"{EVENT_NAMESPACE}.proposed_change.approved"
6767
PROPOSED_CHANGE_REJECTED = f"{EVENT_NAMESPACE}.proposed_change.rejected"
6868
PROPOSED_CHANGE_APPROVAL_REVOKED = f"{EVENT_NAMESPACE}.proposed_change.approval_revoked"
69+
PROPOSED_CHANGE_APPROVALS_REVOKED = f"{EVENT_NAMESPACE}.proposed_change.approvals_revoked"
6970
PROPOSED_CHANGE_REJECTION_REVOKED = f"{EVENT_NAMESPACE}.proposed_change.rejection_revoked"
7071
PROPOSED_CHANGE_THREAD_CREATED = f"{EVENT_NAMESPACE}.proposed_change_thread.created"
7172
PROPOSED_CHANGE_THREAD_UPDATED = f"{EVENT_NAMESPACE}.proposed_change_thread.updated"

backend/infrahub/events/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from .node_action import NodeCreatedEvent, NodeDeletedEvent, NodeUpdatedEvent
66
from .proposed_change_action import (
77
ProposedChangeApprovalRevokedEvent,
8+
ProposedChangeApprovalsRevokedEvent,
89
ProposedChangeApprovedEvent,
910
ProposedChangeMergedEvent,
1011
ProposedChangeRejectedEvent,
@@ -32,6 +33,7 @@
3233
"NodeDeletedEvent",
3334
"NodeUpdatedEvent",
3435
"ProposedChangeApprovalRevokedEvent",
36+
"ProposedChangeApprovalsRevokedEvent",
3537
"ProposedChangeApprovedEvent",
3638
"ProposedChangeMergedEvent",
3739
"ProposedChangeRejectedEvent",

backend/infrahub/events/proposed_change_action.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from typing import ClassVar
1+
from typing import ClassVar, Self
22

3-
from pydantic import Field
3+
from pydantic import Field, model_validator
44

55
from infrahub.core.constants import InfrahubKind, MutationAction
66

@@ -150,6 +150,33 @@ class ProposedChangeRejectionRevokedEvent(ProposedChangeReviewRevokedEvent):
150150
event_name: ClassVar[str] = f"{EVENT_NAMESPACE}.proposed_change.rejection_revoked"
151151

152152

153+
class ProposedChangeApprovalsRevokedEvent(ProposedChangeEvent):
154+
reviewer_account_ids: list[str] = Field(..., description="IDs of accounts whose approval was revoked")
155+
reviewer_account_names: list[str] = Field(..., description="Names of accounts whose approval was revoked")
156+
157+
event_name: ClassVar[str] = f"{EVENT_NAMESPACE}.proposed_change.approvals_revoked"
158+
159+
@model_validator(mode="after")
160+
def check_same_length(self) -> Self:
161+
if len(self.reviewer_account_ids) != len(self.reviewer_account_names):
162+
raise ValueError("reviewer_account_ids and reviewer_account_names must have the same number of items")
163+
return self
164+
165+
def get_related(self) -> list[dict[str, str]]:
166+
related = super().get_related()
167+
for i, account_id in enumerate(self.reviewer_account_ids):
168+
related.append(
169+
{
170+
"prefect.resource.id": account_id,
171+
"prefect.resource.role": "infrahub.related.node",
172+
"infrahub.node.kind": InfrahubKind.GENERICACCOUNT,
173+
"infrahub.node.id": account_id,
174+
"infrahub.reviewer.account.name": self.reviewer_account_names[i],
175+
}
176+
)
177+
return related
178+
179+
153180
class ProposedChangeThreadEvent(ProposedChangeEvent):
154181
thread_id: str = Field(..., description="The ID of the thread that was created or updated")
155182
thread_kind: str = Field(..., description="The name of the thread that was created or updated")

0 commit comments

Comments
 (0)