Secure Send documented, and the machine form stops re-creating a controlling-PC link that already exists
This commit is contained in:
@@ -379,6 +379,7 @@ import PrinterAssignmentPicker from '@/components/PrinterAssignmentPicker.vue'
|
||||
import { currentTheme } from '@/stores/theme'
|
||||
import { useIdentifierFlags } from '@/composables/identifierSettings'
|
||||
import { apiError } from '@/utils/apiError'
|
||||
import { planControllingPcChange } from './controllingPc'
|
||||
|
||||
const { isEnabled } = useIdentifierFlags()
|
||||
|
||||
@@ -440,6 +441,9 @@ const relationshipTypes = ref([])
|
||||
const controllingPcId = ref(null)
|
||||
const relationshipTypeId = ref(null)
|
||||
const existingRelationshipId = ref(null)
|
||||
// Which PC the link named when the form loaded, so an unchanged one can be left
|
||||
// alone. Editing a machine is mostly editing something else about it.
|
||||
const loadedControllingPcId = ref(null)
|
||||
const currentMachine = ref(null)
|
||||
|
||||
// Filter models by selected machine vendor
|
||||
@@ -575,7 +579,16 @@ onMounted(async () => {
|
||||
if (rel.sourceasset?.assettypename === 'computer' && (rel.relationshiptypename || '').toLowerCase() === 'controls') {
|
||||
controllingPcId.value = rel.sourceasset.assetid
|
||||
relationshipTypeId.value = rel.relationshiptypeid
|
||||
existingRelationshipId.value = rel.assetrelationshipid
|
||||
// relationshipid. `assetrelationshipid` is not a key the API has
|
||||
// ever emitted - to_dict serialises the column names and the
|
||||
// column is relationshipid - so this read undefined every time,
|
||||
// and saveRelationship then took the "there is nothing to
|
||||
// replace" path on a machine that had a controlling PC. Saving
|
||||
// ANY change, a map position included, re-POSTed the link that
|
||||
// was already there and the server correctly answered 409 "this
|
||||
// relationship already exists".
|
||||
existingRelationshipId.value = rel.relationshipid
|
||||
loadedControllingPcId.value = rel.sourceasset.assetid
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -693,31 +706,40 @@ async function saveMachine() {
|
||||
}
|
||||
|
||||
async function saveRelationship(assetId) {
|
||||
// If no PC selected and no existing relationship, nothing to do
|
||||
if (!controllingPcId.value && !existingRelationshipId.value) {
|
||||
// The decision lives in controllingPc.js, where it is covered by tests.
|
||||
// See that file for why "is there a link" and "do I know its id" are two
|
||||
// different questions and what happened when they were treated as one.
|
||||
const plan = planControllingPcChange({
|
||||
selected: controllingPcId.value,
|
||||
loaded: loadedControllingPcId.value,
|
||||
existingRelationshipId: existingRelationshipId.value,
|
||||
})
|
||||
|
||||
if (plan.action === 'none') {
|
||||
return
|
||||
}
|
||||
|
||||
// If clearing the relationship
|
||||
if (!controllingPcId.value && existingRelationshipId.value) {
|
||||
await assetsApi.deleteRelationship(existingRelationshipId.value)
|
||||
if (plan.deleteId !== null) {
|
||||
await assetsApi.deleteRelationship(plan.deleteId)
|
||||
existingRelationshipId.value = null
|
||||
loadedControllingPcId.value = null
|
||||
}
|
||||
|
||||
if (plan.action === 'unlink') {
|
||||
return
|
||||
}
|
||||
|
||||
// If PC is selected
|
||||
if (controllingPcId.value) {
|
||||
// If there's an existing relationship, delete it first
|
||||
if (existingRelationshipId.value) {
|
||||
await assetsApi.deleteRelationship(existingRelationshipId.value)
|
||||
}
|
||||
// PC controls Machine, so the PC is the source and the machine the target.
|
||||
const created = await assetsApi.createRelationship({
|
||||
sourceassetid: controllingPcId.value,
|
||||
targetassetid: assetId,
|
||||
relationshiptypeid: relationshipTypeId.value
|
||||
})
|
||||
|
||||
// Create new relationship (PC controls Machine, so PC is source, Machine is target)
|
||||
await assetsApi.createRelationship({
|
||||
sourceassetid: controllingPcId.value,
|
||||
targetassetid: assetId,
|
||||
relationshiptypeid: relationshipTypeId.value
|
||||
})
|
||||
}
|
||||
// Keep the form honest about what is now stored, so a second save without a
|
||||
// reload does not repeat the create it just did.
|
||||
existingRelationshipId.value = created?.data?.data?.relationshipid ?? null
|
||||
loadedControllingPcId.value = controllingPcId.value
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user