|
1 |
| -from typing import ClassVar |
| 1 | +from typing import ClassVar, Self |
2 | 2 |
|
3 |
| -from pydantic import Field |
| 3 | +from pydantic import Field, model_validator |
4 | 4 |
|
5 | 5 | from infrahub.core.constants import InfrahubKind, MutationAction
|
6 | 6 |
|
@@ -150,6 +150,33 @@ class ProposedChangeRejectionRevokedEvent(ProposedChangeReviewRevokedEvent):
|
150 | 150 | event_name: ClassVar[str] = f"{EVENT_NAMESPACE}.proposed_change.rejection_revoked"
|
151 | 151 |
|
152 | 152 |
|
| 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 | + |
153 | 180 | class ProposedChangeThreadEvent(ProposedChangeEvent):
|
154 | 181 | thread_id: str = Field(..., description="The ID of the thread that was created or updated")
|
155 | 182 | thread_kind: str = Field(..., description="The name of the thread that was created or updated")
|
|
0 commit comments