Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Sep 12, 2023
2 parents a4afbc4 + d10e174 commit cbcd379
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 41 deletions.
4 changes: 2 additions & 2 deletions requirements-base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ google-auth==2.22.0
# google-auth-oauthlib
google-auth-httplib2==0.1.0
# via google-api-python-client
google-auth-oauthlib==1.0.0
google-auth-oauthlib==1.1.0
# via -r requirements-base.in
googleapis-common-protos==1.60.0
# via google-api-core
Expand Down Expand Up @@ -391,7 +391,7 @@ six==1.16.0
# validators
slack-bolt==1.18.0
# via -r requirements-base.in
slack-sdk==3.21.3
slack-sdk==3.22.0
# via
# -r requirements-base.in
# slack-bolt
Expand Down
6 changes: 3 additions & 3 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ attrs==22.1.0
# via -r requirements-dev.in
backcall==0.2.0
# via ipython
black==23.7.0
black==23.9.1
# via -r requirements-dev.in
cfgv==3.4.0
# via pre-commit
Expand All @@ -34,7 +34,7 @@ executing==1.2.0
# stack-data
factory-boy==3.3.0
# via -r requirements-dev.in
faker==19.4.0
faker==19.6.1
# via
# -r requirements-dev.in
# factory-boy
Expand Down Expand Up @@ -90,7 +90,7 @@ python-dateutil==2.8.2
# via faker
pyyaml==6.0.1
# via pre-commit
ruff==0.0.287
ruff==0.0.288
# via -r requirements-dev.in
six==1.16.0
# via
Expand Down
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: 4e57f5b1f3f3
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 = "4e57f5b1f3f3"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("project", sa.Column("stable_priority_id", sa.Integer(), nullable=True))
op.create_foreign_key(None, "project", "incident_priority", ["stable_priority_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", "stable_priority_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]
stable_priority: Optional[IncidentPriorityRead] = None


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.stable_priority:
incident_priority = incident.project.stable_priority
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)

stable_priority_id = Column(Integer, nullable=True)
stable_priority = relationship(
IncidentPriority,
foreign_keys=[stable_priority_id],
primaryjoin="IncidentPriority.id == Project.stable_priority_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)
stable_priority_id: Optional[int]


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


class ProjectPagination(Pagination):
Expand Down
44 changes: 22 additions & 22 deletions src/dispatch/static/dispatch/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 stablePriority = project.stable_priority
if (!stablePriority) return true
if (status == "Stable" && value.name != stablePriority.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 stablePriority = this.project.stable_priority
if (!stablePriority) return null
if (this.status == "Stable" && this.value.name != stablePriority.name) {
return `Priority must be ${stablePriority.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
Loading

0 comments on commit cbcd379

Please sign in to comment.