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

Allow a restricted incident priority for stable status #3751

Merged
merged 19 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8d332c4
Adding validation to ensure low priority for stable
whitdog47 Aug 21, 2023
ea21300
Merge branch 'master' into enhancement/restrict-priority-for-stable
whitdog47 Aug 21, 2023
a08732f
Working on adding selectable stable priority setting
whitdog47 Aug 23, 2023
8c9fa50
Merge branch 'master' into enhancement/restrict-priority-for-stable
whitdog47 Aug 23, 2023
edf2376
Updating project model for new setting
whitdog47 Aug 23, 2023
0764484
Working on database migration
whitdog47 Aug 24, 2023
9940d5d
Getting the database right
whitdog47 Sep 3, 2023
37d06e4
Finalizing priority selection for stable incidents
whitdog47 Sep 4, 2023
17ca9e5
Require self-closing on Vue.js custom components
whitdog47 Sep 5, 2023
062c80d
Merge branch 'master' into enhancement/restrict-priority-for-stable
whitdog47 Sep 5, 2023
0c64874
Adding project name for unit test
whitdog47 Sep 5, 2023
87b4012
Merge branch 'enhancement/restrict-priority-for-stable' of https://gi…
whitdog47 Sep 5, 2023
2b1388b
Merge branch 'master' into enhancement/restrict-priority-for-stable
whitdog47 Sep 6, 2023
02ee406
Merge branch 'master' into enhancement/restrict-priority-for-stable
whitdog47 Sep 7, 2023
481aed6
Updating database revision numbers
whitdog47 Sep 7, 2023
823e83a
Rename restriction function to better reflect action
whitdog47 Sep 8, 2023
03f7036
Merge branch 'master' into enhancement/restrict-priority-for-stable
whitdog47 Sep 11, 2023
ad08239
Rename restrict_priority_to to stable_priority
whitdog47 Sep 11, 2023
9665f55
Merge branch 'master' into enhancement/restrict-priority-for-stable
whitdog47 Sep 12, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""Adds new restrict to stable incident priority id

Revision ID: 0356472ea980
Revises: 1dd78f49e303
Create Date: 2023-09-01 15:30:52.512886

