Skip to content

Commit

Permalink
Adds functionality to manually create missing incident and case resou…
Browse files Browse the repository at this point in the history
…rces. (#3791)

* Refactors resource creation to a separate function outside of the background task. Adds checks for resource existence.

* Adds a button to the resources tab to initiate a retry for creating any missing or unsuccessfully created incident resource(s)

* Adds a button to the resources tab to initiate a retry for creating any missing or unsuccessfully created case management resource(s)

* Fixes lint errors.

* Update src/dispatch/static/dispatch/src/case/ResourcesTab.vue

Co-authored-by: David Whittaker <[email protected]>

* Plugin retrieval returns list of all enabled plugins instead of by individual queries. Adds additional indicators that resource creation is active

* Fixes lint errors.

* Changes in client-side incident updates.

* Removes success toast after resource creation.

* Sets resource creation as a background task.

* Bump jsonpath-ng from 1.5.3 to 1.6.0 (#3787)

Bumps [jsonpath-ng](https://github.com/h2non/jsonpath-ng) from 1.5.3 to 1.6.0.
- [Release notes](https://github.com/h2non/jsonpath-ng/releases)
- [Changelog](https://github.com/h2non/jsonpath-ng/blob/master/History.md)
- [Commits](h2non/jsonpath-ng@v1.5.3...v1.6.0)

---
updated-dependencies:
- dependency-name: jsonpath-ng
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump @playwright/test in /src/dispatch/static/dispatch (#3786)

Bumps [@playwright/test](https://github.com/Microsoft/playwright) from 1.37.1 to 1.38.0.
- [Release notes](https://github.com/Microsoft/playwright/releases)
- [Commits](microsoft/playwright@v1.37.1...v1.38.0)

---
updated-dependencies:
- dependency-name: "@playwright/test"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump google-api-python-client from 2.98.0 to 2.99.0 (#3784)

Bumps [google-api-python-client](https://github.com/googleapis/google-api-python-client) from 2.98.0 to 2.99.0.
- [Release notes](https://github.com/googleapis/google-api-python-client/releases)
- [Changelog](https://github.com/googleapis/google-api-python-client/blob/main/CHANGELOG.md)
- [Commits](googleapis/google-api-python-client@v2.98.0...v2.99.0)

---
updated-dependencies:
- dependency-name: google-api-python-client
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump pdpyras from 5.1.1 to 5.1.2 (#3783)

Bumps [pdpyras](https://github.com/PagerDuty/pdpyras) from 5.1.1 to 5.1.2.
- [Release notes](https://github.com/PagerDuty/pdpyras/releases)
- [Changelog](https://github.com/PagerDuty/pdpyras/blob/main/docs/changelog.html)
- [Commits](PagerDuty/pdpyras@v5.1.1...v5.1.2)

---
updated-dependencies:
- dependency-name: pdpyras
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump msal from 1.23.0 to 1.24.0 (#3782)

Bumps [msal](https://github.com/AzureAD/microsoft-authentication-library-for-python) from 1.23.0 to 1.24.0.
- [Release notes](https://github.com/AzureAD/microsoft-authentication-library-for-python/releases)
- [Commits](AzureAD/microsoft-authentication-library-for-python@1.23.0...1.24.0)

---
updated-dependencies:
- dependency-name: msal
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump sentry-sdk from 1.30.0 to 1.31.0 (#3781)

Bumps [sentry-sdk](https://github.com/getsentry/sentry-python) from 1.30.0 to 1.31.0.
- [Release notes](https://github.com/getsentry/sentry-python/releases)
- [Changelog](https://github.com/getsentry/sentry-python/blob/master/CHANGELOG.md)
- [Commits](getsentry/sentry-python@1.30.0...1.31.0)

---
updated-dependencies:
- dependency-name: sentry-sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Do not run playwright with safar (#3797)

* Appends outstanding incident tasks in tactical reports (#3798)

* Appends outstanding incident tasks to the end of user input in tactical reports.

* Update src/dispatch/plugins/dispatch_slack/incident/interactive.py

Co-authored-by: Marc Vilanova <[email protected]>

* Update src/dispatch/static/dispatch/src/incident/store.js

Co-authored-by: Marc Vilanova <[email protected]>

---------

Co-authored-by: Marc Vilanova <[email protected]>

* Rework the way slack api errors are propagated (to the caller) (#3789)

Co-authored-by: David Whittaker <[email protected]>

* Only use stable priority if set (#3803)

Co-authored-by: David Whittaker <[email protected]>

* Bump pandas from 2.1.0 to 2.1.1 (#3801)

Bumps [pandas](https://github.com/pandas-dev/pandas) from 2.1.0 to 2.1.1.
- [Release notes](https://github.com/pandas-dev/pandas/releases)
- [Commits](pandas-dev/pandas@v2.1.0...v2.1.1)

---
updated-dependencies:
- dependency-name: pandas
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump faker from 19.6.1 to 19.6.2 (#3800)

Bumps [faker](https://github.com/joke2k/faker) from 19.6.1 to 19.6.2.
- [Release notes](https://github.com/joke2k/faker/releases)
- [Changelog](https://github.com/joke2k/faker/blob/master/CHANGELOG.md)
- [Commits](joke2k/faker@v19.6.1...v19.6.2)

---
updated-dependencies:
- dependency-name: faker
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump numpy from 1.25.2 to 1.26.0 (#3794)

Bumps [numpy](https://github.com/numpy/numpy) from 1.25.2 to 1.26.0.
- [Release notes](https://github.com/numpy/numpy/releases)
- [Changelog](https://github.com/numpy/numpy/blob/main/doc/RELEASE_WALKTHROUGH.rst)
- [Commits](numpy/numpy@v1.25.2...v1.26.0)

---
updated-dependencies:
- dependency-name: numpy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Whittaker <[email protected]>

* Bump google-api-python-client from 2.99.0 to 2.100.0 (#3793)

Bumps [google-api-python-client](https://github.com/googleapis/google-api-python-client) from 2.99.0 to 2.100.0.
- [Release notes](https://github.com/googleapis/google-api-python-client/releases)
- [Changelog](https://github.com/googleapis/google-api-python-client/blob/main/CHANGELOG.md)
- [Commits](googleapis/google-api-python-client@v2.99.0...v2.100.0)

---
updated-dependencies:
- dependency-name: google-api-python-client
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Whittaker <[email protected]>

* Bump ruff from 0.0.289 to 0.0.290 (#3792)

Bumps [ruff](https://github.com/astral-sh/ruff) from 0.0.289 to 0.0.290.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/BREAKING_CHANGES.md)
- [Commits](astral-sh/ruff@v0.0.289...v0.0.290)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: David Whittaker <[email protected]>

* Making experience textbox from oncall end-of-shift feedback optional (#3799)

* Handles unexpected numbers of enabled plugins.

* Adds front end polling for resource creation updates. Adds success notification.

* Minor refactors for case and incident resource creation.

* Bump google-api-python-client from 2.98.0 to 2.99.0 (#3784)

Bumps [google-api-python-client](https://github.com/googleapis/google-api-python-client) from 2.98.0 to 2.99.0.
- [Release notes](https://github.com/googleapis/google-api-python-client/releases)
- [Changelog](https://github.com/googleapis/google-api-python-client/blob/main/CHANGELOG.md)
- [Commits](googleapis/google-api-python-client@v2.98.0...v2.99.0)

---
updated-dependencies:
- dependency-name: google-api-python-client
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump google-api-python-client from 2.100.0 to 2.101.0 (#3810)

Bumps [google-api-python-client](https://github.com/googleapis/google-api-python-client) from 2.100.0 to 2.101.0.
- [Release notes](https://github.com/googleapis/google-api-python-client/releases)
- [Changelog](https://github.com/googleapis/google-api-python-client/blob/main/CHANGELOG.md)
- [Commits](googleapis/google-api-python-client@v2.100.0...v2.101.0)

---
updated-dependencies:
- dependency-name: google-api-python-client
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump openai from 0.28.0 to 0.28.1 (#3809)

Bumps [openai](https://github.com/openai/openai-python) from 0.28.0 to 0.28.1.
- [Release notes](https://github.com/openai/openai-python/releases)
- [Commits](openai/openai-python@v0.28.0...v0.28.1)

---
updated-dependencies:
- dependency-name: openai
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump ruff from 0.0.290 to 0.0.291 (#3808)

Bumps [ruff](https://github.com/astral-sh/ruff) from 0.0.290 to 0.0.291.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/BREAKING_CHANGES.md)
- [Commits](astral-sh/ruff@v0.0.290...v0.0.291)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump eslint from 8.49.0 to 8.50.0 in /src/dispatch/static/dispatch (#3807)

Bumps [eslint](https://github.com/eslint/eslint) from 8.49.0 to 8.50.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/main/CHANGELOG.md)
- [Commits](eslint/eslint@v8.49.0...v8.50.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Revert "Making experience textbox from oncall end-of-shift feedback optional (#3799)" (#3814)

This reverts commit db544b0.

* Bump @playwright/test in /src/dispatch/static/dispatch (#3786)

Bumps [@playwright/test](https://github.com/Microsoft/playwright) from 1.37.1 to 1.38.0.
- [Release notes](https://github.com/Microsoft/playwright/releases)
- [Commits](microsoft/playwright@v1.37.1...v1.38.0)

---
updated-dependencies:
- dependency-name: "@playwright/test"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Update src/dispatch/case/views.py

Co-authored-by: Marc Vilanova <[email protected]>

* Fixes lint error.

* Bump @playwright/test in /src/dispatch/static/dispatch (#3786)

Bumps [@playwright/test](https://github.com/Microsoft/playwright) from 1.37.1 to 1.38.0.
- [Release notes](https://github.com/Microsoft/playwright/releases)
- [Commits](microsoft/playwright@v1.37.1...v1.38.0)

---
updated-dependencies:
- dependency-name: "@playwright/test"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Restores original package-lock file.

* Removes irrelevant files.

* Removes irrelevant files.

* Refactors converstion creation flow.

* Fixes linting errors.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: David Whittaker <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Will Sheldon <[email protected]>
Co-authored-by: Marc Vilanova <[email protected]>
Co-authored-by: kevgliss <[email protected]>
Co-authored-by: David Whittaker <[email protected]>
  • Loading branch information
7 people authored Sep 29, 2023
1 parent 4bc4863 commit f08a22b
Show file tree
Hide file tree
Showing 13 changed files with 581 additions and 183 deletions.
206 changes: 90 additions & 116 deletions src/dispatch/case/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

from dispatch.case import service as case_service
from dispatch.case.models import CaseRead
from dispatch.conversation import service as conversation_service
from dispatch.conversation.models import ConversationCreate
from dispatch.conversation import flows as conversation_flows
from dispatch.database.core import SessionLocal
from dispatch.decorators import background_task
from dispatch.document import flows as document_flows
Expand Down Expand Up @@ -154,26 +153,6 @@ def case_add_or_reactivate_participant_flow(
return participant


def create_conversation(case: Case, conversation_target: str, db_session: SessionLocal):
"""Create external communication conversation."""
plugin = plugin_service.get_active_instance(
db_session=db_session, project_id=case.project.id, plugin_type="conversation"
)
conversation = plugin.instance.create_threaded(
case=case, conversation_id=conversation_target, db_session=db_session
)
conversation.update({"resource_type": plugin.plugin.slug, "resource_id": conversation["id"]})

event_service.log_case_event(
db_session=db_session,
source=plugin.plugin.title,
description="Case conversation created",
case_id=case.id,
)

return conversation


def update_conversation(case: Case, db_session: SessionLocal):
"""Updates external communication conversation."""
plugin = plugin_service.get_active_instance(
Expand Down Expand Up @@ -217,6 +196,7 @@ def case_new_create_flow(
case_id=case.id,
individual_participants=individual_participants,
team_participants=team_participants,
conversation_target=conversation_target,
)

if case.case_priority.page_assignee:
Expand All @@ -241,67 +221,6 @@ def case_new_create_flow(
else:
log.warning("Case assignee not paged. No plugin of type oncall enabled.")

conversation_plugin = plugin_service.get_active_instance(
db_session=db_session, project_id=case.project.id, plugin_type="conversation"
)
if conversation_plugin:
if not conversation_target:
conversation_target = case.case_type.conversation_target
if conversation_target:
try:
# TODO: Refactor conversation creation using conversation_flows module
conversation = create_conversation(case, conversation_target, db_session)
conversation_in = ConversationCreate(
resource_id=conversation["resource_id"],
resource_type=conversation["resource_type"],
weblink=conversation["weblink"],
thread_id=conversation["timestamp"],
channel_id=conversation["id"],
)
case.conversation = conversation_service.create(
db_session=db_session, conversation_in=conversation_in
)

event_service.log_case_event(
db_session=db_session,
source="Dispatch Core App",
description="Conversation added to case",
case_id=case.id,
)
# wait until all resources are created before adding suggested participants
individual_participants = [x.email for x, _ in individual_participants]

for email in individual_participants:
# we don't rely on on this flow to add folks to the conversation because in this case
# we want to do it in bulk
case_add_or_reactivate_participant_flow(
db_session=db_session,
user_email=email,
case_id=case.id,
add_to_conversation=False,
)
# explicitly add the assignee to the conversation
all_participants = individual_participants + [case.assignee.individual.email]
conversation_plugin.instance.add_to_thread(
case.conversation.channel_id,
case.conversation.thread_id,
all_participants,
)
event_service.log_case_event(
db_session=db_session,
source="Dispatch Core App",
description="Case participants added to conversation.",
case_id=case.id,
)
except Exception as e:
event_service.log_case_event(
db_session=db_session,
source="Dispatch Core App",
description=f"Creation of case conversation failed. Reason: {e}",
case_id=case.id,
)
log.exception(e)

db_session.add(case)
db_session.commit()

Expand Down Expand Up @@ -684,51 +603,106 @@ def case_assign_role_flow(


def case_create_resources_flow(
db_session: Session, case_id: int, individual_participants: list, team_participants: list
db_session: Session,
case_id: int,
individual_participants: List[str],
team_participants: List[str],
conversation_target: str = None,
create_resources: bool = True,
) -> None:
"""Runs the case resource creation flow."""
case = get(db_session=db_session, case_id=case_id)

if case.assignee:
individual_participants.append((case.assignee.individual, None))

# we create the tactical group
direct_participant_emails = [i.email for i, _ in individual_participants]
if create_resources:
# we create the tactical group
direct_participant_emails = [i.email for i, _ in individual_participants]

indirect_participant_emails = [t.email for t in team_participants]
indirect_participant_emails = [t.email for t in team_participants]

group = group_flows.create_group(
subject=case,
group_type=GroupType.tactical,
group_participants=list(set(direct_participant_emails + indirect_participant_emails)),
db_session=db_session,
)
if not case.groups:
group_flows.create_group(
subject=case,
group_type=GroupType.tactical,
group_participants=list(
set(direct_participant_emails + indirect_participant_emails)
),
db_session=db_session,
)

# we create the storage folder
storage_members = []
if group:
storage_members = [group.email]
# we create the storage folder
storage_members = []
if case.tactical_group:
storage_members = [case.tactical_group.email]
# direct add members if not group exists
else:
storage_members = direct_participant_emails

# direct add members if not group exists
else:
storage_members = direct_participant_emails
if not case.storage:
storage_flows.create_storage(
subject=case, storage_members=storage_members, db_session=db_session
)

case.storage = storage_flows.create_storage(
subject=case, storage_members=storage_members, db_session=db_session
)
# we create the investigation document
if not case.case_document:
document_flows.create_document(
subject=case,
document_type=DocumentResourceTypes.case,
document_template=case.case_type.case_template_document,
db_session=db_session,
)

# we create the investigation document
document = document_flows.create_document(
subject=case,
document_type=DocumentResourceTypes.case,
document_template=case.case_type.case_template_document,
db_session=db_session,
)
# we update the ticket
ticket_flows.update_case_ticket(case=case, db_session=db_session)

# we update the ticket
ticket_flows.update_case_ticket(case=case, db_session=db_session)
# we update the case document
document_flows.update_document(
document=case.case_document, project_id=case.project.id, db_session=db_session
)

# we update the case document
document_flows.update_document(
document=document, project_id=case.project.id, db_session=db_session
)
try:
# we create the conversation and add participants to the thread
conversation_flows.create_case_conversation(case, conversation_target, db_session)

event_service.log_case_event(
db_session=db_session,
source="Dispatch Core App",
description="Conversation added to case",
case_id=case.id,
)
# wait until all resources are created before adding suggested participants
individual_participants = [x.email for x, _ in individual_participants]

for email in individual_participants:
# we don't rely on on this flow to add folks to the conversation because in this case
# we want to do it in bulk
case_add_or_reactivate_participant_flow(
db_session=db_session,
user_email=email,
case_id=case.id,
add_to_conversation=False,
)
# explicitly add the assignee to the conversation
all_participants = individual_participants + [case.assignee.individual.email]

# # we add the participant to the conversation
conversation_flows.add_case_participants(
case=case, participant_emails=all_participants, db_session=db_session
)

event_service.log_case_event(
db_session=db_session,
source="Dispatch Core App",
description="Case participants added to conversation.",
case_id=case.id,
)
except Exception as e:
event_service.log_case_event(
db_session=db_session,
source="Dispatch Core App",
description=f"Creation of case conversation failed. Reason: {e}",
case_id=case.id,
)
log.exception(e)
28 changes: 28 additions & 0 deletions src/dispatch/case/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
case_new_create_flow,
case_triage_create_flow,
case_update_flow,
case_create_resources_flow,
get_case_participants,
)
from .models import Case, CaseCreate, CasePagination, CaseRead, CaseUpdate, CaseExpandedPagination
from .service import create, delete, get, update
Expand Down Expand Up @@ -145,6 +147,32 @@ def create_case(
return case


@router.post(
"/{case_id}/resources",
response_model=CaseRead,
summary="Creates resources for an existing case.",
)
def create_case_resources(
db_session: DbSession,
case_id: PrimaryKey,
current_case: CurrentCase,
background_tasks: BackgroundTasks,
):
"""Creates resources for an existing case."""
individual_participants, team_participants = get_case_participants(
case=current_case, db_session=db_session
)
background_tasks.add_task(
case_create_resources_flow,
db_session=db_session,
case_id=case_id,
individual_participants=individual_participants,
team_participants=team_participants,
)

return current_case


@router.put(
"/{case_id}",
response_model=CaseRead,
Expand Down
Loading

0 comments on commit f08a22b

Please sign in to comment.