Beispiel #1
0
def list_tasks(
    incident_id: int,
    command: dict = None,
    db_session=None,
    by_creator: str = None,
    by_assignee: str = None,
):
    """Returns the list of incident tasks to the user as an ephemeral message."""
    blocks = []

    for status in TaskStatus:
        blocks.append(
            {
                "type": "section",
                "text": {"type": "mrkdwn", "text": f"*{status.value} Incident Tasks*"},
            }
        )
        button_text = "Resolve" if status.value == TaskStatus.open else "Re-open"
        action_type = "resolve" if status.value == TaskStatus.open else "reopen"

        tasks = task_service.get_all_by_incident_id_and_status(
            db_session=db_session, incident_id=incident_id, status=status.value
        )

        if by_creator or by_assignee:
            tasks = filter_tasks_by_assignee_and_creator(tasks, by_assignee, by_creator)

        for idx, task in enumerate(tasks):
            assignees = [f"<{a.individual.weblink}|{a.individual.name}>" for a in task.assignees]

            blocks.append(
                {
                    "type": "section",
                    "text": {
                        "type": "mrkdwn",
                        "text": (
                            f"*Description:* <{task.weblink}|{task.description}>\n"
                            f"*Creator:* <{task.creator.individual.weblink}|{task.creator.individual.name}>\n"
                            f"*Assignees:* {', '.join(assignees)}"
                        ),
                    },
                    "block_id": f"{ConversationButtonActions.update_task_status}-{task.status}-{idx}",
                    "accessory": {
                        "type": "button",
                        "text": {"type": "plain_text", "text": button_text},
                        "value": f"{action_type}-{task.resource_id}",
                    },
                }
            )
        blocks.append({"type": "divider"})

    dispatch_slack_service.send_ephemeral_message(
        slack_client,
        command["channel_id"],
        command["user_id"],
        "Incident Task List",
        blocks=blocks,
    )
Beispiel #2
0
def list_tasks(
    incident_id: int,
    command: dict = None,
    db_session=None,
    by_creator: str = None,
    by_assignee: str = None,
):
    """Returns the list of incident tasks to the user as an ephemeral message."""
    blocks = []
    for status in TaskStatus:
        blocks.append({
            "type": "section",
            "text": {
                "type": "mrkdwn",
                "text": f"*{status.value} Incident Tasks*"
            },
        })

        tasks = task_service.get_all_by_incident_id_and_status(
            db_session=db_session,
            incident_id=incident_id,
            status=status.value)

        if by_creator or by_assignee:
            tasks = filter_tasks_by_assignee_and_creator(
                tasks, by_assignee, by_creator)

        for task in tasks:
            assignees = [a.individual.email for a in task.assignees]
            blocks.append({
                "type": "section",
                "text": {
                    "type":
                    "mrkdwn",
                    "text":
                    (f"*Description:* <{task.weblink}|{task.description}>\n"
                     f"*Assignees:* {', '.join(assignees)}"),
                },
            })
        blocks.append({"type": "divider"})

    dispatch_slack_service.send_ephemeral_message(
        slack_client,
        command["channel_id"],
        command["user_id"],
        "Incident List Tasks",
        blocks=blocks,
    )