Skip to content

Commit

Permalink
Restrict select incident severities to active incidents only (#5185)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Sep 10, 2024
1 parent 7677134 commit 0636f96
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Adds restriction ability to incident severity
Revision ID: 0a6702319f6a
Revises: 51eacaf1f62c
Create Date: 2024-09-10 10:13:04.192475
"""

from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "0a6702319f6a"
down_revision = "51eacaf1f62c"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"incident_severity",
sa.Column("allowed_for_stable_incidents", sa.Boolean(), server_default="t", nullable=True),
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("incident_severity", "allowed_for_stable_incidents")
# ### end Alembic commands ###
3 changes: 3 additions & 0 deletions src/dispatch/incident/severity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class IncidentSeverity(Base, ProjectMixin):
color = Column(String)
enabled = Column(Boolean, default=True)
default = Column(Boolean, default=False)
allowed_for_stable_incidents = Column(Boolean, default=True, server_default="t")

# This column is used to control how severities should be displayed
# Lower numbers will be shown first.
Expand All @@ -46,6 +47,7 @@ class IncidentSeverityBase(DispatchBase):
name: NameStr
project: Optional[ProjectRead]
view_order: Optional[int]
allowed_for_stable_incidents: Optional[bool]


class IncidentSeverityCreate(IncidentSeverityBase):
Expand All @@ -67,6 +69,7 @@ class IncidentSeverityReadMinimal(DispatchBase):
description: Optional[str] = Field(None, nullable=True)
enabled: Optional[bool]
name: NameStr
allowed_for_stable_incidents: Optional[bool]


class IncidentSeverityPagination(Pagination):
Expand Down
23 changes: 21 additions & 2 deletions src/dispatch/plugins/dispatch_slack/incident/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from dispatch.participant import service as participant_service
from dispatch.participant.models import ParticipantUpdate
from dispatch.participant_role import service as participant_role_service
from dispatch.incident.severity import service as incident_severity_service
from dispatch.participant_role.enums import ParticipantRoleType
from dispatch.plugin import service as plugin_service
from dispatch.plugins.dispatch_slack import service as dispatch_slack_service
Expand Down Expand Up @@ -1011,7 +1012,9 @@ def handle_member_joined_channel(

if participant.added_by:
# Message text when someone @'s a user is not available in body, use generic added by reason
participant.added_reason = f"Participant added by {participant.added_by.individual.name}"
participant.added_reason = (
f"Participant added by {participant.added_by.individual.name}"
)
else:
# We couldn't find a user to attribute the addition to, add generic reason
participant.added_reason = "Participant added by Dispatch"
Expand Down Expand Up @@ -1061,7 +1064,9 @@ def handle_member_joined_channel(

if participant.added_by:
# Message text when someone @'s a user is not available in body, use generic added by reason
participant.added_reason = f"Participant added by {participant.added_by.individual.name}"
participant.added_reason = (
f"Participant added by {participant.added_by.individual.name}"
)
else:
# We couldn't find a user to attribute the addition to, add generic reason
participant.added_reason = "Participant added by Dispatch"
Expand Down Expand Up @@ -1980,6 +1985,20 @@ def handle_update_incident_submission_event(
user: DispatchUser,
) -> None:
"""Handles the update incident submission"""
incident_severity_id = form_data[DefaultBlockIds.incident_severity_select]["value"]
incident_severity = incident_severity_service.get(
db_session=db_session, incident_severity_id=incident_severity_id
)
status = form_data[DefaultBlockIds.incident_status_select]["name"]
if not incident_severity.allowed_for_stable_incidents and (
status == IncidentStatus.stable or status == IncidentStatus.closed
):
errors = {
DefaultBlockIds.incident_severity_select: f"Severity cannot be {incident_severity.name} for {status} incidents"
}
ack(response_action="errors", errors=errors)
return

ack_incident_update_submission_event(ack=ack)
incident = incident_service.get(db_session=db_session, incident_id=context["subject"].id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<v-checkbox
v-model="enabled"
label="Enabled"
hint="Determines whether this case priority is availible for new cases."
hint="Determines whether this case priority is available for new cases."
/>
</v-col>
</v-row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<v-checkbox
v-model="enabled"
label="Enabled"
hint="Determines whether this case severity is availible for new cases."
hint="Determines whether this case severity is available for new cases."
/>
</v-col>
</v-row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<v-checkbox
v-model="enabled"
label="Enabled"
hint="Determines whether this case type is availible for new cases."
hint="Determines whether this case type is available for new cases."
/>
</v-col>
<v-col cols="12">
Expand Down
2 changes: 1 addition & 1 deletion src/dispatch/static/dispatch/src/incident/DetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<incident-type-select v-model="incident_type" :project="project" />
</v-col>
<v-col cols="6">
<incident-severity-select v-model="incident_severity" :project="project" />
<incident-severity-select v-model="incident_severity" :project="project" :status="status" />
</v-col>
<v-col cols="6">
<incident-priority-select v-model="incident_priority" :project="project" :status="status" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
<v-checkbox
v-model="enabled"
label="Enabled"
hint="Determines whether this incident priority is availible for new incidents."
hint="Determines whether this incident priority is available for new incidents."
/>
</v-col>
</v-row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
label="Severity"
return-object
:loading="loading"
:error-messages="show_error"
:rules="[is_severity_in_project]"
>
<template #item="data">
Expand Down Expand Up @@ -40,6 +41,10 @@ export default {
type: [Object],
default: null,
},
status: {
type: String,
default: "",
},
},
data() {
Expand All @@ -64,6 +69,12 @@ export default {
this.validateSeverity()
},
},
show_error() {
if (this.status != "Active" && this.modelValue?.allowed_for_stable_incidents === false) {
return `Severity cannot be ${this.modelValue?.name} for ${this.status} incidents`
}
return null
},
},
methods: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@
<v-checkbox
v-model="enabled"
label="Enabled"
hint="Determines whether this incident severity is availible for new incidents."
hint="Determines whether this incident severity is available for new incidents."
/>
</v-col>
<v-col cols="12">
<v-checkbox
v-model="allowed_for_stable_incidents"
label="Allowed for stable incidents"
hint="Determines whether this incident severity is available for stable (and closed) incidents."
/>
</v-col>
</v-row>
Expand Down Expand Up @@ -126,6 +133,7 @@ export default {
"selected.name",
"selected.project",
"selected.view_order",
"selected.allowed_for_stable_incidents",
]),
...mapFields("incident_severity", {
default_incident_severity: "selected.default",
Expand Down
4 changes: 4 additions & 0 deletions src/dispatch/static/dispatch/src/incident/severity/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<template #item.enabled="{ value }">
<v-checkbox-btn :model-value="value" disabled />
</template>
<template #item.allowed_for_stable_incidents="{ value }">
<v-checkbox-btn :model-value="value" disabled />
</template>
<template #item.data-table-actions="{ item }">
<v-menu location="right" origin="overlap">
<template #activator="{ props }">
Expand Down Expand Up @@ -90,6 +93,7 @@ export default {
{ title: "Description", value: "description", sortable: false },
{ title: "Default", value: "default", sortable: true },
{ title: "Enabled", value: "enabled", sortable: true },
{ title: "Allowed for Stable", value: "allowed_for_stable_incidents", sortable: true },
{ title: "View Order", value: "view_order", sortable: true },
{ title: "", key: "data-table-actions", sortable: false, align: "end" },
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<v-checkbox
v-model="enabled"
label="Enabled"
hint="Determines whether this incident type is availible for new incidents."
hint="Determines whether this incident type is available for new incidents."
/>
</v-col>
<v-col cols="12">
Expand Down

0 comments on commit 0636f96

Please sign in to comment.