Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

techdebt(plugin): deprecates the document resolver plugin and its code #5420

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 8 additions & 27 deletions src/dispatch/incident/flows.py
Original file line number Diff line number Diff line change
@@ -1,62 +1,57 @@
import logging

from datetime import datetime
from typing import Optional

from sqlalchemy.orm import Session

from dispatch.case.models import Case
from dispatch.case import service as case_service
from dispatch.case.models import Case
from dispatch.conference import flows as conference_flows
from dispatch.conversation import flows as conversation_flows
from dispatch.database.core import resolve_attr
from dispatch.decorators import background_task
from dispatch.document import flows as document_flows
from dispatch.document.models import Document
from dispatch.enums import DocumentResourceTypes
from dispatch.enums import Visibility, EventType
from dispatch.enums import DocumentResourceTypes, EventType, Visibility
from dispatch.event import service as event_service
from dispatch.group import flows as group_flows
from dispatch.group.enums import GroupType, GroupAction
from dispatch.group.enums import GroupAction, GroupType
from dispatch.incident import service as incident_service
from dispatch.incident.models import IncidentRead
from dispatch.incident_cost import service as incident_cost_service
from dispatch.individual import service as individual_service
from dispatch.individual.models import IndividualContact
from dispatch.participant import flows as participant_flows
from dispatch.participant import service as participant_service
from dispatch.participant.models import Participant
from dispatch.individual.models import IndividualContact
from dispatch.team.models import TeamContact
from dispatch.participant_role import flows as participant_role_flows
from dispatch.participant_role.models import ParticipantRoleType
from dispatch.plugin import service as plugin_service
from dispatch.report.enums import ReportTypes
from dispatch.report.messaging import send_incident_report_reminder
from dispatch.service import service as service_service
from dispatch.storage import flows as storage_flows
from dispatch.tag.flows import check_for_tag_change
from dispatch.task.enums import TaskStatus
from dispatch.team.models import TeamContact
from dispatch.ticket import flows as ticket_flows
from dispatch.tag.flows import check_for_tag_change

from .messaging import (
# get_suggested_document_items,
bulk_participant_announcement_message,
send_incident_closed_information_review_reminder,
send_incident_commander_readded_notification,
send_incident_created_notifications,
send_incident_management_help_tips_message,
send_incident_new_role_assigned_notification,
send_incident_open_tasks_ephemeral_message,
send_participant_announcement_message,
bulk_participant_announcement_message,
send_incident_rating_feedback_message,
send_incident_review_document_notification,
# send_incident_suggested_reading_messages,
send_incident_update_notifications,
send_incident_welcome_participant_messages,
send_participant_announcement_message,
)
from .models import Incident, IncidentStatus


log = logging.getLogger(__name__)


