Skip to content

Commit d58d605

Browse files
committed
Add project id for post requests as well in the params
1 parent fb6adac commit d58d605

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

ui/src/utils/request.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ const err = (error) => {
149149
service.interceptors.request.use(config => {
150150
source = sourceToken.getSource()
151151
config.cancelToken = source.token
152+
153+
// Handle GET requests (params)
152154
if (config && config.params) {
153155
config.params.response = 'json'
154156
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
@@ -163,6 +165,26 @@ service.interceptors.request.use(config => {
163165
config.params.ignoreproject = null
164166
}
165167
}
168+
169+
// Handle POST requests (data)
170+
if (config && config.data && config.data instanceof URLSearchParams) {
171+
const project = vueProps.$localStorage.get(CURRENT_PROJECT)
172+
const command = config.data.get('command')
173+
const hasProjectId = config.data.has('projectid')
174+
const ignoreProject = config.data.has('ignoreproject')
175+
176+
if (!hasProjectId && !ignoreProject && project && project.id) {
177+
if (command === 'listTags') {
178+
config.data.append('projectid', '-1')
179+
} else if (command !== 'assignVirtualMachine') {
180+
config.data.append('projectid', project.id)
181+
}
182+
}
183+
if (config.data.has('ignoreproject')) {
184+
config.data.delete('ignoreproject')
185+
}
186+
}
187+
166188
return config
167189
}, err)
168190

0 commit comments

Comments
 (0)