Skip to content

Commit

Permalink
Rename restrict_priority_to to stable_priority
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 committed Sep 11, 2023
1 parent 03f7036 commit ad08239
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Adds new restrict to stable incident priority id
Revision ID: 0356472ea980
Revises: 1dd78f49e303
Revises: 4e57f5b1f3f3
Create Date: 2023-09-01 15:30:52.512886
"""
Expand All @@ -10,20 +10,20 @@

# revision identifiers, used by Alembic.
revision = "0356472ea980"
down_revision = "1dd78f49e303"
down_revision = "4e57f5b1f3f3"
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"])
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", "restrict_stable_to_id")
op.drop_column("project", "stable_priority_id")
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion src/dispatch/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class ProjectRead(DispatchBase):
id: Optional[PrimaryKey]
name: NameStr
color: Optional[str]
restrict_stable_to: Optional[IncidentPriorityRead] = None
stable_priority: Optional[IncidentPriorityRead] = None


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

if incident_in.status == IncidentStatus.stable:
if incident.project.restrict_stable_to:
incident_priority = incident.project.restrict_stable_to
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
12 changes: 6 additions & 6 deletions src/dispatch/project/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class Project(Base):

send_daily_reports = Column(Boolean)

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

@hybrid_property
Expand Down Expand Up @@ -76,12 +76,12 @@ class ProjectCreate(ProjectBase):

class ProjectUpdate(ProjectBase):
send_daily_reports: Optional[bool] = Field(True, nullable=True)
restrict_stable_to_id: Optional[int]
stable_priority_id: Optional[int]


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


class ProjectPagination(Pagination):
Expand Down
6 changes: 3 additions & 3 deletions src/dispatch/static/dispatch/src/incident/DetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ 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) {
const stablePriority = project.stable_priority
if (!stablePriority) return true
if (status == "Stable" && value.name != stablePriority.name) {
return false
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ export default {
},
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`
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
},
Expand Down
18 changes: 9 additions & 9 deletions src/dispatch/static/dispatch/src/incident/priority/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
class="ml-10 mr-5"
v-model="restrictStable"
label="Restrict Stable status to this priority:"
@change="updateRestrictStable"
@change="updateStablePriority"
/>
<v-tooltip max-width="500px" open-delay="50" bottom>
<template #activator="{ on }">
Expand All @@ -96,7 +96,7 @@
<incident-priority-select
class="ml-4"
max-width="400px"
v-model="restrictStableTo"
v-model="stablePriority"
:project="project[0]"
/>
</span>
Expand Down Expand Up @@ -151,7 +151,7 @@ export default {
"table.loading",
"table.rows.items",
"table.rows.total",
"restrictStableTo",
"stablePriority",
]),
...mapFields("route", ["query", "params"]),
},
Expand All @@ -160,23 +160,23 @@ export default {
this.project = [{ name: this.query.project }]
this.getAll()
this.restrictStable = this.restrictStableTo != null
this.restrictStable = this.stablePriority != 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.restrictStable = this.stablePriority != null
}
)
this.$watch(
(vm) => [vm.restrictStableTo],
(vm) => [vm.stablePriority],
() => {
this.restrictStable = this.restrictStableTo != null
this.updateRestrictStable(this.restrictStable)
this.restrictStable = this.stablePriority != null
this.updateStablePriority(this.restrictStable)
}
)
},
Expand All @@ -186,7 +186,7 @@ export default {
"getAll",
"createEditShow",
"removeShow",
"updateRestrictStable",
"updateStablePriority",
]),
},
}
Expand Down
28 changes: 14 additions & 14 deletions src/dispatch/static/dispatch/src/incident/priority/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,21 @@ const state = {
},
loading: false,
},
restrictStableTo: null,
stablePriority: null,
}

const getters = {
getField,
}

// debounce setting changes
var oldRestrictStableTo = undefined
var oldStablePriority = undefined

function commitRestrictToStable(commit, value) {
function commitStablePriority(commit, value) {
ProjectApi.getAll({ q: state.table.options.filters.project[0].name }).then((response) => {
const project = response.data.items[0]
if (project) {
project.restrict_stable_to_id = value
project.stable_priority_id = value
ProjectApi.update(project.id, project).then(() => {
commit(
"notification_backend/addBeNotification",
Expand All @@ -87,8 +87,8 @@ const actions = {
.then((response) => {
if (response.data.items[0]) {
ProjectApi.get(response.data.items[0].project.id).then((response) => {
state.restrictStableTo = response.data.restrict_stable_to
oldRestrictStableTo = state.restrictStableTo
state.stablePriority = response.data.stable_priority
oldStablePriority = state.stablePriority
})
}
commit("SET_TABLE_LOADING", false)
Expand Down Expand Up @@ -162,18 +162,18 @@ const actions = {
)
})
},
updateRestrictStable({ commit }, value) {
if (!value) state.restrictStableTo = null
if (oldRestrictStableTo === undefined) {
oldRestrictStableTo = state.restrictStableTo
updateStablePriority({ commit }, value) {
if (!value) state.stablePriority = null
if (oldStablePriority === undefined) {
oldStablePriority = state.stablePriority
return
}
if (oldRestrictStableTo?.name !== state.restrictStableTo?.name) {
oldRestrictStableTo = state.restrictStableTo
if (oldStablePriority?.name !== state.stablePriority?.name) {
oldStablePriority = state.stablePriority
if (value) {
commitRestrictToStable(commit, state.restrictStableTo.id)
commitStablePriority(commit, state.stablePriority.id)
} else {
commitRestrictToStable(commit, null)
commitStablePriority(commit, null)
}
}
},
Expand Down

0 comments on commit ad08239

Please sign in to comment.