| 258 | |
| 259 | |
| 260 | class ChangeRequestApproval(LifecycleModel, abstract_base_auditable_model_factory()): # type: ignore[misc] |
| 261 | related_object_type = RelatedObjectType.CHANGE_REQUEST |
| 262 | history_record_class_path = ( |
| 263 | "features.workflows.core.models.HistoricalChangeRequestApproval" |
| 264 | ) |
| 265 | |
| 266 | user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) # type: ignore[var-annotated] |
| 267 | change_request = models.ForeignKey( # type: ignore[var-annotated] |
| 268 | ChangeRequest, on_delete=models.CASCADE, related_name="approvals" |
| 269 | ) |
| 270 | created_at = models.DateTimeField(auto_now_add=True) # type: ignore[var-annotated] |
| 271 | approved_at = models.DateTimeField(null=True) # type: ignore[var-annotated] |
| 272 | |
| 273 | class Meta: |
| 274 | unique_together = ("user", "change_request") |
| 275 | |
| 276 | @hook(AFTER_CREATE, when="approved_at", is_now=None) |
| 277 | def send_email_notification_to_assignee(self): # type: ignore[no-untyped-def] |
| 278 | context = { |
| 279 | "url": self.change_request.url, |
| 280 | "approver": self.user, |
| 281 | "author": self.change_request.user, |
| 282 | } |
| 283 | |
| 284 | send_mail( |
| 285 | subject=self.change_request.email_subject, |
| 286 | message=render_to_string( |
| 287 | "workflows_core/change_request_assignee_notification.txt", context |
| 288 | ), |
| 289 | from_email=settings.DEFAULT_FROM_EMAIL, |
| 290 | recipient_list=[self.user.email], |
| 291 | html_message=render_to_string( |
| 292 | "workflows_core/change_request_assignee_notification.html", context |
| 293 | ), |
| 294 | fail_silently=True, |
| 295 | ) |
| 296 | |
| 297 | @hook(AFTER_CREATE, when="approved_at", is_not=None) |
| 298 | @hook(AFTER_UPDATE, when="approved_at", was=None, is_not=None) |
| 299 | def send_email_notification_to_author(self): # type: ignore[no-untyped-def] |
| 300 | context = { |
| 301 | "url": self.change_request.url, |
| 302 | "approver": self.user, |
| 303 | "author": self.change_request.user, |
| 304 | } |
| 305 | |
| 306 | send_mail( |
| 307 | subject=self.change_request.email_subject, |
| 308 | message=render_to_string( |
| 309 | "workflows_core/change_request_approved_author_notification.txt", |
| 310 | context, |
| 311 | ), |
| 312 | from_email=settings.DEFAULT_FROM_EMAIL, |
| 313 | recipient_list=[self.change_request.user.email], |
| 314 | html_message=render_to_string( |
| 315 | "workflows_core/change_request_approved_author_notification.html", |
| 316 | context, |
| 317 | ), |
nothing calls this directly
no test coverage detected
searching dependent graphs…