Expand Down Expand Up @@ -315,13 +310,6 @@ def incident_create_resources(
# we send the welcome messages to the participant
send_incident_welcome_participant_messages(user_email, incident, db_session)

# NOTE: Temporarily disabled until an issue with the Dispatch resolver plugin is resolved
# we send a suggested reading message to the participant
# suggested_document_items = get_suggested_document_items(incident, db_session)
# send_incident_suggested_reading_messages(
# incident, suggested_document_items, user_email, db_session
# )

bulk_participant_announcement_message(
participant_emails=user_emails,
subject=incident,
Expand Down Expand Up @@ -1051,13 +1039,6 @@ def incident_add_or_reactivate_participant_flow(
# we send the welcome messages to the participant
send_incident_welcome_participant_messages(user_email, incident, db_session)

# NOTE: Temporarily disabled until an issue with the Dispatch resolver plugin is resolved
# we send a suggested reading message to the participant
# suggested_document_items = get_suggested_document_items(incident, db_session)
# send_incident_suggested_reading_messages(
# incident, suggested_document_items, user_email, db_session
# )

return participant


Expand Down
74 changes: 9 additions & 65 deletions src/dispatch/incident/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,55 @@
"""

import logging

from typing import Optional

from slack_sdk.errors import SlackApiError
from sqlalchemy.orm import Session

from dispatch.decorators import timer
from dispatch.config import DISPATCH_UI_URL
from dispatch.conversation.enums import ConversationCommands
from dispatch.database.core import SessionLocal, resolve_attr
from dispatch.decorators import timer
from dispatch.document import service as document_service
from dispatch.email_templates.models import EmailTemplates
from dispatch.email_templates import service as email_template_service
from dispatch.email_templates.enums import EmailTemplateTypes
from dispatch.email_templates.models import EmailTemplates
from dispatch.enums import SubjectNames
from dispatch.event import service as event_service
from dispatch.forms.models import Forms
from dispatch.incident.enums import IncidentStatus
from dispatch.incident.models import Incident, IncidentRead
from dispatch.notification import service as notification_service
from dispatch.forms.models import Forms
from dispatch.messaging.strings import (
INCIDENT_CLOSE_REMINDER,
INCIDENT_CLOSED_INFORMATION_REVIEW_REMINDER_NOTIFICATION,
INCIDENT_CLOSED_RATING_FEEDBACK_NOTIFICATION,
INCIDENT_CLOSE_REMINDER,
INCIDENT_COMMANDER,
INCIDENT_COMMANDER_READDED_NOTIFICATION,
INCIDENT_COMPLETED_FORM_MESSAGE,
INCIDENT_MANAGEMENT_HELP_TIPS_MESSAGE,
INCIDENT_NAME,
INCIDENT_NAME_WITH_ENGAGEMENT,
INCIDENT_NAME_WITH_ENGAGEMENT_NO_SELF_JOIN,
INCIDENT_NEW_ROLE_NOTIFICATION,
INCIDENT_NOTIFICATION,
INCIDENT_NOTIFICATION_COMMON,
INCIDENT_OPEN_TASKS,
INCIDENT_PARTICIPANT_SUGGESTED_READING_ITEM,
INCIDENT_PRIORITY_CHANGE,
INCIDENT_REVIEW_DOCUMENT,
INCIDENT_SEVERITY_CHANGE,
INCIDENT_STATUS_CHANGE,
INCIDENT_TYPE_CHANGE,
INCIDENT_COMPLETED_FORM_MESSAGE,
INCIDENT_TASK_ADD_TO_INCIDENT,
INCIDENT_NAME_WITH_ENGAGEMENT_NO_SELF_JOIN,
INCIDENT_TYPE_CHANGE,
MessageType,
generate_welcome_message,
)
from dispatch.notification import service as notification_service
from dispatch.participant import service as participant_service
from dispatch.participant_role import service as participant_role_service
from dispatch.plugin import service as plugin_service
from dispatch.plugins.dispatch_slack.enums import SlackAPIErrorCode
from dispatch.types import Subject
from dispatch.task.models import TaskCreate

from dispatch.types import Subject

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -322,59 +319,6 @@ def send_incident_welcome_participant_messages(
log.debug(f"Welcome participant messages sent {participant_email}.")


@timer
def get_suggested_document_items(incident: Incident, db_session: SessionLocal):
"""Create the suggested document item message."""
suggested_documents = get_suggested_documents(db_session, incident)

items = []
if suggested_documents:
# we send the ephemeral message
# lets grab the first 5 documents
# TODO add more intelligent ranking
for i in suggested_documents[:5]:
description = i.description
if not description:
if i.incident:
description = i.incident.title

items.append({"name": i.name, "weblink": i.weblink, "description": description})
return items


@timer
def send_incident_suggested_reading_messages(
incident: Incident, items: list, participant_email: str, db_session: SessionLocal
):
"""Sends a suggested reading message to a participant."""
if not items:
return

if not incident.conversation:
log.warning(
"Incident suggested reading message not sent. No conversation available for this incident."
)
return

plugin = plugin_service.get_active_instance(
db_session=db_session, project_id=incident.project.id, plugin_type="conversation"
)
if not plugin:
log.warning("Incident suggested reading message not sent. No conversation plugin enabled.")
return

plugin.instance.send_ephemeral(
incident.conversation.channel_id,
participant_email,
"Suggested Reading",
[INCIDENT_PARTICIPANT_SUGGESTED_READING_ITEM],
MessageType.incident_participant_suggested_reading,
items=items,
)

log.debug(f"Suggested reading ephemeral message sent to {participant_email}.")


def send_incident_created_notifications(incident: Incident, db_session: SessionLocal):
"""Sends incident created notifications."""
notification_template = INCIDENT_NOTIFICATION.copy()
Expand Down
1 change: 0 additions & 1 deletion src/dispatch/plugins/bases/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from .conversation import ConversationPlugin # noqa
from .definition import DefinitionPlugin # noqa
from .document import DocumentPlugin # noqa
from .document_resolver import DocumentResolverPlugin # noqa
from .email import EmailPlugin # noqa
from .monitor import MonitorPlugin # noqa
from .oncall import OncallPlugin # noqa
Expand Down
16 changes: 0 additions & 16 deletions src/dispatch/plugins/bases/document_resolver.py

This file was deleted.

6 changes: 3 additions & 3 deletions src/dispatch/plugins/dispatch_core/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import logging
from dispatch.config import BaseConfigurationModel

from starlette.config import Config
from pydantic import Field
from starlette.config import Config

log = logging.getLogger(__name__)
from dispatch.config import BaseConfigurationModel

log = logging.getLogger(__name__)

config = Config(".env")

Expand Down
39 changes: 6 additions & 33 deletions src/dispatch/plugins/dispatch_core/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
from fastapi.security.utils import get_authorization_scheme_param
from jose import JWTError, jwt
from jose.exceptions import JWKError
from sqlalchemy.orm import Session
from starlette.requests import Request
from starlette.status import HTTP_401_UNAUTHORIZED
from sqlalchemy.orm import Session

from dispatch.auth.models import MfaChallenge, MfaPayload, DispatchUser, MfaChallengeStatus
from dispatch.auth.models import DispatchUser, MfaChallenge, MfaChallengeStatus, MfaPayload
from dispatch.case import service as case_service
from dispatch.config import (
DISPATCH_AUTHENTICATION_PROVIDER_HEADER_NAME,
Expand All @@ -33,36 +33,33 @@
DISPATCH_UI_URL,
)
from dispatch.database.core import Base
from dispatch.document.models import Document, DocumentRead
from dispatch.incident import service as incident_service
from dispatch.incident.models import Incident
from dispatch.individual import service as individual_service
from dispatch.individual.models import IndividualContact, IndividualContactRead
from dispatch.plugin import service as plugin_service
from dispatch.plugins import dispatch_core as dispatch_plugin
from dispatch.plugins.bases import (
AuthenticationProviderPlugin,
ContactPlugin,
DocumentResolverPlugin,
MultiFactorAuthenticationPlugin,
ParticipantPlugin,
TicketPlugin,
)
from dispatch.plugins.dispatch_core.config import DispatchTicketConfiguration
from dispatch.plugins.dispatch_core.exceptions import (
InvalidChallengeError,
UserMismatchError,
ActionMismatchError,
ExpiredChallengeError,
InvalidChallengeError,
InvalidChallengeStateError,
UserMismatchError,
)
from dispatch.plugins.dispatch_core.service import create_resource_id
from dispatch.project import service as project_service
from dispatch.route import service as route_service
from dispatch.service import service as service_service
from dispatch.service.models import Service, ServiceRead
from dispatch.team import service as team_service
from dispatch.team.models import TeamContact, TeamContactRead
from dispatch.plugins.dispatch_core.config import DispatchTicketConfiguration
from dispatch.plugins.dispatch_core.service import create_resource_id

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -289,30 +286,6 @@ def create_task_ticket(
}


class DispatchDocumentResolverPlugin(DocumentResolverPlugin):
title = "Dispatch Plugin - Document Resolver"
slug = "dispatch-document-resolver"
description = "Uses dispatch itself to resolve incident documents."
version = dispatch_plugin.__version__

author = "Netflix"
author_url = "https://github.com/netflix/dispatch.git"

def get(
self,
incident: Incident,
db_session=None,
):
"""Fetches documents from Dispatch."""
recommendation = route_service.get(
db_session=db_session,
project_id=incident.project_id,
class_instance=incident,
models=[(Document, DocumentRead)],
)
return recommendation.matches


class DispatchMfaPlugin(MultiFactorAuthenticationPlugin):
title = "Dispatch Plugin - Multi Factor Authentication"
slug = "dispatch-auth-mfa"
Expand Down
Loading