# What this PR does Closes #2868 **Slack thread message** <img width="442" alt="Screenshot 2023-09-07 at 15 47 30" src="https://github.com/grafana/oncall/assets/9406895/f8f39341-4d18-4a43-88be-066993275fcd"> **Push notification** Clicking on the push notification goes to the SSR detail view <img width="423" alt="Screenshot 2023-09-07 at 15 48 59" src="https://github.com/grafana/oncall/assets/9406895/5bb0fbf3-3e55-47e3-bf24-9cb5690dc17c"> ## Checklist - [x] Unit, integration, and e2e (if applicable) tests updated - [x] Documentation added (or `pr:no public docs` PR label added if not required) - [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not required)
36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
from celery.utils.log import get_task_logger
|
|
|
|
from apps.mobile_app.tasks import (
|
|
notify_beneficiary_about_taken_shift_swap_request as notify_beneficiary_about_taken_shift_swap_request_via_push_notification,
|
|
)
|
|
from common.custom_celery_tasks import shared_dedicated_queue_retry_task
|
|
|
|
task_logger = get_task_logger(__name__)
|
|
|
|
|
|
@shared_dedicated_queue_retry_task()
|
|
def notify_beneficiary_about_taken_shift_swap_request(shift_swap_request_pk: str) -> None:
|
|
from apps.schedules.models import ShiftSwapRequest
|
|
from apps.slack.scenarios.shift_swap_requests import AcceptShiftSwapRequestStep
|
|
|
|
task_logger.info(f"Start notify_beneficiary_about_taken_shift_swap_request: pk = {shift_swap_request_pk}")
|
|
|
|
try:
|
|
shift_swap_request = ShiftSwapRequest.objects.get(pk=shift_swap_request_pk)
|
|
except ShiftSwapRequest.DoesNotExist:
|
|
task_logger.info(
|
|
f"Tried to notify_beneficiary_about_taken_shift_swap_request for non-existing shift swap request {shift_swap_request_pk}"
|
|
)
|
|
return
|
|
|
|
notify_beneficiary_about_taken_shift_swap_request_via_push_notification.apply_async((shift_swap_request_pk,))
|
|
|
|
if shift_swap_request.slack_channel_id is None:
|
|
task_logger.info(
|
|
f"Skipping notify_beneficiary_about_taken_shift_swap_request for shift_swap_request {shift_swap_request_pk} because channel_id is None"
|
|
)
|
|
return
|
|
|
|
organization = shift_swap_request.organization
|
|
step = AcceptShiftSwapRequestStep(organization.slack_team_identity, organization)
|
|
step.post_request_taken_message_to_thread(shift_swap_request)
|