"""
from alembic import op
import sqlalchemy as sa

# revision identifiers, used by Alembic.
revision = "0356472ea980"
down_revision = "1dd78f49e303"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("project", sa.Column("restrict_stable_to_id", sa.Integer(), nullable=True))
op.create_foreign_key(None, "project", "incident_priority", ["restrict_stable_to_id"], ["id"])
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, "project", type_="foreignkey")
op.drop_column("project", "restrict_stable_to_id")
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions src/dispatch/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ class ProjectRead(DispatchBase):
id: Optional[PrimaryKey]
name: NameStr
color: Optional[str]
restrict_stable_to: Optional[IncidentPriorityRead] = None
whitdog47 marked this conversation as resolved.
Show resolved Hide resolved


class CaseRead(DispatchBase):
Expand Down
6 changes: 5 additions & 1 deletion src/dispatch/incident/priority/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from dispatch.database.core import Base, ensure_unique_default_per_project
from dispatch.models import DispatchBase, NameStr, ProjectMixin, PrimaryKey, Pagination
from dispatch.project.models import ProjectRead


class IncidentPriority(Base, ProjectMixin):
Expand All @@ -36,6 +35,11 @@ class IncidentPriority(Base, ProjectMixin):
listen(IncidentPriority.default, "set", ensure_unique_default_per_project)


class ProjectRead(DispatchBase):
id: Optional[PrimaryKey]
name: NameStr


# Pydantic models...
class IncidentPriorityBase(DispatchBase):
name: NameStr
Expand Down
6 changes: 2 additions & 4 deletions src/dispatch/incident/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,8 @@ def update(*, db_session, incident: Incident, incident_in: IncidentUpdate) -> In
)

if incident_in.status == IncidentStatus.stable:
incident_priority = incident_priority_service.get_default(
db_session=db_session,
project_id=incident.project.id,
)
if incident.project.restrict_stable_to:
incident_priority = incident.project.restrict_stable_to
else:
incident_priority = incident_priority_service.get_by_name_or_default(
db_session=db_session,
Expand Down
13 changes: 13 additions & 0 deletions src/dispatch/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
from dispatch.models import DispatchBase, NameStr, PrimaryKey, Pagination

from dispatch.organization.models import Organization, OrganizationRead
from dispatch.incident.priority.models import (
IncidentPriority,
IncidentPriorityRead,
)


class Project(Base):
Expand All @@ -37,6 +41,13 @@ class Project(Base):

send_daily_reports = Column(Boolean)

restrict_stable_to_id = Column(Integer, nullable=True)
restrict_stable_to = relationship(
IncidentPriority,
foreign_keys=[restrict_stable_to_id],
primaryjoin="IncidentPriority.id == Project.restrict_stable_to_id",
)

@hybrid_property
def slug(self):
return slugify(self.name)
Expand Down Expand Up @@ -65,10 +76,12 @@ class ProjectCreate(ProjectBase):

class ProjectUpdate(ProjectBase):
send_daily_reports: Optional[bool] = Field(True, nullable=True)
restrict_stable_to_id: Optional[int]
whitdog47 marked this conversation as resolved.
Show resolved Hide resolved


class ProjectRead(ProjectBase):
id: Optional[PrimaryKey]
restrict_stable_to: Optional[IncidentPriorityRead] = None


class ProjectPagination(Pagination):
Expand Down
50 changes: 43 additions & 7 deletions src/dispatch/static/dispatch/src/incident/DetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,27 @@
<incident-severity-select v-model="incident_severity" :project="project" />
</v-flex>
<v-flex xs6>
<incident-priority-select v-model="incident_priority" :project="project" />
<ValidationProvider
name="Incident Priority"
rules="stableRestrictedPriority:@status,@project"
immediate
>
<incident-priority-select
v-model="incident_priority"
:project="project"
:status="status"
/>
</ValidationProvider>
</v-flex>
<v-flex xs6>
<v-select
v-model="status"
label="Status"
:items="statuses"
hint="The status of the incident."
/>
<ValidationProvider name="status" rules="alwaysTrue" immediate>
<v-select
v-model="status"
label="Status"
:items="statuses"
hint="The status of the incident."
/>
</ValidationProvider>
</v-flex>
<v-flex xs6>
<v-select
Expand Down Expand Up @@ -120,6 +132,11 @@
<v-flex xs12>
<case-filter-combobox label="Cases" v-model="cases" />
</v-flex>
<v-flex xs12 v-show="false">
<ValidationProvider name="project" rules="alwaysTrue" immediate>
<v-text-field v-model="project" />
</ValidationProvider>
</v-flex>
</v-layout>
</v-container>
</template>
Expand All @@ -144,6 +161,25 @@ extend("required", {
message: "This field is required",
})

extend("stableRestrictedPriority", {
params: ["status", "project"],
validate(value, { status, project }) {
if (!project) return true
const restrictStableTo = project.restrict_stable_to
if (!restrictStableTo) return true
if (status == "Stable" && value.name != restrictStableTo.name) {
return false
}
return true
},
})

extend("alwaysTrue", {
validate() {
return true
},
})

export default {
name: "IncidentDetailsTab",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
label="Priority"
return-object
:loading="loading"
:error-messages="show_error"
>
<template #item="data">
<template>
Expand Down Expand Up @@ -38,6 +39,10 @@ export default {
type: [Object],
default: null,
},
status: {
type: String,
default: "",
},
},

data() {
Expand All @@ -56,6 +61,15 @@ export default {
this.$emit("input", value)
},
},
show_error() {
if (!this.project) return null
const restrictStableTo = this.project.restrict_stable_to
if (!restrictStableTo) return null
if (this.status == "Stable" && this.value.name != restrictStableTo.name) {
return `Priority must be ${restrictStableTo.name} for Stable incidents`
}
return null
},
},

methods: {
Expand Down Expand Up @@ -101,7 +115,7 @@ export default {
created() {
this.fetchData()
this.$watch(
(vm) => [vm.project],
(vm) => [vm.project, vm.status],
() => {
this.fetchData()
}
Expand Down
57 changes: 56 additions & 1 deletion src/dispatch/static/dispatch/src/incident/priority/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<v-btn color="info" class="mr-2" @click="createEditShow()"> New </v-btn>
</v-col>
</v-row>
<v-row no-gutters>
<div class="text-body-1 ml-4 mt-3">Incident priority types</div>
</v-row>
<v-row no-gutters>
<v-col>
<v-card elevation="0">
Expand Down Expand Up @@ -68,6 +71,39 @@
</v-card>
</v-col>
</v-row>
<v-divider />
<v-row no-gutters>
<v-col>
<div class="text-body-1 ml-4 mt-6">Incident priority settings</div>
<v-row align="start" no-gutters>
<v-col class="d-flex justify-start">
<v-checkbox
class="ml-10 mr-5"
v-model="restrictStable"
label="Restrict Stable status to this priority:"
@change="updateRestrictStable"
/>
<v-tooltip max-width="500px" open-delay="50" bottom>
<template #activator="{ on }">
<v-icon v-on="on"> mdi-information </v-icon>
</template>
<span>
If activated, Dispatch will automatically change Stable incidents to this priority.
Also, users will not be permitted to change the priority on Stable incidents.
</span>
</v-tooltip>
<span max-width="500px">
<incident-priority-select
class="ml-4"
max-width="400px"
v-model="restrictStableTo"
:project="project[0]"
/>
</span>
</v-col>
</v-row>
</v-col>
</v-row>
</v-container>
</template>

Expand All @@ -77,13 +113,15 @@ import { mapActions } from "vuex"

import NewEditSheet from "@/incident/priority/NewEditSheet.vue"
import SettingsBreadcrumbs from "@/components/SettingsBreadcrumbs.vue"
import IncidentPrioritySelect from "@/incident/priority/IncidentPrioritySelect.vue"

export default {
name: "IncidentPriorityTable",

components: {
NewEditSheet,
SettingsBreadcrumbs,
IncidentPrioritySelect,
},
data() {
return {
Expand All @@ -98,6 +136,7 @@ export default {
{ text: "View Order", value: "view_order", sortable: true },
{ text: "", value: "data-table-actions", sortable: false, align: "end" },
],
restrictStable: false,
}
},

Expand All @@ -112,6 +151,7 @@ export default {
"table.loading",
"table.rows.items",
"table.rows.total",
"restrictStableTo",
]),
...mapFields("route", ["query", "params"]),
},
Expand All @@ -120,19 +160,34 @@ export default {
this.project = [{ name: this.query.project }]

this.getAll()
this.restrictStable = this.restrictStableTo != null

this.$watch(
(vm) => [vm.q, vm.itemsPerPage, vm.sortBy, vm.descending, vm.project],
() => {
this.page = 1
this.$router.push({ query: { project: this.project[0].name } })
this.getAll()
this.restrictStable = this.restrictStableTo != null
}
)

this.$watch(
(vm) => [vm.restrictStableTo],
() => {
this.restrictStable = this.restrictStableTo != null
this.updateRestrictStable(this.restrictStable)
}
)
},

methods: {
...mapActions("incident_priority", ["getAll", "createEditShow", "removeShow"]),
...mapActions("incident_priority", [
"getAll",
"createEditShow",
"removeShow",
"updateRestrictStable",
]),
},
}
</script>
Loading