add a key to every api action

This commit is contained in:
axolotle 2021-04-09 21:47:19 +02:00
parent 9d26e2af70
commit f5b5ba5905
25 changed files with 176 additions and 40 deletions

View file

@ -327,6 +327,82 @@
"rerun_diagnosis": "Rerun diagnosis", "rerun_diagnosis": "Rerun diagnosis",
"restore": "Restore", "restore": "Restore",
"restart": "Restart", "restart": "Restart",
"human_routes": {
"adminpw": "Change admin password",
"apps": {
"change_label": "Change label of '{prevName}' for '{nextName}'",
"change_url": "Change access url of '{name}'",
"install": "Install app '{name}'",
"set_default": "Redirect '{domain}' domain root to '{name}'",
"perform_action": "Perform action '{action}' of app '{name}'",
"uninstall": "Uninstall app '{name}'",
"update_config": "Update app '{name}' configuration"
},
"backups": {
"create": "Create a backup",
"delete": "Delete backup '{name}'",
"restore": "Restore backup '{name}'"
},
"diagnosis": {
"ignore": {
"error": "Ignore an error",
"warning": "Ignore a warning"
},
"run": "Run the diagnosis",
"run_specific": "Run '{description}' diagnosis",
"unignore": {
"error": "Unignore an error",
"warning": "Unignore a warning"
}
},
"domains": {
"add": "Add domain '{name}'",
"delete": "Delete domain '{name}'",
"install_LE": "Install certificate for '{name}'",
"manual_renew_LE": "Renew certificate for '{name}'",
"regen_selfsigned": "Renew self-signed certificate for '{name}'",
"revert_to_selfsigned": "Revert to self-signed certificate for '{name}'",
"set_default": "Set '{name}' as default domain"
},
"firewall": {
"ports": "{action} port {port} ({protocol}, {connection})",
"upnp": "{action} UPnP"
},
"groups": {
"create": "Create group '{name}'",
"delete": "Delete group '{name}'",
"add": "Add '{user}' to group '{name}'",
"remove": "Remove '{user}' from group '{name}'"
},
"migrations": {
"run": "Run migrations",
"skip": "Skip migrations"
},
"permissions": {
"add": "Allow '{name}' to access '{perm}'",
"remove": "Remove '{name}' access to '{perm}'"
},
"postinstall": "Run the post-install",
"reboot": "Reboot the server",
"services": {
"restart": "Restart the service '{name}'",
"start": "Start the service '{name}'",
"stop": "Stop the service '{name}'"
},
"share_logs": "Generate link for log '{name}'",
"shutdown": "Shutdown the server",
"update": "Check for updates",
"upgrade": {
"system": "Upgrade the system",
"apps": "Upgrade all apps",
"app": "Upgrade '{app}' app"
},
"users": {
"create": "Create user '{name}'",
"delete": "Delete user '{name}'",
"update": "Update user '{name}'"
}
},
"run": "Run", "run": "Run",
"running": "Running", "running": "Running",
"save": "Save", "save": "Save",

View file

@ -108,7 +108,7 @@ export default {
}, },
'LOGIN' ({ dispatch }, password) { 'LOGIN' ({ dispatch }, password) {
return api.post('login', { password }, { websocket: false }).then(() => { return api.post('login', { password }, null, { websocket: false }).then(() => {
dispatch('CONNECT') dispatch('CONNECT')
}) })
}, },

View file

