fix(flows): add saved flows navigation drawer in FlowEditorView and fix 403 on shared workflows
Some checks failed
Build, Test, and Deploy / build-and-deploy (push) Failing after 59s

This commit is contained in:
Goose 2026-09-29 14:57:54 +00:00
parent 4e1e693378
commit 2ed637eb51
3 changed files with 187 additions and 18 deletions

View file

@ -4,11 +4,22 @@
<div class="bg-white border-b border-slate-200 px-6 py-3 flex items-center justify-between">
<div class="flex items-center space-x-4">
<div>
<h2 class="text-lg font-bold text-slate-900">Visual Flow Editor</h2>
<div class="flex items-center gap-2">
<h2 class="text-lg font-bold text-slate-900">Visual Flow Editor</h2>
<span v-if="currentFlow" class="text-xs bg-indigo-50 text-indigo-700 font-semibold px-2 py-0.5 rounded border border-indigo-200">
{{ currentFlow.name }} (#{{ currentFlow.id }})
</span>
</div>
<p class="text-xs text-slate-500">Design automation DAGs with Decision branching, Loops, and Subflows</p>
</div>
</div>
<div class="flex items-center space-x-3">
<div class="flex items-center space-x-2">
<button
@click="showNewFlowModal = true"
class="px-3 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-xs font-semibold rounded-md shadow-sm border border-slate-200 transition"
>
+ New Flow
</button>
<button
@click="addDecisionNode"
class="px-3 py-1.5 bg-indigo-50 text-indigo-700 hover:bg-indigo-100 border border-indigo-200 text-xs font-semibold rounded-md shadow-sm transition"
@ -45,8 +56,38 @@
</div>
</div>
<!-- Main Workspace Canvas -->
<!-- Main Workspace Canvas with Flows Sidebar Drawer -->
<div class="flex-1 flex overflow-hidden">
<!-- Flows Sidebar List -->
<div class="w-64 bg-white border-r border-slate-200 flex flex-col">
<div class="p-3 border-b border-slate-100 flex items-center justify-between bg-slate-50/50">
<span class="text-xs font-bold uppercase tracking-wider text-slate-500">Saved Flows</span>
<span class="text-[11px] bg-slate-200 text-slate-600 px-1.5 py-0.5 rounded font-medium">
{{ flowList.length }}
</span>
</div>
<div class="overflow-y-auto flex-1 divide-y divide-slate-100">
<div
v-for="flow in flowList"
:key="flow.id"
@click="selectFlow(flow)"
:class="['p-3 cursor-pointer transition flex items-center justify-between group',
currentFlowId === flow.id ? 'bg-indigo-50/80 border-l-4 border-indigo-600' : 'hover:bg-slate-50']"
>
<div class="overflow-hidden pr-2">
<div class="text-xs font-semibold text-slate-800 truncate">{{ flow.name }}</div>
<div class="text-[10px] text-slate-400 truncate mt-0.5">
{{ flow.trigger_type || 'manual' }} • {{ flow.trigger_object || 'Any' }}
</div>
</div>
<span class="text-xs text-slate-400 group-hover:translate-x-0.5 transition-transform">→</span>
</div>
<div v-if="flowList.length === 0" class="p-4 text-center text-slate-400 text-xs italic">
{{ isLoadingFlows ? 'Loading flows...' : 'No workflows found.' }}
</div>
</div>
</div>
<!-- Vue Flow Canvas -->
<div class="flex-1 h-full relative">
<VueFlow
@ -100,11 +141,50 @@
</div>
</div>
</div>
<!-- New Flow Modal -->
<div v-if="showNewFlowModal" class="fixed inset-0 bg-slate-900/40 backdrop-blur-sm flex items-center justify-center z-50 p-4">
<div class="bg-white rounded-lg shadow-xl border border-slate-200 w-full max-w-md overflow-hidden">
<div class="px-5 py-3 border-b border-slate-200 flex items-center justify-between bg-slate-50">
<h3 class="text-sm font-bold text-slate-800">Create New Flow</h3>
<button @click="showNewFlowModal = false" class="text-slate-400 hover:text-slate-600 text-lg">&times;</button>
</div>
<div class="p-5 space-y-4 text-xs">
<div>
<label class="block font-semibold text-slate-700 mb-1">Flow Name *</label>
<input v-model="newFlowData.name" type="text" placeholder="e.g. Lead Qualification Flow" class="w-full border border-slate-300 rounded px-3 py-1.5" />
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Description</label>
<textarea v-model="newFlowData.description" rows="2" class="w-full border border-slate-300 rounded px-3 py-1.5" placeholder="Purpose of this flow"></textarea>
</div>
<div class="grid grid-cols-2 gap-3">
<div>
<label class="block font-semibold text-slate-700 mb-1">Trigger Type</label>
<select v-model="newFlowData.trigger_type" class="w-full border border-slate-300 rounded px-2.5 py-1.5">
<option value="record_created">Record Created</option>
<option value="record_updated">Record Updated</option>
<option value="scheduled">Scheduled</option>
<option value="manual">Manual / API</option>
</select>
</div>
<div>
<label class="block font-semibold text-slate-700 mb-1">Trigger Object</label>
<input v-model="newFlowData.trigger_object" type="text" placeholder="e.g. Account, Contact" class="w-full border border-slate-300 rounded px-2.5 py-1.5" />
</div>
</div>
</div>
<div class="px-5 py-3 bg-slate-50 border-t border-slate-200 flex justify-end gap-2">
<button @click="showNewFlowModal = false" class="px-3 py-1.5 border border-slate-300 rounded text-slate-600 font-semibold hover:bg-slate-100 text-xs">Cancel</button>
<button @click="createNewFlow" class="px-4 py-1.5 bg-indigo-600 hover:bg-indigo-700 text-white rounded font-semibold text-xs shadow-sm">Create Flow</button>
</div>
</div>
</div>
</div>
</template>
<script setup>
import { ref } from 'vue'
import { ref, onMounted } from 'vue'
import { VueFlow } from '@vue-flow/core'
import { Background } from '@vue-flow/background'
import { Controls } from '@vue-flow/controls'
@ -112,20 +192,31 @@ import api from '../api'
const isSaving = ref(false)
const isRunning = ref(false)
const isLoadingFlows = ref(false)
const flowList = ref([])
const currentFlowId = ref(null)
const currentFlow = ref(null)
const executionResult = ref(null)
const showNewFlowModal = ref(false)
const nodes = ref([
const newFlowData = ref({
name: '',
description: '',
trigger_type: 'record_created',
trigger_object: 'Account'
})
const defaultNodes = [
{
id: 'start-trigger',
type: 'input',
label: '⚡ Trigger: Account Created',
label: '⚡ Trigger: Record Created',
position: { x: 100, y: 150 },
class: 'bg-emerald-600 text-white font-semibold text-xs p-3 rounded-lg shadow-md border-0'
},
{
id: 'decision-tier',
label: '⚖️ Decision: VIP Tier Check',
label: '⚖️ Decision: VIP Check',
position: { x: 340, y: 150 },
data: {
type: 'decision',
@ -175,15 +266,78 @@ const nodes = ref([
},
class: 'bg-violet-600 text-white font-semibold text-xs p-3 rounded-lg shadow-md border-0'
}
])
]
const edges = ref([
const defaultEdges = [
{ id: 'e1-2', source: 'start-trigger', target: 'decision-tier', animated: true },
{ id: 'e2-3', source: 'decision-tier', target: 'assign-vip', label: 'VIP (>= 50k)' },
{ id: 'e2-4', source: 'decision-tier', target: 'assign-standard', label: 'Default/Standard' },
{ id: 'e3-5', source: 'assign-vip', target: 'subflow-sync' },
{ id: 'e4-5', source: 'assign-standard', target: 'subflow-sync' }
])
]
const nodes = ref(JSON.parse(JSON.stringify(defaultNodes)))
const edges = ref(JSON.parse(JSON.stringify(defaultEdges)))
async function fetchFlows() {
isLoadingFlows.value = true
try {
const res = await api.get('/workflows/')
flowList.value = res.data.results || res.data || []
if (flowList.value.length > 0 && !currentFlowId.value) {
selectFlow(flowList.value[0])
}
} catch (err) {
console.error('Failed to fetch workflows:', err)
} finally {
isLoadingFlows.value = false
}
}
function selectFlow(flow) {
currentFlowId.value = flow.id
currentFlow.value = flow
executionResult.value = null
if (flow.graph && flow.graph.nodes && flow.graph.nodes.length > 0) {
nodes.value = flow.graph.nodes
edges.value = flow.graph.edges || []
} else {
nodes.value = JSON.parse(JSON.stringify(defaultNodes))
edges.value = JSON.parse(JSON.stringify(defaultEdges))
}
}
async function createNewFlow() {
if (!newFlowData.value.name.trim()) {
alert('Please enter a flow name.')
return
}
isSaving.value = true
try {
const payload = {
name: newFlowData.value.name.trim(),
description: newFlowData.value.description || '',
trigger_type: newFlowData.value.trigger_type || 'record_created',
trigger_object: newFlowData.value.trigger_object || 'Account',
is_active: true,
graph: {
nodes: JSON.parse(JSON.stringify(defaultNodes)),
edges: JSON.parse(JSON.stringify(defaultEdges))
}
}
const res = await api.post('/workflows/', payload)
flowList.value.unshift(res.data)
selectFlow(res.data)
showNewFlowModal.value = false
newFlowData.value.name = ''
newFlowData.value.description = ''
} catch (err) {
console.error('Failed to create flow:', err)
alert('Failed to create flow: ' + (err.response?.data?.detail || err.message))
} finally {
isSaving.value = false
}
}
function addDecisionNode() {
const id = `decision-${Date.now().toString().slice(-4)}`
@ -233,11 +387,11 @@ async function saveFlow() {
isSaving.value = true
try {
const payload = {
name: 'Account Onboarding & VIP Routing Flow',
description: 'Automates VIP routing, variable assignment, and billing sync',
trigger_type: 'record_created',
trigger_object: 'Account',
is_active: true,
name: currentFlow.value?.name || 'Account Onboarding & VIP Routing Flow',
description: currentFlow.value?.description || 'Automates VIP routing, variable assignment, and billing sync',
trigger_type: currentFlow.value?.trigger_type || 'record_created',
trigger_object: currentFlow.value?.trigger_object || 'Account',
is_active: currentFlow.value?.is_active ?? true,
graph: {
nodes: nodes.value,
edges: edges.value
@ -246,14 +400,21 @@ async function saveFlow() {
let res
if (currentFlowId.value) {
res = await api.put(`/workflows/${currentFlowId.value}/`, payload)
// update in flowList
const idx = flowList.value.findIndex(f => f.id === currentFlowId.value)
if (idx !== -1) {
flowList.value[idx] = res.data
}
} else {
res = await api.post('/workflows/', payload)
currentFlowId.value = res.data.id
flowList.value.unshift(res.data)
}
currentFlow.value = res.data
alert(`Workflow graph saved successfully! (ID: ${currentFlowId.value})`)
} catch (err) {
console.error('Failed to save workflow:', err)
alert('Failed to save workflow: ' + (err.response?.data?.message || err.message))
alert('Failed to save workflow: ' + (err.response?.data?.message || err.response?.data?.detail || err.message))
} finally {
isSaving.value = false
}
@ -291,4 +452,8 @@ async function runFlow() {
isRunning.value = false
}
}
onMounted(async () => {
await fetchFlows()
})
</script>

View file

@ -22,6 +22,10 @@ class ScopedOwnerAccessPermission(permissions.BasePermission):
created_by = getattr(obj, 'created_by', None)
if created_by is not None:
return created_by == user
else:
# System-level or unassigned flow definition / shared template
if hasattr(obj, 'graph') or obj.__class__.__name__ == 'FlowDefinition':
return True
# In CustomFieldDefinition, check custom_object's creator
custom_obj = getattr(obj, 'custom_object', None)
if custom_obj is not None:

View file

@ -20,11 +20,11 @@ class FlowDefinitionViewSet(viewsets.ModelViewSet):
qs = super().get_queryset()
user = self.request.user
if not user or not user.is_authenticated:
return qs
return qs.none()
if user.is_superuser or user.is_staff:
return qs
if hasattr(FlowDefinition, 'created_by'):
return qs.filter(created_by=user)
return qs.filter(models.Q(created_by=user) | models.Q(created_by__isnull=True))
return qs
def perform_create(self, serializer):