@ -92,7 +92,8 @@ export default {
performPostInstall () { performPostInstall () {
// FIXME does the api will throw an error for bad passwords ? // FIXME does the api will throw an error for bad passwords ?
api.post('postinstall', { domain: this.domain, password: this.password }).then(data => { const { domain, password } = this
api.post('postinstall', { domain, password }, 'postinstall').then(() => {
// Display success message and allow the user to login // Display success message and allow the user to login
this.step = 'login' this.step = 'login'
}) })

View file

@ -99,7 +99,11 @@ export default {
// FIXME api expects at least one argument ?! (fake one given with { dontmindthis } ) // FIXME api expects at least one argument ?! (fake one given with { dontmindthis } )
const args = objectToParams(action.form ? formatFormData(action.form) : { dontmindthis: undefined }) const args = objectToParams(action.form ? formatFormData(action.form) : { dontmindthis: undefined })
api.put(`apps/${this.id}/actions/${action.id}`, { args }).then(() => { api.put(
`apps/${this.id}/actions/${action.id}`,
{ args },
{ key: 'apps.perform_action', action: action.id, name: this.id }
).then(() => {
this.$refs.view.fetchQueries() this.$refs.view.fetchQueries()
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err if (err.name !== 'APIBadRequestError') throw err

View file

@ -102,7 +102,9 @@ export default {
applyConfig (id_) { applyConfig (id_) {
const args = objectToParams(formatFormData(this.forms[id_])) const args = objectToParams(formatFormData(this.forms[id_]))
api.put(`apps/${this.id}/config`, { args }).then(response => { api.put(
`apps/${this.id}/config`, { args }, { key: 'apps.update_config', name: this.id }
).then(response => {
console.log('SUCCESS', response) console.log('SUCCESS', response)
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err if (err.name !== 'APIBadRequestError') throw err

View file

@ -252,7 +252,11 @@ export default {
changeLabel (permName, data) { changeLabel (permName, data) {
data.show_tile = data.show_tile ? 'True' : 'False' data.show_tile = data.show_tile ? 'True' : 'False'
api.put('users/permissions/' + permName, data).then(this.$refs.view.fetchQueries) api.put(
'users/permissions/' + permName,
data,
{ key: 'apps.change_label', prevName: this.infos.label, nextName: data.label }
).then(this.$refs.view.fetchQueries)
}, },
async changeUrl () { async changeUrl () {
@ -262,7 +266,8 @@ export default {
const { domain, path } = this.form.url const { domain, path } = this.form.url
api.put( api.put(
`apps/${this.id}/changeurl`, `apps/${this.id}/changeurl`,
{ domain, path: '/' + path } { domain, path: '/' + path },
{ key: 'apps.change_url', name: this.infos.label }
).then(this.$refs.view.fetchQueries) ).then(this.$refs.view.fetchQueries)
}, },
@ -270,7 +275,11 @@ export default {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_app_default')) const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_app_default'))
if (!confirmed) return if (!confirmed) return
api.put(`apps/${this.id}/default`).then(this.$refs.view.fetchQueries) api.put(
`apps/${this.id}/default`,
{},
{ key: 'apps.set_default', name: this.infos.label, domain: this.app.domain }
).then(this.$refs.view.fetchQueries)
}, },
async uninstall () { async uninstall () {
@ -279,7 +288,7 @@ export default {
) )
if (!confirmed) return if (!confirmed) return
api.delete('apps/' + this.id).then(() => { api.delete('apps/' + this.id, {}, { key: 'apps.uninstall', name: this.infos.label }).then(() => {
this.$router.push({ name: 'app-list' }) this.$router.push({ name: 'app-list' })
}) })
} }

View file

@ -92,7 +92,7 @@ export default {
}, },
getApiManifest () { getApiManifest () {
return api.get('appscatalog?full').then(response => response.apps[this.id].manifest) return api.get('apps/catalog?full').then(response => response.apps[this.id].manifest)
}, },
formatManifestData (manifest) { formatManifestData (manifest) {
@ -128,7 +128,7 @@ export default {
const { data: args, label } = formatFormData(this.form, { extract: ['label'] }) const { data: args, label } = formatFormData(this.form, { extract: ['label'] })
const data = { app: this.id, label, args: objectToParams(args) } const data = { app: this.id, label, args: objectToParams(args) }
api.post('apps', data).then(response => { api.post('apps', data, { key: 'apps.install', name: this.name }).then(() => {
this.$router.push({ name: 'app-list' }) this.$router.push({ name: 'app-list' })
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err if (err.name !== 'APIBadRequestError') throw err

View file

@ -164,7 +164,7 @@ export default {
} }
} }
api.post('backups', data).then(response => { api.post('backups', data, 'backups.create').then(() => {
this.$router.push({ name: 'backup-list', params: { id: this.id } }) this.$router.push({ name: 'backup-list', params: { id: this.id } })
}) })
} }

View file

@ -210,7 +210,9 @@ export default {
} }
} }
api.put(`backups/${this.name}/restore`, data).then(response => { api.put(
`backups/${this.name}/restore`, data, { key: 'backups.restore', name: this.name }
).then(() => {
this.isValid = null this.isValid = null
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err if (err.name !== 'APIBadRequestError') throw err
@ -223,7 +225,9 @@ export default {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_delete', { name: this.name })) const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_delete', { name: this.name }))
if (!confirmed) return if (!confirmed) return
api.delete('backups/' + this.name).then(() => { api.delete(
'backups/' + this.name, {}, { key: 'backups.delete', name: this.name }
).then(() => {
this.$router.push({ name: 'backup-list', params: { id: this.id } }) this.$router.push({ name: 'backup-list', params: { id: this.id } })
}) })
}, },

View file

@ -42,7 +42,7 @@
</template> </template>
<template #header-buttons> <template #header-buttons>
<b-button size="sm" :variant="report.items ? 'info' : 'success'" @click="runDiagnosis(report.id)"> <b-button size="sm" :variant="report.items ? 'info' : 'success'" @click="runDiagnosis(report)">
<icon iname="refresh" /> {{ $t('rerun_diagnosis') }} <icon iname="refresh" /> {{ $t('rerun_diagnosis') }}
</b-button> </b-button>
</template> </template>
@ -115,7 +115,7 @@ export default {
data () { data () {
return { return {
queries: [ queries: [
['PUT', 'diagnosis/run?except_if_never_ran_yet'], ['PUT', 'diagnosis/run?except_if_never_ran_yet', {}, 'diagnosis.run'],
['GET', 'diagnosis?full'] ['GET', 'diagnosis?full']
], ],
reports: undefined reports: undefined
@ -171,10 +171,15 @@ export default {
this.reports = reports this.reports = reports
}, },
runDiagnosis (id = null) { runDiagnosis ({ id = null, description } = {}) {
const param = id !== null ? '?force' : '' const param = id !== null ? '?force' : ''
const data = id !== null ? { categories: [id] } : {} const data = id !== null ? { categories: [id] } : {}
api.post('diagnosis/run' + param, data).then(this.$refs.view.fetchQueries)
api.put(
'diagnosis/run' + param,
data,
{ key: 'diagnosis.run' + (id !== null ? '_specific' : ''), description }
).then(this.$refs.view.fetchQueries)
}, },
toggleIgnoreIssue (action, report, item) { toggleIgnoreIssue (action, report, item) {
@ -183,7 +188,11 @@ export default {
return filterArgs return filterArgs
}, [report.id]) }, [report.id])
api.put('diagnosis/' + action, { filter: filterArgs }).then(() => { api.put(
'diagnosis/' + action,
{ filter: filterArgs },
`diagnosis.${action}.${item.status.toLowerCase()}`
).then(() => {
item.ignored = action === 'ignore' item.ignored = action === 'ignore'
if (item.ignored) { if (item.ignored) {
report[item.status.toLowerCase() + 's']-- report[item.status.toLowerCase() + 's']--

View file

@ -27,8 +27,7 @@ export default {
onSubmit ({ domain, domainType }) { onSubmit ({ domain, domainType }) {
const uri = 'domains' + (domainType === 'dynDomain' ? '?dyndns' : '') const uri = 'domains' + (domainType === 'dynDomain' ? '?dyndns' : '')
api.post( api.post(
{ uri, storeKey: 'domains' }, { uri, storeKey: 'domains' }, { domain }, { key: 'domains.add', name: domain }
{ domain }
).then(() => { ).then(() => {
this.$router.push({ name: 'domain-list' }) this.$router.push({ name: 'domain-list' })
}).catch(err => { }).catch(err => {

View file

@ -151,7 +151,9 @@ export default {
if (action === 'regen_selfsigned') uri += '?self_signed' if (action === 'regen_selfsigned') uri += '?self_signed'
else if (action === 'manual_renew_LE') uri += '?force' else if (action === 'manual_renew_LE') uri += '?force'
else if (action === 'revert_to_selfsigned') uri += '?self_signed&force' else if (action === 'revert_to_selfsigned') uri += '?self_signed&force'
api.put(uri).then(this.$refs.view.fetchQueries) api.put(
uri, {}, { key: 'domains.' + action, name: this.name }
).then(this.$refs.view.fetchQueries)
} }
} }
} }

View file

@ -83,7 +83,7 @@ export default {
if (!confirmed) return if (!confirmed) return
api.delete( api.delete(
{ uri: 'domains', param: this.name } { uri: 'domains', param: this.name }, {}, { key: 'domains.delete', name: this.name }
).then(() => { ).then(() => {
this.$router.push({ name: 'domain-list' }) this.$router.push({ name: 'domain-list' })
}) })
@ -94,7 +94,9 @@ export default {
if (!confirmed) return if (!confirmed) return
api.put( api.put(
{ uri: `domains/${this.name}/main`, storeKey: 'main_domain' } { uri: `domains/${this.name}/main`, storeKey: 'main_domain' },
{},
{ key: 'domains.set_default', name: this.name }
).then(() => { ).then(() => {
// FIXME Have to commit by hand here since the response is empty (should return the given name) // FIXME Have to commit by hand here since the response is empty (should return the given name)
this.$store.commit('UPDATE_MAIN_DOMAIN', this.name) this.$store.commit('UPDATE_MAIN_DOMAIN', this.name)

View file

@ -45,7 +45,8 @@ export default {
onSubmit () { onSubmit () {
api.post( api.post(
{ uri: 'users/groups', storeKey: 'groups' }, { uri: 'users/groups', storeKey: 'groups' },
this.form this.form,
{ key: 'groups.create', name: this.form.groupname }
).then(() => { ).then(() => {
this.$router.push({ name: 'group-list' }) this.$router.push({ name: 'group-list' })
}).catch(err => { }).catch(err => {

View file

@ -220,7 +220,11 @@ export default {
// const data = { [action]: name } // const data = { [action]: name }
const from = action === 'add' ? 'availablePermissions' : 'permissions' const from = action === 'add' ? 'availablePermissions' : 'permissions'
const to = action === 'add' ? 'permissions' : 'availablePermissions' const to = action === 'add' ? 'permissions' : 'availablePermissions'
api.put(`users/permissions/${item}/${action}/${name}`).then(() => { api.put(
`users/permissions/${item}/${action}/${name}`,
{},
{ key: 'permissions.' + action, perm: item.replace('.main', ''), name }
).then(() => {
this[groupType + 'Groups'][name][from].splice(index, 1) this[groupType + 'Groups'][name][from].splice(index, 1)
this[groupType + 'Groups'][name][to].push(item) this[groupType + 'Groups'][name][to].push(item)
}) })
@ -229,7 +233,11 @@ export default {
onUserChanged ({ item, index, name, action }) { onUserChanged ({ item, index, name, action }) {
const from = action === 'add' ? 'availableMembers' : 'members' const from = action === 'add' ? 'availableMembers' : 'members'
const to = action === 'add' ? 'members' : 'availableMembers' const to = action === 'add' ? 'members' : 'availableMembers'
api.put(`users/groups/${name}/${action}/${item}`).then(() => { api.put(
`users/groups/${name}/${action}/${item}`,
{},
{ key: 'groups.' + action, user: item, name }
).then(() => {
this.normalGroups[name][from].splice(index, 1) this.normalGroups[name][from].splice(index, 1)
this.normalGroups[name][to].push(item) this.normalGroups[name][to].push(item)
}) })
@ -253,7 +261,7 @@ export default {
if (!confirmed) return if (!confirmed) return
api.delete( api.delete(
{ uri: 'users/groups', param: name, storeKey: 'groups' } { uri: 'users/groups', param: name, storeKey: 'groups' }, {}, { key: 'groups.delete', name }
).then(() => { ).then(() => {
Vue.delete(this.normalGroups, name) Vue.delete(this.normalGroups, name)
}) })

View file

@ -120,7 +120,11 @@ export default {
) )
if (!confirmed) return if (!confirmed) return
api.put(`services/${this.name}/${action}`).then(this.$refs.view.fetchQueries) api.put(
`services/${this.name}/${action}`,
{},
{ key: 'services.' + action, name: this.name }
).then(this.$refs.view.fetchQueries)
}, },
shareLogs () { shareLogs () {

View file

@ -44,8 +44,8 @@ export default {
this.serverError = '' this.serverError = ''
api.fetchAll( api.fetchAll(
[['POST', 'login', { password: currentPassword }, { websocket: false }], [['POST', 'login', { password: currentPassword }, null, { websocket: false }],
['PUT', 'adminpw', { new_password: password }]], ['PUT', 'adminpw', { new_password: password }, 'adminpw']],
{ wait: true } { wait: true }
).then(() => { ).then(() => {
this.$store.dispatch('DISCONNECT') this.$store.dispatch('DISCONNECT')

View file

@ -183,8 +183,12 @@ export default {
if (!confirmed) { if (!confirmed) {
return Promise.resolve(confirmed) return Promise.resolve(confirmed)
} }
const actionTrad = this.$i18n.t({ allow: 'open', disallow: 'close' }[action])
return api.put( return api.put(
`firewall/${protocol}/${action}/${port}?${connection}_only`, `firewall/${protocol}/${action}/${port}?${connection}_only`,
{},
{ key: 'firewall.ports', protocol, action: actionTrad, port, connection },
{ wait: false } { wait: false }
).then(() => confirmed) ).then(() => confirmed)
}, },
@ -194,7 +198,11 @@ export default {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_upnp_' + action)) const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_upnp_' + action))
if (!confirmed) return if (!confirmed) return
api.put('firewall/upnp/' + action).then(() => { api.put(
'firewall/upnp/' + action,
{},
{ key: 'firewall.upnp', action: this.$i18n.t(action) }
).then(() => {
// FIXME Couldn't test when it works. // FIXME Couldn't test when it works.
this.$refs.view.fetchQueries() this.$refs.view.fetchQueries()
}).catch(err => { }).catch(err => {

View file

@ -127,7 +127,12 @@ export default {
}, },
shareLogs () { shareLogs () {
api.get(`logs/${this.name}/share`, null, { websocket: true }).then(({ url }) => { api.get(
`logs/${this.name}/share`,
null,
{ key: 'share_logs', name: this.name },
{ websocket: true }
).then(({ url }) => {
window.open(url, '_blank') window.open(url, '_blank')
}) })
} }

View file

@ -121,7 +121,7 @@ export default {
} }
// Check that every migration's disclaimer has been checked. // Check that every migration's disclaimer has been checked.
if (Object.values(this.checked).every(value => value === true)) { if (Object.values(this.checked).every(value => value === true)) {
api.put('migrations', { accept_disclaimer: true }).then(() => { api.put('migrations', { accept_disclaimer: true }, 'migrations.run').then(() => {
this.$refs.view.fetchQueries() this.$refs.view.fetchQueries()
}) })
} }
@ -131,7 +131,7 @@ export default {
const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_migrations_skip')) const confirmed = await this.$askConfirmation(this.$i18n.t('confirm_migrations_skip'))
if (!confirmed) return if (!confirmed) return
api.put('migrations/' + id, { skip: '' }).then(() => { api.put('migrations/' + id, { skip: '' }, 'migration.skip').then(() => {
this.$refs.view.fetchQueries() this.$refs.view.fetchQueries()
}) })
} }

View file

@ -66,7 +66,7 @@ export default {
if (!confirmed) return if (!confirmed) return
this.action = action this.action = action
api.put(action + '?force').then(() => { api.put(action + '?force', {}, action).then(() => {
// Use 'RESET_CONNECTED' and not 'DISCONNECT' else user will be redirect to login // Use 'RESET_CONNECTED' and not 'DISCONNECT' else user will be redirect to login
this.$store.dispatch('RESET_CONNECTED') this.$store.dispatch('RESET_CONNECTED')
this.inProcess = true this.inProcess = true

View file

@ -74,7 +74,7 @@ export default {
return { return {
queries: [ queries: [
['GET', 'migrations?pending'], ['GET', 'migrations?pending'],
['PUT', 'update/all'] ['PUT', 'update/all', {}, 'update']
], ],
// API data // API data
migrationsNotDone: undefined, migrationsNotDone: undefined,
@ -96,7 +96,7 @@ export default {
if (!confirmed) return if (!confirmed) return
const uri = id !== null ? `apps/${id}/upgrade` : 'upgrade/' + type const uri = id !== null ? `apps/${id}/upgrade` : 'upgrade/' + type
api.put(uri).then(() => { api.put(uri, {}, { key: 'upgrade.' + (id ? 'app' : type), app: id }).then(() => {
this.$router.push({ name: 'tool-logs' }) this.$router.push({ name: 'tool-logs' })
}) })
} }

View file

@ -175,7 +175,7 @@ export default {
onSubmit () { onSubmit () {
const data = formatFormData(this.form, { flatten: true }) const data = formatFormData(this.form, { flatten: true })
api.post({ uri: 'users' }, data).then(() => { api.post({ uri: 'users' }, data, { key: 'users.create', name: this.form.username }).then(() => {
this.$router.push({ name: 'user-list' }) this.$router.push({ name: 'user-list' })
}).catch(err => { }).catch(err => {
if (err.name !== 'APIBadRequestError') throw err if (err.name !== 'APIBadRequestError') throw err

View file

@ -296,7 +296,8 @@ export default {
api.put( api.put(
{ uri: 'users', param: this.name, storeKey: 'users_details' }, { uri: 'users', param: this.name, storeKey: 'users_details' },
data data,
{ key: 'users.update', name: this.name }
).then(() => { ).then(() => {
this.$router.push({ name: 'user-info', param: { name: this.name } }) this.$router.push({ name: 'user-info', param: { name: this.name } })
}).catch(err => { }).catch(err => {

View file

@ -108,7 +108,8 @@ export default {
const data = this.purge ? { purge: '' } : {} const data = this.purge ? { purge: '' } : {}
api.delete( api.delete(
{ uri: 'users', param: this.name, storeKey: 'users_details' }, { uri: 'users', param: this.name, storeKey: 'users_details' },
data data,
{ key: 'users.delete', name: this.name }
).then(() => { ).then(() => {
this.$router.push({ name: 'user-list' }) this.$router.push({ name: 'user-list' })
}) })